Skip to content

Commit 6b53df4

Browse files
committed
Add line endings tests for naming rules
1 parent e8f8552 commit 6b53df4

File tree

14 files changed

+149
-93
lines changed

14 files changed

+149
-93
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1302UnitTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
9+
using StyleCop.Analyzers.Test.Helpers;
1110
using Xunit;
1211
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1312
StyleCop.Analyzers.NamingRules.SA1302InterfaceNamesMustBeginWithI,
1413
StyleCop.Analyzers.NamingRules.SA1302CodeFixProvider>;
1514

1615
public class SA1302UnitTests
1716
{
18-
[Fact]
19-
public async Task TestInterfaceDeclarationDoesNotStartWithIAsync()
17+
[Theory]
18+
[InlineData("\n")]
19+
[InlineData("\r\n")]
20+
public async Task TestInterfaceDeclarationDoesNotStartWithIAsync(string lineEnding)
2021
{
2122
var testCode = @"
22-
public interface Foo
23+
public interface {|#0:Foo|}
2324
{
24-
}";
25+
}".ReplaceLineEndings(lineEnding);
2526

26-
DiagnosticResult expected = Diagnostic().WithLocation(2, 18);
27+
DiagnosticResult expected = Diagnostic().WithLocation(0);
2728

2829
var fixedCode = @"
2930
public interface IFoo
3031
{
31-
}";
32+
}".ReplaceLineEndings(lineEnding);
3233

3334
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
3435
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
9+
using StyleCop.Analyzers.Test.Helpers;
1110
using Xunit;
1211
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1312
StyleCop.Analyzers.NamingRules.SA1303ConstFieldNamesMustBeginWithUpperCaseLetter,
1413
StyleCop.Analyzers.NamingRules.RenameToUpperCaseCodeFixProvider>;
1514

1615
public class SA1303UnitTests
1716
{
18-
[Fact]
19-
public async Task TestConstFieldStartingWithLowerCaseAsync()
17+
[Theory]
18+
[InlineData("\n")]
19+
[InlineData("\r\n")]
20+
public async Task TestConstFieldStartingWithLowerCaseAsync(string lineEnding)
2021
{
2122
var testCode = @"public class Foo
2223
{
23-
public const string bar = ""baz"";
24-
}";
24+
public const string {|#0:bar|} = ""baz"";
25+
}".ReplaceLineEndings(lineEnding);
2526
var fixedCode = @"public class Foo
2627
{
2728
public const string Bar = ""baz"";
28-
}";
29+
}".ReplaceLineEndings(lineEnding);
2930

30-
DiagnosticResult expected = Diagnostic().WithLocation(3, 25);
31+
DiagnosticResult expected = Diagnostic().WithLocation(0);
3132
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
3233
}
3334

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
9+
using StyleCop.Analyzers.Test.Helpers;
1110
using Xunit;
1211
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1312
StyleCop.Analyzers.NamingRules.SA1304NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter,
@@ -72,20 +71,22 @@ public async Task TestFieldInNativeMethodsClassAsync()
7271
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
7372
}
7473

75-
[Fact]
76-
public async Task TestInternalReadonlyFieldStartingWithLowerCaseAsync()
74+
[Theory]
75+
[InlineData("\n")]
76+
[InlineData("\r\n")]
77+
public async Task TestInternalReadonlyFieldStartingWithLowerCaseAsync(string lineEnding)
7778
{
7879
var testCode = @"public class Foo
7980
{
80-
internal readonly string bar = ""baz"";
81-
}";
81+
internal readonly string {|#0:bar|} = ""baz"";
82+
}".ReplaceLineEndings(lineEnding);
8283

83-
DiagnosticResult expected = Diagnostic().WithLocation(3, 30);
84+
DiagnosticResult expected = Diagnostic().WithLocation(0);
8485

8586
var fixedCode = @"public class Foo
8687
{
8788
internal readonly string Bar = ""baz"";
88-
}";
89+
}".ReplaceLineEndings(lineEnding);
8990
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
9091
}
9192

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1306UnitTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
119
using StyleCop.Analyzers.NamingRules;
10+
using StyleCop.Analyzers.Test.Helpers;
1211
using Xunit;
1312
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1413
StyleCop.Analyzers.NamingRules.SA1306FieldNamesMustBeginWithLowerCaseLetter,
@@ -259,22 +258,24 @@ public async Task TestFieldWithTrailingUnderscoreAsync()
259258
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
260259
}
261260

