Skip to content

Commit 575d877

Browse files
committed
Add tests for rename to upper case with conflicts
1 parent c05d224 commit 575d877

5 files changed

Lines changed: 335 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1300UnitTests.cs

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ public async Task TestLowerCaseClassAsync()
106106
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
107107
}
108108

109+
[Fact]
110+
public async Task TestLowerCaseClassWithConflictAsync()
111+
{
112+
var testCode = @"public class test
113+
{
114+
}
115+
116+
public class Test { }";
117+
var fixedCode = @"public class Test1
118+
{
119+
}
120+
121+
public class Test { }";
122+
123+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 14);
124+
125+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
126+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
127+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
128+
}
129+
109130
[Fact]
110131
public async Task TestUpperCaseInterfaceAsync()
111132
{
@@ -159,6 +180,27 @@ public async Task TestLowerCaseStructAsync()
159180
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
160181
}
161182

183+
[Fact]
184+
public async Task TestLowerCaseStructWithConflictAsync()
185+
{
186+
var testCode = @"public struct test
187+
{
188+
}
189+
190+
public class Test { }";
191+
var fixedCode = @"public struct Test1
192+
{
193+
}
194+
195+
public class Test { }";
196+
197+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 15);
198+
199+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
200+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
201+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
202+
}
203+
162204
[Fact]
163205
public async Task TestUpperCaseEnumAsync()
164206
{
@@ -189,6 +231,27 @@ public async Task TestLowerCaseEnumAsync()
189231
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
190232
}
191233

234+
[Fact]
235+
public async Task TestLowerCaseEnumWithConflictAsync()
236+
{
237+
var testCode = @"public enum test
238+
{
239+
}
240+
241+
public class Test { }";
242+
var fixedCode = @"public enum Test1
243+
{
244+
}
245+
246+
public class Test { }";
247+
248+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 13);
249+
250+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
251+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
252+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
253+
}
254+
192255
[Fact]
193256
public async Task TestUpperCaseDelegateAsync()
194257
{
@@ -219,6 +282,29 @@ public async Task TestLowerCaseDelegateAsync()
219282
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
220283
}
221284

285+
[Fact]
286+
public async Task TestLowerCaseDelegateWithConflictAsync()
287+
{
288+
var testCode = @"public class Test1
289+
{
290+
public delegate void test();
291+
292+
public int Test => 0;
293+
}";
294+
var fixedCode = @"public class Test1
295+
{
296+
public delegate void Test2();
297+
298+
public int Test => 0;
299+
}";
300+
301+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(3, 22);
302+
303+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
304+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
305+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
306+
}
307+
222308
[Fact]
223309
public async Task TestUpperCaseEventAsync()
224310
{
@@ -285,6 +371,53 @@ public event Test TestEvent
285371
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
286372
}
287373

374+
[Fact]
375+
public async Task TestLowerCaseEventWithConflictAsync()
376+
{
377+
var testCode = @"public class TestClass
378+
{
379+
public delegate void Test();
380+
Test _testEvent;
381+
public event Test testEvent
382+
{
383+
add
384+
{
385+
_testEvent += value;
386+
}
387+
remove
388+
{
389+
_testEvent -= value;
390+
}
391+
}
392+
393+
public int TestEvent => 0;
394+
}";
395+
var fixedCode = @"public class TestClass
396+
{
397+
public delegate void Test();
398+
Test _testEvent;
399+
public event Test TestEvent1
400+
{
401+
add
402+
{
403+
_testEvent += value;
404+
}
405+
remove
406+
{
407+
_testEvent -= value;
408+
}
409+
}
410+
411+
public int TestEvent => 0;
412+
}";
413+
414+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("testEvent").WithLocation(5, 23);
415+
416+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
417+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
418+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
419+
}
420+
288421
[Fact]
289422
public async Task TestUpperCaseEventFieldAsync()
290423
{
@@ -318,6 +451,29 @@ public async Task TestLowerCaseEventFieldAsync()
318451
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
319452
}
320453

454+
[Fact]
455+
public async Task TestLowerCaseEventFieldWithConflictAsync()
456+
{
457+
var testCode = @"public class TestClass
458+
{
459+
public delegate void Test();
460+
public event Test testEvent;
461+
public event Test TestEvent;
462+
}";
463+
var fixedCode = @"public class TestClass
464+
{
465+
public delegate void Test();
466+
public event Test TestEvent1;
467+
public event Test TestEvent;
468+
}";
469+
470+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("testEvent").WithLocation(4, 23);
471+
472+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
473+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
474+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
475+
}
476+
321477
[Fact]
322478
public async Task TestUpperCaseMethodAsync()
323479
{
@@ -354,6 +510,34 @@ public void Test()
354510
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
355511
}
356512

513+
[Fact]
514+
public async Task TestLowerCaseMethodWithConflictAsync()
515+
{
516+
// Conflict resolution does not attempt to examine overloaded methods.
517+
var testCode = @"public class TestClass
518+
{
519+
public void test()
520+
{
521+
}
522+
523+
public int Test(int value) => value;
524+
}";
525+
var fixedCode = @"public class TestClass
526+
{
527+
public void Test1()
528+
{
529+
}
530+
531+
public int Test(int value) => value;
532+
}";
533+
534+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(3, 13);
535+
536+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
537+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
538+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
539+
}
540+
357541
[Fact]
358542
public async Task TestUpperCasePropertyAsync()
359543
{
@@ -384,6 +568,27 @@ public async Task TestLowerCasePropertyAsync()
384568
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
385569
}
386570

