Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit 280a9c4

Browse files
committed
Tests for preprocessor directives
This adds tests for how we handle preprocessor directives with respect to file formatting. closes #38
1 parent 875e611 commit 280a9c4

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/Microsoft.DotNet.CodeFormatting.Tests/Rules/CombinationTest.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public CombinationTest()
2626
{
2727
s_formattingEngine.CopyrightHeader = ImmutableArray.Create("", "// header");
2828
s_formattingEngine.FormatLogger = new EmptyFormatLogger();
29+
s_formattingEngine.PreprocessorConfigurations = ImmutableArray<string[]>.Empty;
2930
}
3031

3132
protected override async Task<Document> RewriteDocumentAsync(Document document)
@@ -93,5 +94,57 @@ private void M()
9394

9495
Verify(text, expected, runFormatter: false);
9596
}
97+
98+
[Fact]
99+
public void PreprocessorSymbolNotDefined()
100+
{
101+
var text = @"
102+
class C
103+
{
104+
#if DOG
105+
void M() { }
106+
#endif
107+
}";
108+
109+
var expected = @"
110+
// header
111+
112+
internal class C
113+
{
114+
#if DOG
115+
void M() { }
116+
#endif
117+
}";
118+
119+
Verify(text, expected, runFormatter: false);
120+
}
121+
122+
[Fact]
123+
public void PreprocessorSymbolDefined()
124+
{
125+
var text = @"
126+
internal class C
127+
{
128+
#if DOG
129+
internal void M() {
130+
}
131+
#endif
132+
}";
133+
134+
var expected = @"
135+
// header
136+
137+
internal class C
138+
{
139+
#if DOG
140+
internal void M()
141+
{
142+
}
143+
#endif
144+
}";
145+
146+
s_formattingEngine.PreprocessorConfigurations = ImmutableArray.CreateRange(new[] { new[] { "DOG" } });
147+
Verify(text, expected, runFormatter: false);
148+
}
96149
}
97150
}

0 commit comments

Comments
 (0)