@@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
11
11
using System . Threading . Tasks ;
12
12
using Microsoft . CodeAnalysis . Testing ;
13
13
using StyleCop . Analyzers . DocumentationRules ;
14
+ using StyleCop . Analyzers . Lightup ;
14
15
using StyleCop . Analyzers . Test . Verifiers ;
15
16
using Xunit ;
16
17
using static StyleCop . Analyzers . Test . Verifiers . CustomDiagnosticVerifier < StyleCop . Analyzers . DocumentationRules . SA1612ElementParameterDocumentationMustMatchElementParameters > ;
@@ -24,9 +25,26 @@ public static IEnumerable<object[]> Declarations
24
25
{
25
26
get
26
27
{
27
- yield return new object [ ] { " public ClassName {|#0:Method|}(string foo, string bar, string @new) { return null; }" } ;
28
- yield return new object [ ] { " public delegate ClassName {|#0:Method|}(string foo, string bar, string @new);" } ;
29
- yield return new object [ ] { " public ClassName {|#0:this|}[string foo, string bar, string @new] { get { return null; } set { } }" } ;
28
+ yield return new [ ] { " public ClassName {|#0:Method|}(string foo, string bar, string @new) { return null; }" } ;
29
+ yield return new [ ] { " public delegate ClassName {|#0:Method|}(string foo, string bar, string @new);" } ;
30
+ yield return new [ ] { " public ClassName {|#0:this|}[string foo, string bar, string @new] { get { return null; } set { } }" } ;
31
+
32
+ if ( LightupHelpers . SupportsCSharp9 )
33
+ {
34
+ yield return new [ ] { " public record {|#0:TestType|}(string foo, string bar, string @new) {}" } ;
35
+ }
36
+
37
+ if ( LightupHelpers . SupportsCSharp10 )
38
+ {
39
+ yield return new [ ] { " public record struct {|#0:TestType|}(string foo, string bar, string @new) {}" } ;
40
+ yield return new [ ] { " public record class {|#0:TestType|}(string foo, string bar, string @new) {}" } ;
41
+ }
42
+
43
+ if ( LightupHelpers . SupportsCSharp12 )
44
+ {
45
+ yield return new [ ] { " public struct {|#0:TestType|}(string foo, string bar, string @new) {}" } ;
46
+ yield return new [ ] { " public class {|#0:TestType|}(string foo, string bar, string @new) {}" } ;
47
+ }
30
48
}
31
49
}
32
50
@@ -165,11 +183,12 @@ public class ClassName
165
183
var diagnostic = Diagnostic ( )
166
184
. WithMessageFormat ( "The parameter documentation for '{0}' should be at position {1}" ) ;
167
185
168
- var expected = new [ ]
186
+ var normallyExpected = new [ ]
169
187
{
170
188
diagnostic . WithLocation ( 10 , 21 ) . WithArguments ( "new" , 3 ) ,
171
189
diagnostic . WithLocation ( 11 , 21 ) . WithArguments ( "foo" , 1 ) ,
172
190
} ;
191
+ var expected = GetExpectedDiagnostics ( normallyExpected , declaration ) ;
173
192
174
193
await VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
175
194
}
@@ -193,12 +212,13 @@ public class ClassName
193
212
$$
194
213
}" ;
195
214
196
- var expected = new [ ]
215
+ var normallyExpected = new [ ]
197
216
{
198
217
Diagnostic ( ) . WithLocation ( 10 , 21 ) . WithArguments ( "boo" ) ,
199
218
Diagnostic ( ) . WithLocation ( 11 , 21 ) . WithArguments ( "far" ) ,
200
219
Diagnostic ( ) . WithLocation ( 12 , 21 ) . WithArguments ( "foe" ) ,
201
220
} ;
221
+ var expected = GetExpectedDiagnostics ( normallyExpected , declaration ) ;
202
222
203
223
await VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
204
224
}
@@ -248,12 +268,13 @@ public class ClassName
248
268
var diagnostic = Diagnostic ( )
249
269
. WithMessageFormat ( "The parameter documentation for '{0}' should be at position {1}" ) ;
250
270
251
- var expected = new [ ]
271
+ var normallyExpected = new [ ]
252
272
{
253
273
diagnostic . WithLocation ( 10 , 22 ) . WithArguments ( "bar" , 2 ) ,
254
274
diagnostic . WithLocation ( 11 , 22 ) . WithArguments ( "new" , 3 ) ,
255
275
diagnostic . WithLocation ( 12 , 22 ) . WithArguments ( "foo" , 1 ) ,
256
276
} ;
277
+ var expected = GetExpectedDiagnostics ( normallyExpected , declaration ) ;
257
278
258
279
await VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
259
280
@@ -267,10 +288,11 @@ public class ClassName
267
288
}
268
289
" ;
269
290
270
- expected = new [ ]
291
+ normallyExpected = new [ ]
271
292
{
272
293
diagnostic . WithLocation ( 12 , 22 ) . WithArguments ( "foo" , 1 ) ,
273
294
} ;
295
+ expected = GetExpectedDiagnostics ( normallyExpected , declaration ) ;
274
296
275
297
await VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , testSettings , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
276
298
}
@@ -298,7 +320,8 @@ public class ClassName
298
320
var diagnostic = Diagnostic ( )
299
321
. WithMessageFormat ( "The parameter documentation for '{0}' should be at position {1}" ) ;
300
322
301
- var expected = diagnostic . WithLocation ( 13 , 22 ) . WithArguments ( "bar" , 2 ) ;
323
+ var normallyExpected = diagnostic . WithLocation ( 13 , 22 ) . WithArguments ( "bar" , 2 ) ;
324
+ var expected = GetExpectedDiagnostics ( normallyExpected , declaration ) ;
302
325
303
326
await VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
304
327
}
@@ -409,12 +432,13 @@ public class ClassName
409
432
$$
410
433
}" ;
411
434
412
- var expected = new [ ]
435
+ var normallyExpected = new [ ]
413
436
{
414
437
Diagnostic ( ) . WithLocation ( 0 ) . WithArguments ( "boo" ) ,
415
438
Diagnostic ( ) . WithLocation ( 0 ) . WithArguments ( "far" ) ,
416
439
Diagnostic ( ) . WithLocation ( 0 ) . WithArguments ( "foe" ) ,
417
440
} ;
441
+ var expected = GetExpectedDiagnostics ( normallyExpected , declaration ) ;
418
442
419
443
await VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
420
444
}
@@ -451,12 +475,13 @@ public class ClassName
451
475
var diagnostic = Diagnostic ( )
452
476
. WithMessageFormat ( "The parameter documentation for '{0}' should be at position {1}" ) ;
453
477
454
- var expected = new [ ]
478
+ var normallyExpected = new [ ]
455
479
{
456
480
diagnostic . WithLocation ( 0 ) . WithArguments ( "new" , 3 ) ,
457
481
diagnostic . WithLocation ( 0 ) . WithArguments ( "foo" , 1 ) ,
458
482
diagnostic . WithLocation ( 0 ) . WithArguments ( "bar" , 2 ) ,
459
483
} ;
484
+ var expected = GetExpectedDiagnostics ( normallyExpected , declaration ) ;
460
485
461
486
await VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
462
487
@@ -473,11 +498,12 @@ public class ClassName
473
498
}
474
499
" ;
475
500
476
- expected = new [ ]
501
+ normallyExpected = new [ ]
477
502
{
478
503
diagnostic . WithLocation ( 0 ) . WithArguments ( "foo" , 1 ) ,
479
504
diagnostic . WithLocation ( 0 ) . WithArguments ( "bar" , 2 ) ,
480
505
} ;
506
+ expected = GetExpectedDiagnostics ( normallyExpected , declaration ) ;
481
507
482
508
await VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , testSettings , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
483
509
}
@@ -499,7 +525,8 @@ public class ClassName
499
525
var diagnostic = Diagnostic ( )
500
526
. WithMessageFormat ( "The parameter documentation for '{0}' should be at position {1}" ) ;
501
527
502
- var expected = diagnostic . WithLocation ( 0 ) . WithArguments ( "bar" , 2 ) ;
528
+ var normallyExpected = diagnostic . WithLocation ( 0 ) . WithArguments ( "bar" , 2 ) ;
529
+ var expected = GetExpectedDiagnostics ( normallyExpected , declaration ) ;
503
530
504
531
await VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
505
532
}
@@ -535,8 +562,27 @@ public class ClassName
535
562
await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
536
563
}
537
564
538
- private static Task VerifyCSharpDiagnosticAsync ( string source , DiagnosticResult expected , CancellationToken cancellationToken )
539
- => VerifyCSharpDiagnosticAsync ( source , testSettings : null , new [ ] { expected } , ignoreCompilerDiagnostics : false , cancellationToken ) ;
565
+ private static DiagnosticResult [ ] GetExpectedDiagnostics ( DiagnosticResult normallyExpected , string declaration )
566
+ {
567
+ return GetExpectedDiagnostics ( new [ ] { normallyExpected } , declaration ) ;
568
+ }
569
+
570
+ // Syntax node actions for type declarations with a primary constructor were called twice
571
+ // before support for c# 11 was added.
572
+ private static DiagnosticResult [ ] GetExpectedDiagnostics ( DiagnosticResult [ ] normallyExpected , string declaration )
573
+ {
574
+ var isPrimaryConstructor = declaration . Contains ( "record" ) || declaration . Contains ( "class" ) || declaration . Contains ( "struct" ) ;
575
+
576
+ if ( isPrimaryConstructor && ! LightupHelpers . SupportsCSharp11 )
577
+ {
578
+ // Diagnostic issued twice because of https://github.com/dotnet/roslyn/issues/53136 and https://github.com/dotnet/roslyn/issues/70488
579
+ return normallyExpected . Concat ( normallyExpected ) . ToArray ( ) ;
580
+ }
581
+ else
582
+ {
583
+ return normallyExpected ;
584
+ }
585
+ }
540
586
541
587
private static Task VerifyCSharpDiagnosticAsync ( string source , DiagnosticResult [ ] expected , CancellationToken cancellationToken )
542
588
=> VerifyCSharpDiagnosticAsync ( source , testSettings : null , expected , ignoreCompilerDiagnostics : false , cancellationToken ) ;
0 commit comments