262-
[Fact]
263-
public async Task TestFieldWithCodefixRenameConflictAsync()
261+
[Theory]
262+
[InlineData("\n")]
263+
[InlineData("\r\n")]
264+
public async Task TestFieldWithCodefixRenameConflictAsync(string lineEnding)
264265
{
265266
var testCode = @"public class Foo
266267
{
267268
private string _test = ""test1"";
268-
private string _Test = ""test2"";
269-
}";
269+
private string {|#0:_Test|} = ""test2"";
270+
}".ReplaceLineEndings(lineEnding);
270271

271272
var fixedTestCode = @"public class Foo
272273
{
273274
private string _test = ""test1"";
274275
private string _test1 = ""test2"";
275-
}";
276+
}".ReplaceLineEndings(lineEnding);
276277

277-
var expected = Diagnostic().WithArguments("_Test").WithLocation(4, 20);
278+
var expected = Diagnostic().WithArguments("_Test").WithLocation(0);
278279
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
279280
}
280281

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
9+
using StyleCop.Analyzers.Test.Helpers;
1110
using Xunit;
1211
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1312
StyleCop.Analyzers.NamingRules.SA1307AccessibleFieldsMustBeginWithUpperCaseLetter,
@@ -151,20 +150,22 @@ public async Task TestThatDiagnosticIsReported_MultipleFieldsWithConflictAsync(s
151150
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
152151
}
153152

154-
[Fact]
155-
public async Task TestFieldStartingWithVerbatimIdentifierAsync()
153+
[Theory]
154+
[InlineData("\n")]
155+
[InlineData("\r\n")]
156+
public async Task TestFieldStartingWithVerbatimIdentifierAsync(string lineEnding)
156157
{
157158
var testCode = @"public class Foo
158159
{
159-
public string @bar = ""baz"";
160-
}";
160+
public string {|#0:@bar|} = ""baz"";
161+
}".ReplaceLineEndings(lineEnding);
161162

162163
var fixedCode = @"public class Foo
163164
{
164165
public string Bar = ""baz"";
165-
}";
166+
}".ReplaceLineEndings(lineEnding);
166167

167-
var expected = Diagnostic().WithArguments("bar").WithLocation(3, 19);
168+
var expected = Diagnostic().WithArguments("bar").WithLocation(0);
168169
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
169170
}
170171

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1308UnitTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.NamingRules
75
{
86
using System.Collections.Generic;
97
using System.Threading;
108
using System.Threading.Tasks;
119
using Microsoft.CodeAnalysis.Testing;
10+
using StyleCop.Analyzers.Test.Helpers;
1211
using Xunit;
1312
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1413
StyleCop.Analyzers.NamingRules.SA1308VariableNamesMustNotBePrefixed,
@@ -50,14 +49,16 @@ public async Task TestFieldStartingWithPrefixesToTriggerDiagnosticAsync()
5049
}
5150
}
5251

