33
44namespace StyleCop . Analyzers . Test . MaintainabilityRules
55{
6+ using System . Linq ;
67 using System . Threading ;
78 using System . Threading . Tasks ;
89 using TestHelper ;
@@ -32,18 +33,30 @@ public async Task TestTwoElementsAsync()
3233%1 Bar
3334{
3435}" ;
35- var fixedCode = @"%1 Foo
36+
37+ var fixedCode = new [ ]
38+ {
39+ @"%1 Foo
3640{
3741}
38- " ;
42+ " ,
43+ @"%1 Bar
44+ {
45+ }"
46+ } ;
3947
4048 DiagnosticResult expected = this . CSharpDiagnostic ( ) . WithLocation ( 4 , this . Keyword . Length + 2 ) ;
4149
4250 await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "%1" , this . Keyword ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
43- await this . VerifyCSharpDiagnosticAsync ( fixedCode . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
51+
52+ foreach ( var code in fixedCode )
53+ {
54+ await this . VerifyCSharpDiagnosticAsync ( code . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
55+ }
56+
4457 if ( this . SupportsCodeFix )
4558 {
46- await this . VerifyCSharpFixAsync ( testCode . Replace ( "%1" , this . Keyword ) , fixedCode . Replace ( "%1" , this . Keyword ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
59+ await this . VerifyCSharpFixAsync ( new [ ] { testCode . Replace ( "%1" , this . Keyword ) } , fixedCode . Select ( c => c . Replace ( "%1" , this . Keyword ) ) . ToArray ( ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
4760 }
4861 }
4962
@@ -59,22 +72,38 @@ public async Task TestThreeElementsAsync()
5972%1 FooBar
6073{
6174}" ;
62- var fixedCode = @"%1 Foo
75+
76+ var fixedCode = new [ ]
77+ {
78+ @"%1 Foo
79+ {
80+ }
81+ " ,
82+ @"%1 Bar
6383{
6484}
65- " ;
85+ " ,
86+ @"%1 FooBar
87+ {
88+ }"
89+ } ;
6690
6791 DiagnosticResult [ ] expected =
68- {
69- this . CSharpDiagnostic ( ) . WithLocation ( 4 , this . Keyword . Length + 2 ) ,
70- this . CSharpDiagnostic ( ) . WithLocation ( 7 , this . Keyword . Length + 2 )
71- } ;
92+ {
93+ this . CSharpDiagnostic ( ) . WithLocation ( 4 , this . Keyword . Length + 2 ) ,
94+ this . CSharpDiagnostic ( ) . WithLocation ( 7 , this . Keyword . Length + 2 )
95+ } ;
7296
7397 await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "%1" , this . Keyword ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
74- await this . VerifyCSharpDiagnosticAsync ( fixedCode . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
98+
99+ foreach ( var code in fixedCode )
100+ {
101+ await this . VerifyCSharpDiagnosticAsync ( code . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
102+ }
103+
75104 if ( this . SupportsCodeFix )
76105 {
77- await this . VerifyCSharpFixAsync ( testCode . Replace ( "%1" , this . Keyword ) , fixedCode . Replace ( "%1" , this . Keyword ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
106+ await this . VerifyCSharpFixAsync ( new [ ] { testCode . Replace ( "%1" , this . Keyword ) } , fixedCode . Select ( c => c . Replace ( "%1" , this . Keyword ) ) . ToArray ( ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
78107 }
79108 }
80109
@@ -89,18 +118,32 @@ public async Task TestRemoveWarningSuppressionAsync()
89118#pragma warning disable SomeWarning
90119#pragma warning restore SomeWarning
91120}" ;
92- var fixedCode = @"%1 Foo
121+
122+ var fixedCode = new [ ]
123+ {
124+ @"%1 Foo
93125{
94126}
95- " ;
127+ " ,
128+ @"%1 Bar
129+ {
130+ #pragma warning disable SomeWarning
131+ #pragma warning restore SomeWarning
132+ }"
133+ } ;
96134
97135 DiagnosticResult expected = this . CSharpDiagnostic ( ) . WithLocation ( 4 , this . Keyword . Length + 2 ) ;
98136
99137 await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "%1" , this . Keyword ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
100- await this . VerifyCSharpDiagnosticAsync ( fixedCode . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
138+
139+ foreach ( var code in fixedCode )
140+ {
141+ await this . VerifyCSharpDiagnosticAsync ( code . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
142+ }
143+
101144 if ( this . SupportsCodeFix )
102145 {
103- await this . VerifyCSharpFixAsync ( testCode . Replace ( "%1" , this . Keyword ) , fixedCode . Replace ( "%1" , this . Keyword ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
146+ await this . VerifyCSharpFixAsync ( new [ ] { testCode . Replace ( "%1" , this . Keyword ) } , fixedCode . Select ( c => c . Replace ( "%1" , this . Keyword ) ) . ToArray ( ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
104147 }
105148 }
106149
@@ -116,18 +159,30 @@ public async Task TestPreserveWarningSuppressionAsync()
116159}" ;
117160
118161 // See https://github.com/dotnet/roslyn/issues/3999
119- var fixedCode = @"%1 Foo
162+ var fixedCode = new [ ]
163+ {
164+ @"%1 Foo
120165{
121166}
122- " ;
167+ " ,
168+ @"%1 Bar
169+ {
170+ #pragma warning disable SomeWarning
171+ }"
172+ } ;
123173
124174 DiagnosticResult expected = this . CSharpDiagnostic ( ) . WithLocation ( 4 , this . Keyword . Length + 2 ) ;
125175
126176 await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "%1" , this . Keyword ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
127- await this . VerifyCSharpDiagnosticAsync ( fixedCode . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
177+
178+ foreach ( var code in fixedCode )
179+ {
180+ await this . VerifyCSharpDiagnosticAsync ( code . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
181+ }
182+
128183 if ( this . SupportsCodeFix )
129184 {
130- await this . VerifyCSharpFixAsync ( testCode . Replace ( "%1" , this . Keyword ) , fixedCode . Replace ( "%1" , this . Keyword ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
185+ await this . VerifyCSharpFixAsync ( new [ ] { testCode . Replace ( "%1" , this . Keyword ) } , fixedCode . Select ( c => c . Replace ( "%1" , this . Keyword ) ) . ToArray ( ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
131186 }
132187 }
133188
@@ -142,18 +197,32 @@ public async Task TestRemovePreprocessorDirectivesAsync()
142197#if true
143198#endif
144199}" ;
145- var fixedCode = @"%1 Foo
200+
201+ var fixedCode = new [ ]
202+ {
203+ @"%1 Foo
146204{
147205}
148- " ;
206+ " ,
207+ @"%1 Bar
208+ {
209+ #if true
210+ #endif
211+ }"
212+ } ;
149213
150214 DiagnosticResult expected = this . CSharpDiagnostic ( ) . WithLocation ( 4 , this . Keyword . Length + 2 ) ;
151215
152216 await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "%1" , this . Keyword ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
153- await this . VerifyCSharpDiagnosticAsync ( fixedCode . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
217+
218+ foreach ( var code in fixedCode )
219+ {
220+ await this . VerifyCSharpDiagnosticAsync ( code . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
221+ }
222+
154223 if ( this . SupportsCodeFix )
155224 {
156- await this . VerifyCSharpFixAsync ( testCode . Replace ( "%1" , this . Keyword ) , fixedCode . Replace ( "%1" , this . Keyword ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
225+ await this . VerifyCSharpFixAsync ( new [ ] { testCode . Replace ( "%1" , this . Keyword ) } , fixedCode . Select ( c => c . Replace ( "%1" , this . Keyword ) ) . ToArray ( ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
157226 }
158227 }
159228
@@ -170,21 +239,35 @@ public async Task TestPreservePreprocessorDirectivesAsync()
170239}" ;
171240
172241 // See https://github.com/dotnet/roslyn/issues/3999
173- var fixedCode = @"%1 Foo
242+ var fixedCode = new [ ]
243+ {
244+ @"%1 Foo
174245{
175246#if true
176247}
177248
178249#endif
179- " ;
250+ " ,
251+ @"
252+ #if true
253+ %1 Bar
254+ {
255+ #endif
256+ }"
257+ } ;
180258
181259 DiagnosticResult expected = this . CSharpDiagnostic ( ) . WithLocation ( 5 , this . Keyword . Length + 2 ) ;
182260
183261 await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "%1" , this . Keyword ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
184- await this . VerifyCSharpDiagnosticAsync ( fixedCode . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
262+
263+ foreach ( var code in fixedCode )
264+ {
265+ await this . VerifyCSharpDiagnosticAsync ( code . Replace ( "%1" , this . Keyword ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
266+ }
267+
185268 if ( this . SupportsCodeFix )
186269 {
187- await this . VerifyCSharpFixAsync ( testCode . Replace ( "%1" , this . Keyword ) , fixedCode . Replace ( "%1" , this . Keyword ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
270+ await this . VerifyCSharpFixAsync ( new [ ] { testCode . Replace ( "%1" , this . Keyword ) } , fixedCode . Select ( c => c . Replace ( "%1" , this . Keyword ) ) . ToArray ( ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
188271 }
189272 }
190273 }
0 commit comments