Skip to content

Commit dd4688f

Browse files
Update tests that fail for c# 12
1 parent ed99667 commit dd4688f

File tree

6 files changed

+135
-38
lines changed

6 files changed

+135
-38
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1130CSharp12UnitTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,58 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp12.ReadabilityRules
55
{
6+
using Microsoft.CodeAnalysis.Testing;
67
using StyleCop.Analyzers.Test.CSharp11.ReadabilityRules;
78

9+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
10+
StyleCop.Analyzers.ReadabilityRules.SA1130UseLambdaSyntax,
11+
StyleCop.Analyzers.ReadabilityRules.SA1130CodeFixProvider>;
12+
813
public partial class SA1130CSharp12UnitTests : SA1130CSharp11UnitTests
914
{
15+
protected override DiagnosticResult[] GetExpectedResultCodeFixSpecialCases()
16+
{
17+
return new[]
18+
{
19+
Diagnostic().WithLocation(8, 20),
20+
Diagnostic().WithLocation(9, 20),
21+
Diagnostic().WithLocation(10, 25),
22+
Diagnostic().WithLocation(11, 30),
23+
Diagnostic().WithLocation(12, 30),
24+
DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53),
25+
Diagnostic().WithLocation(13, 30),
26+
DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47),
27+
Diagnostic().WithLocation(14, 30),
28+
DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47),
29+
Diagnostic().WithLocation(15, 25),
30+
DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42),
31+
DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47),
32+
};
33+
}
34+
35+
protected override DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases()
36+
{
37+
return new DiagnosticResult[]
38+
{
39+
Diagnostic().WithLocation(12, 30),
40+
DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53),
41+
Diagnostic().WithLocation(13, 30),
42+
DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47),
43+
Diagnostic().WithLocation(14, 30),
44+
DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47),
45+
Diagnostic().WithLocation(15, 25),
46+
DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42),
47+
DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47),
48+
};
49+
}
50+
51+
protected override DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions()
52+
{
53+
return new[]
54+
{
55+
Diagnostic().WithSpan(4, 50, 4, 58),
56+
DiagnosticResult.CompilerError("CS1660").WithLocation(4, 50),
57+
};
58+
}
1059
}
1160
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1015CSharp12UnitTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
55
{
6+
using Microsoft.CodeAnalysis.Testing;
67
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;
78

89
public partial class SA1015CSharp12UnitTests : SA1015CSharp11UnitTests
910
{
11+
protected override DiagnosticResult[] GetExpectedResultMissingToken()
12+
{
13+
return new[]
14+
{
15+
DiagnosticResult.CompilerError("CS1003").WithLocation(7, 35).WithArguments(","),
16+
DiagnosticResult.CompilerError("CS1003").WithLocation(7, 36).WithArguments(">"),
17+
DiagnosticResult.CompilerError("CS1026").WithLocation(7, 36),
18+
};
19+
}
1020
}
1121
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1018CSharp12UnitTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
55
{
6+
using Microsoft.CodeAnalysis.Testing;
67
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;
78

89
public partial class SA1018CSharp12UnitTests : SA1018CSharp11UnitTests
910
{
11+
protected override DiagnosticResult[] GetExpectedResultSyntaxErrorAtEndOfFile()
12+
{
13+
return new[]
14+
{
15+
DiagnosticResult.CompilerError("CS1031").WithLocation(10, 2),
16+
DiagnosticResult.CompilerError("CS8803").WithLocation(11, 1),
17+
DiagnosticResult.CompilerError("CS8805").WithLocation(11, 1),
18+
DiagnosticResult.CompilerError("CS1001").WithLocation(11, 2),
19+
DiagnosticResult.CompilerError("CS1002").WithLocation(11, 2),
20+
};
21+
}
1022
}
1123
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1130UnitTests.cs

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -218,33 +218,10 @@ private void Method(object o)
218218
Action<int> h = delegate (int x, __arglist) { Console.WriteLine(); };
219219
}
220220
}";
221-
var expected = new[]
222-
{
223-
Diagnostic().WithLocation(8, 20),
224-
Diagnostic().WithLocation(9, 20),
225-
Diagnostic().WithLocation(10, 25),
226-
Diagnostic().WithLocation(11, 30),
227-
Diagnostic().WithLocation(12, 30),
228-
Diagnostic(CS1065).WithLocation(12, 53),
229-
Diagnostic().WithLocation(13, 30),
230-
Diagnostic(CS7014).WithLocation(13, 47),
231-
Diagnostic().WithLocation(14, 30),
232-
Diagnostic(CS1670).WithLocation(14, 47),
233-
Diagnostic().WithLocation(15, 25),
234-
Diagnostic(CS1669).WithLocation(15, 42),
235-
};
236221