53-
[Fact]
54-
public async Task TestMUnderscoreOnlyAsync()
52+
[Theory]
53+
[InlineData("\n")]
54+
[InlineData("\r\n")]
55+
public async Task TestMUnderscoreOnlyAsync(string lineEnding)
5556
{
5657
var originalCode = @"public class Foo
5758
{
58-
private string m_ = ""baz"";
59-
}";
60-
DiagnosticResult expected = Diagnostic().WithArguments("m_", "m_").WithLocation(3, 16);
59+
private string {|#0:m_|} = ""baz"";
60+
}".ReplaceLineEndings(lineEnding);
61+
DiagnosticResult expected = Diagnostic().WithArguments("m_", "m_").WithLocation(0);
6162

6263
// When the variable name is simply the disallowed prefix, we will not offer a code fix, as we cannot infer the correct variable name.
6364
await VerifyCSharpFixAsync(originalCode, expected, originalCode, CancellationToken.None).ConfigureAwait(false);

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
9+
using StyleCop.Analyzers.Test.Helpers;
1110
using Xunit;
1211
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1312
StyleCop.Analyzers.NamingRules.SA1309FieldNamesMustNotBeginWithUnderscore,
1413
StyleCop.Analyzers.NamingRules.SA1309CodeFixProvider>;
1514

1615
public class SA1309UnitTests
1716
{
18-
[Fact]
19-
public async Task TestFieldStartingWithAnUnderscoreAsync()
17+
[Theory]
18+
[InlineData("\n")]
19+
[InlineData("\r\n")]
20+
public async Task TestFieldStartingWithAnUnderscoreAsync(string lineEnding)
2021
{
2122
var testCode = @"public class Foo
2223
{
23-
public string _bar = ""baz"";
24-
}";
24+
public string {|#0:_bar|} = ""baz"";
25+
}".ReplaceLineEndings(lineEnding);
2526

26-
DiagnosticResult expected = Diagnostic().WithArguments("_bar").WithLocation(3, 19);
27+
DiagnosticResult expected = Diagnostic().WithArguments("_bar").WithLocation(0);
2728

2829
var fixedCode = @"public class Foo
2930
{
3031
public string bar = ""baz"";
31-
}";
32+
}".ReplaceLineEndings(lineEnding);
3233

3334
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
3435
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1310UnitTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
9+
using StyleCop.Analyzers.Test.Helpers;
1110
using Xunit;
1211
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1312
StyleCop.Analyzers.NamingRules.SA1310FieldNamesMustNotContainUnderscore,
1413
StyleCop.Analyzers.NamingRules.SA1310CodeFixProvider>;
1514

1615
public class SA1310UnitTests
1716
{
18-
[Fact]
19-
public async Task TestFieldWithUnderscoreAsync()
17+
[Theory]
18+
[InlineData("\n")]
19+
[InlineData("\r\n")]
20+
public async Task TestFieldWithUnderscoreAsync(string lineEnding)
2021
{
2122
var testCode = @"public class ClassName
2223
{
23-
public string name_bar = ""baz"";
24-
}";
24+
public string {|#0:name_bar|} = ""baz"";
25+
}".ReplaceLineEndings(lineEnding);
2526

26-
DiagnosticResult expected = Diagnostic().WithArguments("name_bar").WithLocation(3, 19);
27+
DiagnosticResult expected = Diagnostic().WithArguments("name_bar").WithLocation(0);
2728

2829
var fixedCode = @"public class ClassName
2930
{
3031
public string nameBar = ""baz"";
31-
}";
32+
}".ReplaceLineEndings(lineEnding);
3233

3334
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
3435
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1311UnitTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
9+
using StyleCop.Analyzers.Test.Helpers;
1110
using Xunit;
1211
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1312
StyleCop.Analyzers.NamingRules.SA1311StaticReadonlyFieldsMustBeginWithUpperCaseLetter,
1413
StyleCop.Analyzers.NamingRules.RenameToUpperCaseCodeFixProvider>;
1514

1615
public class SA1311UnitTests
1716
{
18-
[Fact]
19-
public async Task TestStaticReadonlyFieldStartingWithLowerCaseAsync()
17+
[Theory]
18+
[InlineData("\n")]
19+
[InlineData("\r\n")]
20+
public async Task TestStaticReadonlyFieldStartingWithLowerCaseAsync(string lineEnding)
2021
{
2122
var testCode = @"public class Foo
2223
{
23-
public static readonly string bar = ""baz"";
24-
}";
24+
public static readonly string {|#0:bar|} = ""baz"";
25+
}".ReplaceLineEndings(lineEnding);
2526

26-
DiagnosticResult expected = Diagnostic().WithLocation(3, 35);
27+
DiagnosticResult expected = Diagnostic().WithLocation(0);
2728

2829
var fixedCode = @"public class Foo
2930
{
3031
public static readonly string Bar = ""baz"";
31-
}";
32+
}".ReplaceLineEndings(lineEnding);
3233

3334
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
3435
}

0 commit comments

Comments
 (0)