@@ -135,12 +135,27 @@ public async Task TestThatDiagnosticIsReported_SingleFieldAsync(string modifiers
135135string car;
136136{0}
137137string Dar;
138+ {0}
139+ string _ear;
140+ {0}
141+ string _Far;
142+ {0}
143+ string __gar;
144+ {0}
145+ string __Har;
146+ {0}
147+ string ___iar;
148+ {0}
149+ string ___Jar;
138150}}" ;
139151
140152 DiagnosticResult [ ] expected =
141153 {
142154 this . CSharpDiagnostic ( ) . WithArguments ( "Bar" ) . WithLocation ( 4 , 8 ) ,
143- this . CSharpDiagnostic ( ) . WithArguments ( "Dar" ) . WithLocation ( 8 , 8 )
155+ this . CSharpDiagnostic ( ) . WithArguments ( "Dar" ) . WithLocation ( 8 , 8 ) ,
156+ this . CSharpDiagnostic ( ) . WithArguments ( "_Far" ) . WithLocation ( 12 , 8 ) ,
157+ this . CSharpDiagnostic ( ) . WithArguments ( "__Har" ) . WithLocation ( 16 , 8 ) ,
158+ this . CSharpDiagnostic ( ) . WithArguments ( "___Jar" ) . WithLocation ( 20 , 8 ) ,
144159 } ;
145160
146161 await this . VerifyCSharpDiagnosticAsync ( string . Format ( testCode , modifiers ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
@@ -153,6 +168,18 @@ public async Task TestThatDiagnosticIsReported_SingleFieldAsync(string modifiers
153168string car;
154169{0}
155170string dar;
171+ {0}
172+ string _ear;
173+ {0}
174+ string _far;
175+ {0}
176+ string __gar;
177+ {0}
178+ string __har;
179+ {0}
180+ string ___iar;
181+ {0}
182+ string ___jar;
156183}}" ;
157184
158185 await this . VerifyCSharpDiagnosticAsync ( string . Format ( fixedCode , modifiers ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
@@ -193,28 +220,62 @@ public async Task TestThatDiagnosticIsReported_MultipleFieldsAsync(string modifi
193220 }
194221
195222 [ Fact ]
196- public async Task TestFieldStartingWithAnUnderscoreAsync ( )
223+ public async Task TestFieldStartingWithLetterAsync ( )
197224 {
198- // Makes sure SA1306 is not reported for fields starting with an underscore
199225 var testCode = @"public class Foo
200226{
201- public string _bar = ""baz"";
227+ public string bar = ""baz"";
202228}" ;
203229
204230 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
205231 }
206232
207233 [ Fact ]
208- public async Task TestFieldStartingWithLetterAsync ( )
234+ public async Task TestFieldWithAllUnderscoresAsync ( )
209235 {
210236 var testCode = @"public class Foo
211237{
212- public string bar = ""baz"";
238+ private string _ = ""bar"";
239+ private string __ = ""baz"";
240+ private string ___ = ""qux"";
213241}" ;
214242
215243 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
216244 }
217245
246+ [ Fact ]
247+ public async Task TestFieldWithTrailingUnderscoreAsync ( )
248+ {
249+ var testCode = @"public class Foo
250+ {
251+ private string someVar_ = ""bar"";
252+ }" ;
253+
254+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
255+ }
256+
257+ [ Fact ]
258+ public async Task TestFieldWithCodefixRenameConflictAsync ( )
259+ {
260+ var testCode = @"public class Foo
261+ {
262+ private string _test = ""test1"";
263+ private string _Test = ""test2"";
264+ }" ;
265+
266+ var fixedTestCode = @"public class Foo
267+ {
268+ private string _test = ""test1"";
269+ private string _test1 = ""test2"";
270+ }" ;
271+
272+ var expected = this . CSharpDiagnostic ( ) . WithArguments ( "_Test" ) . WithLocation ( 4 , 20 ) ;
273+
274+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
275+ await this . VerifyCSharpDiagnosticAsync ( fixedTestCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
276+ await this . VerifyCSharpFixAsync ( testCode , fixedTestCode ) . ConfigureAwait ( false ) ;
277+ }
278+
218279 [ Fact ]
219280 public async Task TestFieldPlacedInsideNativeMethodsClassAsync ( )
220281 {
0 commit comments