Skip to content

Commit 4bbe32e

Browse files
committed
Add tests for behavior of preprocessor lines
1 parent 5242d8d commit 4bbe32e

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1200UnitTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,70 @@ namespace TestNamespace
128128
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
129129
}
130130

131+
[Fact]
132+
public async Task TestInvalidUsingStatementsInCompilationUnitWithPragmaAsync()
133+
{
134+
var testCode = @"#pragma warning disable 1573 // Comment
135+
using System;
136+
using System.Threading;
137+
138+
namespace TestNamespace
139+
{
140+
}
141+
";
142+
143+
var fixedTestCode = @"namespace TestNamespace
144+
{
145+
#pragma warning disable 1573 // Comment
146+
using System;
147+
using System.Threading;
148+
}
149+
";
150+
151+
DiagnosticResult[] expectedResults =
152+
{
153+
this.CSharpDiagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(2, 1),
154+
this.CSharpDiagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(3, 1),
155+
};
156+
157+
await this.VerifyCSharpDiagnosticAsync(testCode, expectedResults, CancellationToken.None).ConfigureAwait(false);
158+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
159+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
160+
}
161+
162+
[Fact]
163+
public async Task TestInvalidUsingStatementsInCompilationUnitWithRegionBeforeAsync()
164+
{
165+
var testCode = @"#region Comment
166+
#endregion Comment
167+
using System;
168+
using System.Threading;
169+
170+
namespace TestNamespace
171+
{
172+
}
173+
";
174+
175+
var fixedTestCode = @"namespace TestNamespace
176+
{
177+
#region Comment
178+
#endregion Comment
179+
using System;
180+
using System.Threading;
181+
}
182+
";
183+
184+
DiagnosticResult[] expectedResults =
185+
{
186+
this.CSharpDiagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(3, 1),
187+
this.CSharpDiagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(4, 1),
188+
};
189+
190+
await this.VerifyCSharpDiagnosticAsync(testCode, expectedResults, CancellationToken.None).ConfigureAwait(false);
191+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
192+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
193+
}
194+
131195
[Fact]
132196
[WorkItem(2363, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2363")]
133197
public async Task TestInvalidUsingStatementsWithFileHeaderTriviaAsync()

0 commit comments

Comments
 (0)