Skip to content

Commit 6b2e1ef

Browse files
committed
Updated SA1621. Merged code with SA1620.
1 parent 34dce82 commit 6b2e1ef

7 files changed

Lines changed: 420 additions & 178 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1620UnitTests.cs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
1414
using Xunit;
1515

1616
/// <summary>
17-
/// This class contains unit tests for <see cref="SA1620GenericTypeParameterDocumentationMustMatchTypeParameters"/>.
17+
/// This class contains unit tests for the SA1620 diagnostic.
1818
/// </summary>
1919
public class SA1620UnitTests : DiagnosticVerifier
2020
{
21-
private const string OrderFormatString = "The type parameter documentation for '{0}' should be at position {1}.";
22-
private const string ParameterDoesNotExistFormatString = "The type parameter '{0}' does not exist.";
23-
2421
public static IEnumerable<object[]> Members
2522
{
2623
get
@@ -160,8 +157,7 @@ public class ClassName
160157
public ##
161158
}";
162159

163-
var diagnostic = this.CSharpDiagnostic()
164-
.WithMessageFormat(OrderFormatString);
160+
var diagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620WrongOrderDescriptor);
165161

166162
var expected = new[]
167163
{
@@ -184,8 +180,7 @@ public async Task TestTypesWithAllDocumentationWrongOrderAsync(string p)
184180
/// <typeparam name=""Ta"">Param 1</param>
185181
public ##";
186182

187-
var diagnostic = this.CSharpDiagnostic()
188-
.WithMessageFormat(OrderFormatString);
183+
var diagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620WrongOrderDescriptor);
189184

190185
var expected = new[]
191186
{
@@ -297,9 +292,7 @@ public class ClassName
297292
public ##
298293
}";
299294

300-
var diagnostic = this.CSharpDiagnostic()
301-
.WithMessageFormat(ParameterDoesNotExistFormatString);
302-
295+
var diagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620MissingTypeParameterDescriptor);
303296
var expected = diagnostic.WithLocation(12, 26).WithArguments("Tc");
304297

305298
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false);
@@ -318,9 +311,7 @@ public async Task TestTypesWithInvalidDocumentationAsync(string p)
318311
/// <typeparam name=""Tc"">Param 3</param>
319312
public ##";
320313

321-
var diagnostic = this.CSharpDiagnostic()
322-
.WithMessageFormat(ParameterDoesNotExistFormatString);
323-
314+
var diagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620MissingTypeParameterDescriptor);
324315
var expected = diagnostic.WithLocation(7, 22).WithArguments("Tc");
325316

326317
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false);
@@ -345,9 +336,7 @@ public class ClassName
345336
public ##
346337
}";
347338

348-
var diagnostic = this.CSharpDiagnostic()
349-
.WithMessageFormat(OrderFormatString);
350-
339+
var diagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620WrongOrderDescriptor);
351340
var expected = diagnostic.WithLocation(12, 26).WithArguments("Tb", 2);
352341

353342
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false);
@@ -366,9 +355,7 @@ public async Task TestTypesWithTooManyDocumentationAsync(string p)
366355
/// <typeparam name=""Tb"">Param 3</param>
367356
public ##";
368357

369-
var diagnostic = this.CSharpDiagnostic()
370-
.WithMessageFormat(OrderFormatString);
371-
358+
var diagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620WrongOrderDescriptor);
372359
var expected = diagnostic.WithLocation(7, 22).WithArguments("Tb", 2);
373360

374361
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false);
@@ -438,10 +425,11 @@ public async Task TestTypeWithWronglyOrderedTypeParamInIncludedDocumentationAsyn
438425
/// <include file='TypeWithWronglyOrderedTypeparamsDoc.xml' path='/Foo/*'/>
439426
public ##
440427
";
428+
var diagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620WrongOrderDescriptor);
441429
DiagnosticResult[] expected =
442430
{
443-
this.CSharpDiagnostic().WithLocation(2, 5).WithMessageFormat(OrderFormatString).WithArguments("Tb", 2),
444-
this.CSharpDiagnostic().WithLocation(2, 5).WithMessageFormat(OrderFormatString).WithArguments("Ta", 1),
431+
diagnostic.WithLocation(2, 5).WithArguments("Tb", 2),
432+
diagnostic.WithLocation(2, 5).WithArguments("Ta", 1),
445433
};
446434

447435
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false);
@@ -460,10 +448,14 @@ public async Task TestTypeWithMissingTypeParamInIncludedDocumentationAsync(strin
460448
/// <include file='TypeWithMissingTypeparamDoc.xml' path='/Foo/*'/>
461449
public ##
462450
";
451+
452+
var wrongOrderDiagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620WrongOrderDescriptor);
453+
var missingDiagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620MissingTypeParameterDescriptor);
454+
463455
DiagnosticResult[] expected =
464456
{
465-
this.CSharpDiagnostic().WithLocation(2, 5).WithMessageFormat(OrderFormatString).WithArguments("Tb", 2),
466-
this.CSharpDiagnostic().WithLocation(2, 5).WithMessageFormat(ParameterDoesNotExistFormatString).WithArguments("Tc"),
457+
wrongOrderDiagnostic.WithLocation(2, 5).WithArguments("Tb", 2),
458+
missingDiagnostic.WithLocation(2, 5).WithArguments("Tc"),
467459
};
468460

469461
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false);
@@ -549,10 +541,11 @@ public class TestClass
549541
public ##
550542
}
551543
";
544+
var diagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620WrongOrderDescriptor);
552545
DiagnosticResult[] expected =
553546
{
554-
this.CSharpDiagnostic().WithLocation(5, 9).WithMessageFormat(OrderFormatString).WithArguments("Tb", 2),
555-
this.CSharpDiagnostic().WithLocation(5, 9).WithMessageFormat(OrderFormatString).WithArguments("Ta", 1),
547+
diagnostic.WithLocation(5, 9).WithArguments("Tb", 2),
548+
diagnostic.WithLocation(5, 9).WithArguments("Ta", 1),
556549
};
557550

558551
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false);
@@ -575,10 +568,14 @@ public class TestClass
575568
public ##
576569
}
577570
";
571+
572+
var wrongOrderDiagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620WrongOrderDescriptor);
573+
var missingDiagnostic = this.CSharpDiagnostic(GenericTypeParameterDocumentationAnalyzer.SA1620MissingTypeParameterDescriptor);
574+
578575
DiagnosticResult[] expected =
579576
{
580-
this.CSharpDiagnostic().WithLocation(5, 9).WithMessageFormat(OrderFormatString).WithArguments("Tb", 2),
581-
this.CSharpDiagnostic().WithLocation(5, 9).WithMessageFormat(ParameterDoesNotExistFormatString).WithArguments("Tc"),
577+
wrongOrderDiagnostic.WithLocation(5, 9).WithArguments("Tb", 2),
578+
missingDiagnostic.WithLocation(5, 9).WithArguments("Tc"),
582579
};
583580

584581
await this.VerifyCSharpDiagnosticAsync(testCode.Replace("##", p), expected, CancellationToken.None).ConfigureAwait(false);
@@ -687,7 +684,7 @@ protected override Project ApplyCompilationOptions(Project project)
687684

688685
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
689686
{
690-
yield return new SA1620GenericTypeParameterDocumentationMustMatchTypeParameters();
687+
yield return new GenericTypeParameterDocumentationAnalyzer();
691688
}
692689
}
693690
}

0 commit comments

Comments
 (0)