Skip to content

Commit 30b7631

Browse files
Added test case for verifying SA1402 behaviour for generic classes, interfaces, structs and delegates.
1 parent 36b11db commit 30b7631

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1402ForBlockDeclarationUnitTestsBase.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,37 @@ public abstract class SA1402ForBlockDeclarationUnitTestsBase : FileMayOnlyContai
1919

2020
private bool ConfigureAsNonTopLevelType { get; set; } = false;
2121

22+
[Fact]
23+
public async Task TestTwoGenericElementsAsync()
24+
{
25+
var testCode = @"%1 Foo<T1>
26+
{
27+
}
28+
%1 Bar<T2, T3>
29+
{
30+
}";
31+
32+
var fixedCode = new[]
33+
{
34+
@"%1 Foo<T1>
35+
{
36+
}
37+
",
38+
@"%1 Bar<T2, T3>
39+
{
40+
}"
41+
};
42+
43+
testCode = testCode.Replace("%1", this.Keyword);
44+
fixedCode = fixedCode.Select(c => c.Replace("%1", this.Keyword)).ToArray();
45+
46+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2);
47+
48+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
49+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
50+
await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
51+
}
52+
2253
[Fact]
2354
public async Task TestTwoElementsWithRuleDisabledAsync()
2455
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1402ForDelegateUnitTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ public async Task TestTwoElementsAsync()
4646
await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
4747
}
4848

49+
[Fact]
50+
public async Task TestTwoGenericElementsAsync()
51+
{
52+
var testCode = @"public delegate void Foo();
53+
54+
public delegate void Bar<T1, T2, T3>(T1 x, T2 y, T3 z);
55+
";
56+
57+
var fixedCode = new[]
58+
{
59+
@"public delegate void Foo();
60+
",
61+
62+
// There should be no leading whitespace here... Why are there?
63+
@"
64+
public delegate void Bar<T1, T2, T3>(T1 x, T2 y, T3 z);
65+
"
66+
};
67+
68+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 22);
69+
70+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
71+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
72+
await this.VerifyCSharpFixAsync(new[] { testCode }, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
73+
}
74+
4975
[Fact]
5076
public async Task TestTwoElementsWithRuleDisabledAsync()
5177
{

0 commit comments

Comments
 (0)