237-
var expectedAfterFix = new[]
238-
{
239-
Diagnostic().WithLocation(12, 30),
240-
Diagnostic(CS1065).WithLocation(12, 53),
241-
Diagnostic().WithLocation(13, 30),
242-
Diagnostic(CS7014).WithLocation(13, 47),
243-
Diagnostic().WithLocation(14, 30),
244-
Diagnostic(CS1670).WithLocation(14, 47),
245-
Diagnostic().WithLocation(15, 25),
246-
Diagnostic(CS1669).WithLocation(15, 42),
247-
};
222+
var expected = this.GetExpectedResultCodeFixSpecialCases();
223+
224+
var expectedAfterFix = this.GetExpectedResultAfterFixCodeFixSpecialCases();
248225

249226
var test = new CSharpTest
250227
{
@@ -828,11 +805,7 @@ public class TestClass
828805
}
829806
";
830807

831-
DiagnosticResult[] expected =
832-
{
833-
Diagnostic().WithSpan(4, 50, 4, 58),
834-
DiagnosticResult.CompilerError("CS1660").WithMessage("Cannot convert anonymous method to type 'EventHandler[]' because it is not a delegate type").WithSpan(4, 50, 4, 62),
835-
};
808+
var expected = this.GetExpectedResultVerifyInvalidCodeConstructions();
836809

837810
var test = new CSharpTest
838811
{
@@ -1010,5 +983,48 @@ public void Test()
1010983

1011984
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
1012985
}
986+
987+
protected virtual DiagnosticResult[] GetExpectedResultCodeFixSpecialCases()
988+
{
989+
return new[]
990+
{
991+
Diagnostic().WithLocation(8, 20),
992+
Diagnostic().WithLocation(9, 20),
993+
Diagnostic().WithLocation(10, 25),
994+
Diagnostic().WithLocation(11, 30),
995+
Diagnostic().WithLocation(12, 30),
996+
Diagnostic(CS1065).WithLocation(12, 53),
997+
Diagnostic().WithLocation(13, 30),
998+
Diagnostic(CS7014).WithLocation(13, 47),
999+
Diagnostic().WithLocation(14, 30),
1000+
Diagnostic(CS1670).WithLocation(14, 47),
1001+
Diagnostic().WithLocation(15, 25),
1002+
Diagnostic(CS1669).WithLocation(15, 42),
1003+
};
1004+
}
1005+
1006+
protected virtual DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases()
1007+
{
1008+
return new[]
1009+
{
1010+
Diagnostic().WithLocation(12, 30),
1011+
Diagnostic(CS1065).WithLocation(12, 53),
1012+
Diagnostic().WithLocation(13, 30),
1013+
Diagnostic(CS7014).WithLocation(13, 47),
1014+
Diagnostic().WithLocation(14, 30),
1015+
Diagnostic(CS1670).WithLocation(14, 47),
1016+
Diagnostic().WithLocation(15, 25),
1017+
Diagnostic(CS1669).WithLocation(15, 42),
1018+
};
1019+
}
1020+
1021+
protected virtual DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions()
1022+
{
1023+
return new[]
1024+
{
1025+
Diagnostic().WithSpan(4, 50, 4, 58),
1026+
DiagnosticResult.CompilerError("CS1660").WithMessage("Cannot convert anonymous method to type 'EventHandler[]' because it is not a delegate type").WithSpan(4, 50, 4, 62),
1027+
};
1028+
}
10131029
}
10141030
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1015UnitTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,7 @@ void Method()
376376
}
377377
";
378378

379-
DiagnosticResult[] expected =
380-
{
381-
DiagnosticResult.CompilerError("CS1003").WithMessage("Syntax error, '>' expected").WithLocation(7, 35),
382-
};
379+
var expected = this.GetExpectedResultMissingToken();
383380

384381
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
385382
}
@@ -432,5 +429,13 @@ public void TestMethod2(object input)
432429

433430
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
434431
}
432+
433+
protected virtual DiagnosticResult[] GetExpectedResultMissingToken()
434+
{
435+
return new[]
436+
{
437+
DiagnosticResult.CompilerError("CS1003").WithMessage("Syntax error, '>' expected").WithLocation(7, 35),
438+
};
439+
}
435440
}
436441
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1018UnitTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,17 @@ private void Test()
129129
?
130130
";
131131

132-
DiagnosticResult[] expected =
132+
var expected = this.GetExpectedResultSyntaxErrorAtEndOfFile();
133+
134+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
135+
}
136+
137+
protected virtual DiagnosticResult[] GetExpectedResultSyntaxErrorAtEndOfFile()
138+
{
139+
return new[]
133140
{
134141
DiagnosticResult.CompilerError("CS1031").WithMessage("Type expected").WithLocation(10, 2),
135142
};
136-
137-
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
138143
}
139144
}
140145
}

0 commit comments

Comments
 (0)