Skip to content

Commit 07c527c

Browse files
committed
Add regression tests for #1930
1 parent 9b14293 commit 07c527c

1 file changed

Lines changed: 166 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1305UnitTests.cs

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,172 @@ public async Task TestExcludedPrefixesAreNotReportedAsync()
192192
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
193193
}
194194

195+
[Fact]
196+
public async Task TestVariableInCatchDeclarationAsync()
197+
{
198+
var testCode = @"
199+
using System;
200+
public class TypeName
201+
{
202+
public void MethodName()
203+
{
204+
try
205+
{
206+
}
207+
catch (Exception exA)
208+
{
209+
}
210+
}
211+
}";
212+
213+
DiagnosticResult[] expected =
214+
{
215+
this.CSharpDiagnostic().WithArguments("variable", "exA").WithLocation(10, 26),
216+
};
217+
218+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
219+
}
220+
221+
[Fact]
222+
public async Task TestVariableInForEachStatementAsync()
223+
{
224+
var testCode = @"public class TypeName
225+
{
226+
public void MethodName()
227+
{
228+
foreach (var abX in new int[0])
229+
{
230+
}
231+
}
232+
}";
233+
234+
DiagnosticResult[] expected =
235+
{
236+
this.CSharpDiagnostic().WithArguments("variable", "abX").WithLocation(5, 22),
237+
};
238+
239+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
240+
}
241+
242+
[Fact]
243+
public async Task TestVariableInFromClauseAsync()
244+
{
245+
var testCode = @"
246+
using System.Linq;
247+
public class TypeName
248+
{
249+
public void MethodName()
250+
{
251+
var result =
252+
from abX in new int[0]
253+
select abX;
254+
}
255+
}";
256+
257+
DiagnosticResult[] expected =
258+
{
259+
this.CSharpDiagnostic().WithArguments("variable", "abX").WithLocation(8, 18),
260+
};
261+
262+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
263+
}
264+
265+
[Fact]
266+
public async Task TestVariableInQueryContinuationAsync()
267+
{
268+
var testCode = @"
269+
using System.Linq;
270+
public class TypeName
271+
{
272+
public void MethodName()
273+
{
274+
var result =
275+
from x in new int[0]
276+
select x into abY
277+
select abY;
278+
}
279+
}";
280+
281+
DiagnosticResult[] expected =
282+
{
283+
this.CSharpDiagnostic().WithArguments("variable", "abY").WithLocation(9, 27),
284+
};
285+
286+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
287+
}
288+
289+
[Fact]
290+
public async Task TestVariableInLetClauseAsync()
291+
{
292+
var testCode = @"
293+
using System.Linq;
294+
public class TypeName
295+
{
296+
public void MethodName()
297+
{
298+
var result =
299+
from x in new int[0]
300+
let abY = x
301+
select abY;
302+
}
303+
}";
304+
305+
DiagnosticResult[] expected =
306+
{
307+
this.CSharpDiagnostic().WithArguments("variable", "abY").WithLocation(9, 17),
308+
};
309+
310+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
311+
}
312+
313+
[Fact]
314+
public async Task TestVariableInJoinClauseAsync()
315+
{
316+
var testCode = @"
317+
using System.Linq;
318+
public class TypeName
319+
{
320+
public void MethodName()
321+
{
322+
var result =
323+
from x in new int[0]
324+
join abY in new int[0] on x equals abY
325+
select x;
326+
}
327+
}";
328+
329+
DiagnosticResult[] expected =
330+
{
331+
this.CSharpDiagnostic().WithArguments("variable", "abY").WithLocation(9, 18),
332+
};
333+
334+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
335+
}
336+
337+
[Fact]
338+
public async Task TestVariableInJoinIntoClauseAsync()
339+
{
340+
var testCode = @"
341+
using System.Linq;
342+
public class TypeName
343+
{
344+
public void MethodName()
345+
{
346+
var result =
347+
from x in new int[0]
348+
join y in new int[0] on x equals y into abZ
349+
select abZ;
350+
}
351+
}";
352+
353+
DiagnosticResult[] expected =
354+
{
355+
this.CSharpDiagnostic().WithArguments("variable", "abZ").WithLocation(9, 53),
356+
};
357+
358+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
359+
}
360+
195361
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
196362
{
197363
yield return new SA1305FieldNamesMustNotUseHungarianNotation();

0 commit comments

Comments
 (0)