Skip to content

Commit 3855c91

Browse files
Added test case verifying SA1309 codefix for fields with an identifier starting with an underscore and followed by a keyword.
1 parent a350844 commit 3855c91

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1309UnitTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ public async Task VerifyThatAFieldStartingWithAnUnderscoreAndADigitIsNotAffected
149149
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
150150
}
151151

152+
[Fact]
153+
public async Task VerifyThatAFieldStartingWithUnderscoreAndFollowedByKeywordTriggersDiagnosticAndIsCorrectedByCodefixAsync()
154+
{
155+
var testCode = @"public class Foo
156+
{
157+
private string _int = ""baz"";
158+
}";
159+
160+
var fixedCode = @"public class Foo
161+
{
162+
private string @int = ""baz"";
163+
}";
164+
165+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("_int").WithLocation(3, 20);
166+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
167+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
168+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
169+
}
170+
152171
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
153172
{
154173
yield return new SA1309FieldNamesMustNotBeginWithUnderscore();

0 commit comments

Comments
 (0)