diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1130CSharp12UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1130CSharp12UnitTests.cs index 74d18935a..18d3b12e9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1130CSharp12UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1130CSharp12UnitTests.cs @@ -3,9 +3,58 @@ namespace StyleCop.Analyzers.Test.CSharp12.ReadabilityRules { + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp11.ReadabilityRules; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.ReadabilityRules.SA1130UseLambdaSyntax, + StyleCop.Analyzers.ReadabilityRules.SA1130CodeFixProvider>; + public partial class SA1130CSharp12UnitTests : SA1130CSharp11UnitTests { + protected override DiagnosticResult[] GetExpectedResultCodeFixSpecialCases() + { + return new[] + { + Diagnostic().WithLocation(8, 20), + Diagnostic().WithLocation(9, 20), + Diagnostic().WithLocation(10, 25), + Diagnostic().WithLocation(11, 30), + Diagnostic().WithLocation(12, 30), + DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53), + Diagnostic().WithLocation(13, 30), + DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47), + Diagnostic().WithLocation(14, 30), + DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47), + Diagnostic().WithLocation(15, 25), + DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42), + DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47), + }; + } + + protected override DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases() + { + return new DiagnosticResult[] + { + Diagnostic().WithLocation(12, 30), + DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53), + Diagnostic().WithLocation(13, 30), + DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47), + Diagnostic().WithLocation(14, 30), + DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47), + Diagnostic().WithLocation(15, 25), + DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42), + DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47), + }; + } + + protected override DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions() + { + return new[] + { + Diagnostic().WithSpan(4, 50, 4, 58), + DiagnosticResult.CompilerError("CS1660").WithLocation(4, 50), + }; + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1015CSharp12UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1015CSharp12UnitTests.cs index 192b20aba..a01446ce9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1015CSharp12UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1015CSharp12UnitTests.cs @@ -3,9 +3,19 @@ namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules { + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp11.SpacingRules; public partial class SA1015CSharp12UnitTests : SA1015CSharp11UnitTests { + protected override DiagnosticResult[] GetExpectedResultMissingToken() + { + return new[] + { + DiagnosticResult.CompilerError("CS1003").WithLocation(7, 35).WithArguments(","), + DiagnosticResult.CompilerError("CS1003").WithLocation(7, 36).WithArguments(">"), + DiagnosticResult.CompilerError("CS1026").WithLocation(7, 36), + }; + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1018CSharp12UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1018CSharp12UnitTests.cs index 68449d0b7..c07aa71e4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1018CSharp12UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1018CSharp12UnitTests.cs @@ -3,9 +3,21 @@ namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules { + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp11.SpacingRules; public partial class SA1018CSharp12UnitTests : SA1018CSharp11UnitTests { + protected override DiagnosticResult[] GetExpectedResultSyntaxErrorAtEndOfFile() + { + return new[] + { + DiagnosticResult.CompilerError("CS1031").WithLocation(10, 2), + DiagnosticResult.CompilerError("CS8803").WithLocation(11, 1), + DiagnosticResult.CompilerError("CS8805").WithLocation(11, 1), + DiagnosticResult.CompilerError("CS1001").WithLocation(11, 2), + DiagnosticResult.CompilerError("CS1002").WithLocation(11, 2), + }; + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1130UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1130UnitTests.cs index ef2831880..7d12144e2 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1130UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1130UnitTests.cs @@ -218,33 +218,10 @@ private void Method(object o) Action h = delegate (int x, __arglist) { Console.WriteLine(); }; } }"; - var expected = new[] - { - Diagnostic().WithLocation(8, 20), - Diagnostic().WithLocation(9, 20), - Diagnostic().WithLocation(10, 25), - Diagnostic().WithLocation(11, 30), - Diagnostic().WithLocation(12, 30), - Diagnostic(CS1065).WithLocation(12, 53), - Diagnostic().WithLocation(13, 30), - Diagnostic(CS7014).WithLocation(13, 47), - Diagnostic().WithLocation(14, 30), - Diagnostic(CS1670).WithLocation(14, 47), - Diagnostic().WithLocation(15, 25), - Diagnostic(CS1669).WithLocation(15, 42), - }; - var expectedAfterFix = new[] - { - Diagnostic().WithLocation(12, 30), - Diagnostic(CS1065).WithLocation(12, 53), - Diagnostic().WithLocation(13, 30), - Diagnostic(CS7014).WithLocation(13, 47), - Diagnostic().WithLocation(14, 30), - Diagnostic(CS1670).WithLocation(14, 47), - Diagnostic().WithLocation(15, 25), - Diagnostic(CS1669).WithLocation(15, 42), - }; + var expected = this.GetExpectedResultCodeFixSpecialCases(); + + var expectedAfterFix = this.GetExpectedResultAfterFixCodeFixSpecialCases(); var test = new CSharpTest { @@ -828,11 +805,7 @@ public class TestClass } "; - DiagnosticResult[] expected = - { - Diagnostic().WithSpan(4, 50, 4, 58), - DiagnosticResult.CompilerError("CS1660").WithMessage("Cannot convert anonymous method to type 'EventHandler[]' because it is not a delegate type").WithSpan(4, 50, 4, 62), - }; + var expected = this.GetExpectedResultVerifyInvalidCodeConstructions(); var test = new CSharpTest { @@ -1010,5 +983,48 @@ public void Test() await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false); } + + protected virtual DiagnosticResult[] GetExpectedResultCodeFixSpecialCases() + { + return new[] + { + Diagnostic().WithLocation(8, 20), + Diagnostic().WithLocation(9, 20), + Diagnostic().WithLocation(10, 25), + Diagnostic().WithLocation(11, 30), + Diagnostic().WithLocation(12, 30), + Diagnostic(CS1065).WithLocation(12, 53), + Diagnostic().WithLocation(13, 30), + Diagnostic(CS7014).WithLocation(13, 47), + Diagnostic().WithLocation(14, 30), + Diagnostic(CS1670).WithLocation(14, 47), + Diagnostic().WithLocation(15, 25), + Diagnostic(CS1669).WithLocation(15, 42), + }; + } + + protected virtual DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases() + { + return new[] + { + Diagnostic().WithLocation(12, 30), + Diagnostic(CS1065).WithLocation(12, 53), + Diagnostic().WithLocation(13, 30), + Diagnostic(CS7014).WithLocation(13, 47), + Diagnostic().WithLocation(14, 30), + Diagnostic(CS1670).WithLocation(14, 47), + Diagnostic().WithLocation(15, 25), + Diagnostic(CS1669).WithLocation(15, 42), + }; + } + + protected virtual DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions() + { + return new[] + { + Diagnostic().WithSpan(4, 50, 4, 58), + DiagnosticResult.CompilerError("CS1660").WithMessage("Cannot convert anonymous method to type 'EventHandler[]' because it is not a delegate type").WithSpan(4, 50, 4, 62), + }; + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1015UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1015UnitTests.cs index 2429e609b..e6e7822be 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1015UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1015UnitTests.cs @@ -376,10 +376,7 @@ void Method() } "; - DiagnosticResult[] expected = - { - DiagnosticResult.CompilerError("CS1003").WithMessage("Syntax error, '>' expected").WithLocation(7, 35), - }; + var expected = this.GetExpectedResultMissingToken(); await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); } @@ -432,5 +429,13 @@ public void TestMethod2(object input) await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); } + + protected virtual DiagnosticResult[] GetExpectedResultMissingToken() + { + return new[] + { + DiagnosticResult.CompilerError("CS1003").WithMessage("Syntax error, '>' expected").WithLocation(7, 35), + }; + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1018UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1018UnitTests.cs index 29129cf56..9ed256e69 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1018UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1018UnitTests.cs @@ -129,12 +129,17 @@ private void Test() ? "; - DiagnosticResult[] expected = + var expected = this.GetExpectedResultSyntaxErrorAtEndOfFile(); + + await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + } + + protected virtual DiagnosticResult[] GetExpectedResultSyntaxErrorAtEndOfFile() + { + return new[] { DiagnosticResult.CompilerError("CS1031").WithMessage("Type expected").WithLocation(10, 2), }; - - await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); } } }