571+
[Fact]
572+
public async Task TestLowerCasePropertyWithConflictAsync()
573+
{
574+
var testCode = @"public class TestClass
575+
{
576+
public string test { get; set; }
577+
public string Test => string.Empty;
578+
}";
579+
var fixedCode = @"public class TestClass
580+
{
581+
public string Test1 { get; set; }
582+
public string Test => string.Empty;
583+
}";
584+
585+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(3, 15);
586+
587+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
588+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
589+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
590+
}
591+
387592
[Fact]
388593
public async Task TestUpperCasePublicFieldAsync()
389594
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1303UnitTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ public async Task TestConstFieldStartingWithLowerCaseAsync()
3333
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
3434
}
3535

36+
[Fact]
37+
public async Task TestConstFieldStartingWithLowerCaseWithConflictAsync()
38+
{
39+
var testCode = @"public class Foo
40+
{
41+
public const string bar = ""baz"";
42+
public const int Bar = 0;
43+
}";
44+
var fixedCode = @"public class Foo
45+
{
46+
public const string BarValue = ""baz"";
47+
public const int Bar = 0;
48+
}";
49+
50+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 25);
51+
52+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
53+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
54+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
55+
}
56+
3657
[Fact]
3758
public async Task TestConstFieldStartingWithLowerCaseNativeMethodsExampleOneAsync()
3859
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1304UnitTests.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,50 @@ public async Task TestInternalReadonlyFieldStartingWithLowerCaseAsync()
7979
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
8080
}
8181

82+
[Fact]
83+
public async Task TestInternalReadonlyFieldStartingWithLowerCaseWithConflictAsync()
84+
{
85+
var testCode = @"public class Foo
86+
{
87+
internal readonly string bar = ""baz"";
88+
public string Bar => this.bar;
89+
}";
90+
91+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 30);
92+
93+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
94+
95+
var fixedCode = @"public class Foo
96+
{
97+
internal readonly string BarValue = ""baz"";
98+
public string Bar => this.BarValue;
99+
}";
100+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
101+
}
102+
103+
[Fact]
104+
public async Task TestInternalReadonlyFieldStartingWithLowerCaseWithTwoConflictsAsync()
105+
{
106+
var testCode = @"public class Foo
107+
{
108+
internal readonly string bar = ""baz"";
109+
public string Bar => this.bar;
110+
public string BarValue => this.bar;
111+
}";
112+
113+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 30);
114+
115+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
116+
117+
var fixedCode = @"public class Foo
118+
{
119+
internal readonly string Bar1 = ""baz"";
120+
public string Bar => this.Bar1;
121+
public string BarValue => this.Bar1;
122+
}";
123+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
124+
}
125+
82126
[Fact]
83127
public async Task TestInternalReadonlyFieldStartingWithUpperCaseAsync()
84128
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1307UnitTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,48 @@ public async Task TestThatDiagnosticIsReported_MultipleFieldsAsync(string modifi
106106
await this.VerifyCSharpFixAsync(string.Format(testCode, modifiers), string.Format(fixedCode, modifiers)).ConfigureAwait(false);
107107
}
108108

109+
[Theory]
110+
[InlineData("public")]
111+
[InlineData("internal")]
112+
[InlineData("protected internal")]
113+
public async Task TestThatDiagnosticIsReported_MultipleFieldsWithConflictAsync(string modifiers)
114+
{
115+
var testCode = @"public class Foo
116+
{{
117+
{0}
118+
string bar, Bar, barValue;
119+
{0}
120+
string carValue, Car, car;
121+
}}";
122+
var fixedCode = @"public class Foo
123+
{{
124+
{0}
125+
string BarValue, Bar, BarValueValue;
126+
{0}
127+
string CarValue, Car, Car1;
128+
}}";
129+
var batchFixedCode = @"public class Foo
130+
{{
131+
{0}
132+
string BarValue, Bar, BarValueValue;
133+
{0}
134+
string CarValueValue, Car, CarValue;
135+
}}";
136+
137+
DiagnosticResult[] expected =
138+
{
139+
this.CSharpDiagnostic().WithArguments("bar").WithLocation(4, 8),
140+
this.CSharpDiagnostic().WithArguments("barValue").WithLocation(4, 18),
141+
this.CSharpDiagnostic().WithArguments("carValue").WithLocation(6, 8),
142+
this.CSharpDiagnostic().WithArguments("car").WithLocation(6, 23),
143+
};
144+
145+
await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, modifiers), expected, CancellationToken.None).ConfigureAwait(false);
146+
await this.VerifyCSharpDiagnosticAsync(string.Format(fixedCode, modifiers), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
147+
await this.VerifyCSharpDiagnosticAsync(string.Format(batchFixedCode, modifiers), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
148+
await this.VerifyCSharpFixAsync(string.Format(testCode, modifiers), string.Format(fixedCode, modifiers), string.Format(batchFixedCode, modifiers), cancellationToken: CancellationToken.None).ConfigureAwait(false);
149+
}
150+
109151
[Fact]
110152
public async Task TestFieldStartingWithAnUnderscoreAsync()
111153
{

0 commit comments

Comments
 (0)