Skip to content

Commit 0b37962

Browse files
committed
Add regression test for #2000
1 parent 7a4fcf8 commit 0b37962

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1211UnitTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,38 @@ public async Task TestPreprocessorDirectivesAsync()
196196
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
197197
}
198198

199+
/// <summary>
200+
/// Verifies that the analyzer will not combine using directives that refer to the same type. This is a
201+
/// regression test for DotNetAnalyzers/StyleCopAnalyzers#2000.
202+
/// </summary>
203+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
204+
[Fact]
205+
public async Task TestSameUsingWithDifferentAliasAsync()
206+
{
207+
string testCode = @"namespace NamespaceName
208+
{
209+
using Func2 = System.Func<int>;
210+
using Func1 = System.Func<int>;
211+
212+
internal delegate void DelegateName(Func1 arg1, Func2 arg2);
213+
}
214+
";
215+
string fixedCode = @"namespace NamespaceName
216+
{
217+
using Func1 = System.Func<int>;
218+
using Func2 = System.Func<int>;
219+
220+
internal delegate void DelegateName(Func1 arg1, Func2 arg2);
221+
}
222+
";
223+
224+
var expected = this.CSharpDiagnostic().WithLocation(4, 5).WithArguments("Func1", "Func2");
225+
226+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
227+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
228+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
229+
}
230+
199231
/// <inheritdoc/>
200232
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
201233
{

0 commit comments

Comments
 (0)