Skip to content

Commit 9e41513

Browse files
committed
Add tests based on code coverage information
1 parent 1a7e90a commit 9e41513

File tree

9 files changed

+389
-19
lines changed

9 files changed

+389
-19
lines changed

DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC104CodeFixProvider.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace DocumentationAnalyzers.StyleRules
55
{
66
using System.Collections.Immutable;
77
using System.Composition;
8+
using System.Diagnostics;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using DocumentationAnalyzers.Helpers;
@@ -27,10 +28,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
2728
{
2829
foreach (var diagnostic in context.Diagnostics)
2930
{
30-
if (!FixableDiagnosticIds.Contains(diagnostic.Id))
31-
{
32-
continue;
33-
}
31+
Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)");
3432

3533
context.RegisterCodeFix(
3634
CodeAction.Create(

DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC105CodeFixProvider.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace DocumentationAnalyzers.StyleRules
55
{
66
using System.Collections.Immutable;
77
using System.Composition;
8+
using System.Diagnostics;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using DocumentationAnalyzers.Helpers;
@@ -27,10 +28,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
2728
{
2829
foreach (var diagnostic in context.Diagnostics)
2930
{
30-
if (!FixableDiagnosticIds.Contains(diagnostic.Id))
31-
{
32-
continue;
33-
}
31+
Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)");
3432

3533
context.RegisterCodeFix(
3634
CodeAction.Create(

DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC106CodeFixProvider.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace DocumentationAnalyzers.StyleRules
55
{
66
using System.Collections.Immutable;
77
using System.Composition;
8+
using System.Diagnostics;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using DocumentationAnalyzers.Helpers;
@@ -27,10 +28,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
2728
{
2829
foreach (var diagnostic in context.Diagnostics)
2930
{
30-
if (!FixableDiagnosticIds.Contains(diagnostic.Id))
31-
{
32-
continue;
33-
}
31+
Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)");
3432

3533
context.RegisterCodeFix(
3634
CodeAction.Create(

DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/StyleRules/DOC107CodeFixProvider.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ namespace DocumentationAnalyzers.StyleRules
55
{
66
using System.Collections.Immutable;
77
using System.Composition;
8+
using System.Diagnostics;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using DocumentationAnalyzers.Helpers;
1112
using Microsoft.CodeAnalysis;
1213
using Microsoft.CodeAnalysis.CodeActions;
1314
using Microsoft.CodeAnalysis.CodeFixes;
15+
using Microsoft.CodeAnalysis.CSharp;
1416
using Microsoft.CodeAnalysis.CSharp.Syntax;
1517

1618
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(DOC107CodeFixProvider))]
@@ -27,10 +29,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
2729
{
2830
foreach (var diagnostic in context.Diagnostics)
2931
{
30-
if (!FixableDiagnosticIds.Contains(diagnostic.Id))
31-
{
32-
continue;
33-
}
32+
Debug.Assert(FixableDiagnosticIds.Contains(diagnostic.Id), "Assertion failed: FixableDiagnosticIds.Contains(diagnostic.Id)");
3433

3534
context.RegisterCodeFix(
3635
CodeAction.Create(
@@ -49,7 +48,9 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
4948
var xmlElement = (XmlElementSyntax)root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true);
5049

5150
var newXmlElement = XmlSyntaxFactory.EmptyElement(XmlCommentHelper.SeeXmlTag)
52-
.AddAttributes(XmlSyntaxFactory.TextAttribute("cref", xmlElement.Content.ToFullString()))
51+
.AddAttributes(XmlSyntaxFactory.TextAttribute(
52+
"cref",
53+
SyntaxFactory.Token(SyntaxTriviaList.Empty, SyntaxKind.XmlTextLiteralToken, xmlElement.Content.ToFullString(), xmlElement.Content.ToFullString(), SyntaxTriviaList.Empty)))
5354
.WithTriviaFrom(xmlElement);
5455

5556
return document.WithSyntaxRoot(root.ReplaceNode(xmlElement, newXmlElement));

DocumentationAnalyzers/DocumentationAnalyzers.Test/StyleRules/DOC104UnitTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,74 @@ public async Task TestNonKeywordsAsync(string keyword)
5656
class TestClass
5757
{{
5858
}}
59+
";
60+
61+
await Verify.VerifyAnalyzerAsync(testCode);
62+
}
63+
64+
[Fact]
65+
public async Task TestNonDiagnosticPotentialCasesAsync()
66+
{
67+
// These cases could qualify for this diagnostic, but currently do not.
68+
var testCode = @"
69+
class TestClass
70+
{
71+
/// <summary>
72+
/// The keyword is <c>&#97;wait</c>.
73+
/// The keyword is <c> true</c>.
74+
/// The keyword is <c>true </c>.
75+
/// The keyword is <c> true </c>.
76+
/// The keyword is <c>true
77+
/// </c>.
78+
/// The keyword is <c>
79+
/// true</c>.
80+
/// The keyword is <c>
81+
/// true
82+
/// </c>.
83+
/// </summary>
84+
void Method<a>()
85+
{
86+
}
87+
}
88+
";
89+
90+
await Verify.VerifyAnalyzerAsync(testCode);
91+
}
92+
93+
[Fact]
94+
public async Task TestNonDiagnosticCasesAsync()
95+
{
96+
// These cases *shouldn't* qualify for this diagnostic.
97+
var testCode = @"
98+
class TestClass
99+
{
100+
/// <summary>
101+
/// The keyword is <c>not-keyword</c>.
102+
/// The keyword is <c>True</c>.
103+
/// The keyword is <c>true&gt;</c>.
104+
/// The keyword is <c>&gt;true</c>.
105+
/// The keyword is <c><em>true</em></c>.
106+
/// The keyword is <c><em>true</em>true</c>.
107+
/// </summary>
108+
void Method<a>()
109+
{
110+
}
111+
}
112+
";
113+
114+
await Verify.VerifyAnalyzerAsync(testCode);
115+
}
116+
117+
[Fact]
118+
public async Task TestNonCodeAsync()
119+
{
120+
var testCode = @"
121+
/// <summary>
122+
/// The keyword is <p:c>true</p:c>.
123+
/// </summary>
124+
class TestClass
125+
{
126+
}
59127
";
60128

61129
await Verify.VerifyAnalyzerAsync(testCode);

DocumentationAnalyzers/DocumentationAnalyzers.Test/StyleRules/DOC105UnitTests.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,35 @@ void Method(int a)
4242
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
4343
}
4444

45+
[Fact]
46+
public async Task TestParameterNameEncodedAsync()
47+
{
48+
var testCode = @"
49+
class TestClass
50+
{
51+
/// <summary>
52+
/// Consider a parameter [|<c>&#97;</c>|].
53+
/// </summary>
54+
void Method(int a)
55+
{
56+
}
57+
}
58+
";
59+
var fixedCode = @"
60+
class TestClass
61+
{
62+
/// <summary>
63+
/// Consider a parameter <paramref name=""&#97;""/>.
64+
/// </summary>
65+
void Method(int a)
66+
{
67+
}
68+
}
69+
";
70+
71+
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
72+
}
73+
4574
[Fact]
4675
public async Task TestParameterNameMatchesKeywordAsync()
4776
{
@@ -70,5 +99,75 @@ void Method(int @true)
7099

71100
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
72101
}
102+
103+
[Fact]
104+
public async Task TestNonDiagnosticPotentialCasesAsync()
105+
{
106+
// These cases could qualify for this diagnostic, but currently do not.
107+
var testCode = @"
108+
class TestClass
109+
{
110+
/// <summary>
111+
/// Consider a parameter <c> a</c>.
112+
/// Consider a parameter <c>a </c>.
113+
/// Consider a parameter <c> a </c>.
114+
/// Consider a parameter <c>a
115+
/// </c>.
116+
/// Consider a parameter <c>
117+
/// a</c>.
118+
/// Consider a parameter <c>
119+
/// a
120+
/// </c>.
121+
/// </summary>
122+
void Method(int a)
123+
{
124+
}
125+
}
126+
";
127+
128+
await Verify.VerifyAnalyzerAsync(testCode);
129+
}
130+
131+
[Fact]
132+
public async Task TestNonDiagnosticCasesAsync()
133+
{
134+
// These cases *shouldn't* qualify for this diagnostic.
135+
var testCode = @"
136+
class TestClass
137+
{
138+
/// <summary>
139+
/// Consider a parameter <c>b</c>.
140+
/// Consider a parameter <c>A</c>.
141+
/// Consider a parameter <c>a&gt;</c>.
142+
/// Consider a parameter <c>&gt;a</c>.
143+
/// Consider a parameter <c><em>a</em></c>.
144+
/// Consider a parameter <c><em>a</em>a</c>.
145+
/// </summary>
146+
void Method(int a)
147+
{
148+
}
149+
}
150+
";
151+
152+
await Verify.VerifyAnalyzerAsync(testCode);
153+
}
154+
155+
[Fact]
156+
public async Task TestNonCodeAsync()
157+
{
158+
var testCode = @"
159+
class TestClass
160+
{
161+
/// <summary>
162+
/// Consider a parameter <p:c>a</p:c>.
163+
/// </summary>
164+
void Method(int a)
165+
{
166+
}
167+
}
168+
";
169+
170+
await Verify.VerifyAnalyzerAsync(testCode);
171+
}
73172
}
74173
}

DocumentationAnalyzers/DocumentationAnalyzers.Test/StyleRules/DOC106UnitTests.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,35 @@ void Method<a>()
4242
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
4343
}
4444

45+
[Fact]
46+
public async Task TestTypeParameterNameEncodedAsync()
47+
{
48+
var testCode = @"
49+
class TestClass
50+
{
51+
/// <summary>
52+
/// Consider a type parameter [|<c>&#97;</c>|].
53+
/// </summary>
54+
void Method<a>()
55+
{
56+
}
57+
}
58+
";
59+
var fixedCode = @"
60+
class TestClass
61+
{
62+
/// <summary>
63+
/// Consider a type parameter <typeparamref name=""&#97;""/>.
64+
/// </summary>
65+
void Method<a>()
66+
{
67+
}
68+
}
69+
";
70+
71+
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
72+
}
73+
4574
[Fact]
4675
public async Task TestTypeParameterNameMatchesKeywordAsync()
4776
{
@@ -70,5 +99,75 @@ void Method<@true>()
7099

71100
await Verify.VerifyCodeFixAsync(testCode, fixedCode);
72101
}
102+
103+
[Fact]
104+
public async Task TestNonDiagnosticPotentialCasesAsync()
105+
{
106+
// These cases could qualify for this diagnostic, but currently do not.
107+
var testCode = @"
108+
class TestClass
109+
{
110+
/// <summary>
111+
/// Consider a type parameter <c> a</c>.
112+
/// Consider a type parameter <c>a </c>.
113+
/// Consider a type parameter <c> a </c>.
114+
/// Consider a type parameter <c>a
115+
/// </c>.
116+
/// Consider a type parameter <c>
117+
/// a</c>.
118+
/// Consider a type parameter <c>
119+
/// a
120+
/// </c>.
121+
/// </summary>
122+
void Method<a>()
123+
{
124+
}
125+
}
126+
";
127+
128+
await Verify.VerifyAnalyzerAsync(testCode);
129+
}
130+
131+
[Fact]
132+
public async Task TestNonDiagnosticCasesAsync()
133+
{
134+
// These cases *shouldn't* qualify for this diagnostic.
135+
var testCode = @"
136+
class TestClass
137+
{
138+
/// <summary>
139+
/// Consider a type parameter <c>b</c>.
140+
/// Consider a type parameter <c>A</c>.
141+
/// Consider a type parameter <c>a&gt;</c>.
142+
/// Consider a type parameter <c>&gt;a</c>.
143+
/// Consider a type parameter <c><em>a</em></c>.
144+
/// Consider a type parameter <c><em>a</em>a</c>.
145+
/// </summary>
146+
void Method<a>()
147+
{
148+
}
149+
}
150+
";
151+
152+
await Verify.VerifyAnalyzerAsync(testCode);
153+
}
154+
155+
[Fact]
156+
public async Task TestNonCodeAsync()
157+
{
158+
var testCode = @"
159+
class TestClass
160+
{
161+
/// <summary>
162+
/// Consider a type parameter <p:c>a</p:c>.
163+
/// </summary>
164+
void Method<a>()
165+
{
166+
}
167+
}
168+
";
169+
170+
await Verify.VerifyAnalyzerAsync(testCode);
171+
}
73172
}
74173
}

0 commit comments

Comments
 (0)