Skip to content

Commit d4de971

Browse files
committed
SA1132: improve code coverage
1 parent cba5de1 commit d4de971

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1132UnitTests.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace StyleCop.Analyzers.Test.ReadabilityRules
77
using System.Threading;
88
using System.Threading.Tasks;
99
using Analyzers.ReadabilityRules;
10+
using Microsoft.CodeAnalysis;
1011
using Microsoft.CodeAnalysis.CodeFixes;
1112
using Microsoft.CodeAnalysis.Diagnostics;
1213
using TestHelper;
@@ -34,14 +35,16 @@ public async Task TestInvalidDeclarationAsync()
3435
const string testCode = @"
3536
class Foo
3637
{
37-
private int a, b;
38+
private int a, b,/*foo*/c,d;
3839
public event System.Action aa, bb;
3940
}";
4041
const string fixedCode = @"
4142
class Foo
4243
{
4344
private int a;
44-
private int b;
45+
private int b;/*foo*/
46+
private int c;
47+
private int d;
4548
public event System.Action aa;
4649
public event System.Action bb;
4750
}";
@@ -109,6 +112,37 @@ class Foo
109112
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
110113
}
111114

115+
[Fact]
116+
public async Task TestDeclarationWithMissingTokensAndNodesAsync()
117+
{
118+
const string testCode = @"
119+
class Foo
120+
{
121+
private int a,, b;
122+
private int c, d
123+
}";
124+
125+
DiagnosticResult[] expected =
126+
{
127+
new DiagnosticResult
128+
{
129+
Id = "CS1001",
130+
Severity = DiagnosticSeverity.Error,
131+
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 4, 19) },
132+
Message = "Identifier expected"
133+
},
134+
new DiagnosticResult
135+
{
136+
Id = "CS1002",
137+
Severity = DiagnosticSeverity.Error,
138+
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 5, 21) },
139+
Message = "; expected"
140+
}
141+
};
142+
143+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
144+
}
145+
112146
[Fact]
113147
public async Task TestInvalidEventFieldDeclarationWithAttributesAsync()
114148
{

0 commit comments

Comments
 (0)