@@ -50,5 +50,67 @@ class TestClass
5050
5151 await VerifyCSharpFixAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
5252 }
53+
54+ [ Fact ]
55+ [ WorkItem ( 3931 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3931" ) ]
56+ public async Task TestLambdaAfterCommaInCollectionExpressionAsync ( )
57+ {
58+ var testCode = @"
59+ class TestClass
60+ {
61+ private System.Func<int, int, int>[] functions = [(x, y) => x + y,{|#0:(|}x, y) => x - y];
62+ }
63+ " ;
64+
65+ var fixedCode = @"
66+ class TestClass
67+ {
68+ private System.Func<int, int, int>[] functions = [(x, y) => x + y, (x, y) => x - y];
69+ }
70+ " ;
71+
72+ var expected = Diagnostic ( DescriptorPreceded ) . WithLocation ( 0 ) ;
73+ await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
74+ }
75+
76+ [ Fact ]
77+ [ WorkItem ( 3931 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3931" ) ]
78+ public async Task TestLambdaAfterSpreadInCollectionExpressionAsync ( )
79+ {
80+ var testCode = @"
81+ class TestClass
82+ {
83+ private static System.Func<int, int, int>[] existing = [(x, y) => x + y];
84+ private System.Func<int, int, int>[] functions = [..existing,{|#0:(|}x, y) => x - y];
85+ }
86+ " ;
87+
88+ var fixedCode = @"
89+ class TestClass
90+ {
91+ private static System.Func<int, int, int>[] existing = [(x, y) => x + y];
92+ private System.Func<int, int, int>[] functions = [..existing, (x, y) => x - y];
93+ }
94+ " ;
95+
96+ var expected = Diagnostic ( DescriptorPreceded ) . WithLocation ( 0 ) ;
97+ await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
98+ }
99+
100+ [ Fact ]
101+ [ WorkItem ( 3931 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3931" ) ]
102+ public async Task TestLambdaWithBracketOnPreviousLineAsync ( )
103+ {
104+ var testCode = @"
105+ class TestClass
106+ {
107+ private System.Func<int, int, int>[] functions = [
108+ (x, y) => x + y
109+ ];
110+ }
111+ " ;
112+
113+ await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
114+ }
53115 }
54116}
0 commit comments