66namespace StyleCop . Analyzers . Test . ReadabilityRules
77{
88 using System . Diagnostics . CodeAnalysis ;
9+ using System . Linq ;
910 using System . Threading ;
1011 using System . Threading . Tasks ;
1112 using Microsoft . CodeAnalysis ;
@@ -190,14 +191,14 @@ internal class TypeName
190191{
191192 private void Method(object o)
192193 {
193- Action a = delegate() { Console.WriteLine(); };
194- Action b = delegate() { Console.WriteLine(); };
195- Action<int> c = delegate(int x) { Console.WriteLine(); };
196- Action<int, int> d = delegate(int x, int y) { Console.WriteLine(); };
197- Action<int, int> e = delegate (int x, int y = 0) { Console.WriteLine(); };
198- Action<int, int> f = delegate (int x, [Obsolete]int y) { Console.WriteLine(); };
199- Action<int, int> g = delegate (int x, params int y) { Console.WriteLine(); };
200- Action<int> h = delegate (int x, __arglist) { Console.WriteLine(); };
194+ Action a = [| delegate|] () { Console.WriteLine(); };
195+ Action b = [| delegate|] () { Console.WriteLine(); };
196+ Action<int> c = [| delegate|] (int x) { Console.WriteLine(); };
197+ Action<int, int> d = [| delegate|] (int x, int y) { Console.WriteLine(); };
198+ Action<int, int> e = [| delegate|] (int x, int y = 0) { Console.WriteLine(); };
199+ Action<int, int> f = [| delegate|] (int x, [Obsolete]int y) { Console.WriteLine(); };
200+ Action<int, int> g = [| delegate|] (int x, params int y) { Console.WriteLine(); };
201+ Action<int> h = [| delegate|] (int x, __arglist) { Console.WriteLine(); };
201202 }
202203}" ;
203204
@@ -219,9 +220,16 @@ private void Method(object o)
219220 }
220221}" ;
221222
222- var expected = this . GetExpectedResultCodeFixSpecialCases ( ) ;
223+ var expected = this . GetCompilerExpectedResultCodeFixSpecialCases ( ) ;
223224
224- var expectedAfterFix = this . GetExpectedResultAfterFixCodeFixSpecialCases ( ) ;
225+ var expectedAfterFix = this . GetCompilerExpectedResultCodeFixSpecialCases ( )
226+ . Concat ( new [ ]
227+ {
228+ Diagnostic ( ) . WithLocation ( 12 , 30 ) ,
229+ Diagnostic ( ) . WithLocation ( 13 , 30 ) ,
230+ Diagnostic ( ) . WithLocation ( 14 , 30 ) ,
231+ Diagnostic ( ) . WithLocation ( 15 , 25 ) ,
232+ } ) ;
225233
226234 var test = new CSharpTest
227235 {
@@ -801,11 +809,14 @@ public async Task VerifyInvalidCodeConstructionsAsync()
801809 var testCode = @"using System;
802810public class TestClass
803811{
804- public static EventHandler[] TestMethod() => delegate { };
812+ public static EventHandler[] TestMethod() => [| delegate|] { };
805813}
806814" ;
807815
808- var expected = this . GetExpectedResultVerifyInvalidCodeConstructions ( ) ;
816+ var expected = new [ ]
817+ {
818+ DiagnosticResult . CompilerError ( "CS1660" ) . WithLocation ( 4 , 50 ) ,
819+ } ;
809820
810821 var test = new CSharpTest
811822 {
@@ -984,47 +995,15 @@ public void Test()
984995 await VerifyCSharpFixAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
985996 }
986997
987- protected virtual DiagnosticResult [ ] GetExpectedResultCodeFixSpecialCases ( )
998+ protected virtual DiagnosticResult [ ] GetCompilerExpectedResultCodeFixSpecialCases ( )
988999 {
9891000 return new [ ]
9901001 {
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 ) ,
9961002 Diagnostic ( CS1065 ) . WithLocation ( 12 , 53 ) ,
997- Diagnostic ( ) . WithLocation ( 13 , 30 ) ,
9981003 Diagnostic ( CS7014 ) . WithLocation ( 13 , 47 ) ,
999- Diagnostic ( ) . WithLocation ( 14 , 30 ) ,
10001004 Diagnostic ( CS1670 ) . WithLocation ( 14 , 47 ) ,
1001- Diagnostic ( ) . WithLocation ( 15 , 25 ) ,
10021005 Diagnostic ( CS1669 ) . WithLocation ( 15 , 42 ) ,
10031006 } ;
10041007 }
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- }
10291008 }
10301009}
0 commit comments