Skip to content

Commit 3dc62d4

Browse files
committed
Avoid using replacement strings where grammar may vary by language
1 parent 31df8ce commit 3dc62d4

21 files changed

+707
-505
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1009CSharp7UnitTests.cs

Lines changed: 228 additions & 228 deletions
Large diffs are not rendered by default.

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1010CSharp7UnitTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
99
using Microsoft.CodeAnalysis.Testing;
1010
using StyleCop.Analyzers.Test.SpacingRules;
1111
using Xunit;
12+
using static StyleCop.Analyzers.SpacingRules.SA1010OpeningSquareBracketsMustBeSpacedCorrectly;
1213
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1314
StyleCop.Analyzers.SpacingRules.SA1010OpeningSquareBracketsMustBeSpacedCorrectly,
1415
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -52,9 +53,9 @@ public unsafe void TestMethod()
5253

5354
DiagnosticResult[] expected =
5455
{
55-
Diagnostic().WithArguments("not be preceded").WithLocation(7, 41),
56-
Diagnostic().WithArguments("not be followed").WithLocation(7, 41),
57-
Diagnostic().WithArguments("not be preceded").WithLocation(8, 41),
56+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 41),
57+
Diagnostic(DescriptorNotFollowed).WithLocation(7, 41),
58+
Diagnostic(DescriptorNotPreceded).WithLocation(8, 41),
5859
};
5960

6061
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -97,7 +98,7 @@ public unsafe void TestMethod()
9798

9899
DiagnosticResult[] expected =
99100
{
100-
Diagnostic().WithArguments("not be followed").WithLocation(7, 37),
101+
Diagnostic(DescriptorNotFollowed).WithLocation(7, 37),
101102
};
102103

103104
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1015CSharp7UnitTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.Testing;
99
using StyleCop.Analyzers.Test.SpacingRules;
10-
using TestHelper;
1110
using Xunit;
11+
using static StyleCop.Analyzers.SpacingRules.SA1015ClosingGenericBracketsMustBeSpacedCorrectly;
1212
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1313
StyleCop.Analyzers.SpacingRules.SA1015ClosingGenericBracketsMustBeSpacedCorrectly,
1414
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -45,9 +45,9 @@ public void TestMethod()
4545

4646
DiagnosticResult[] expected =
4747
{
48-
Diagnostic().WithLocation(7, 19).WithArguments(" not", "preceded"),
49-
Diagnostic().WithLocation(7, 19).WithArguments(" not", "followed"),
50-
Diagnostic().WithLocation(7, 32).WithArguments(" not", "preceded"),
48+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 19),
49+
Diagnostic(DescriptorNotFollowed).WithLocation(7, 19),
50+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 32),
5151
};
5252

5353
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1024CSharp7UnitTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.Testing;
99
using StyleCop.Analyzers.Test.SpacingRules;
10-
using TestHelper;
1110
using Xunit;
11+
using static StyleCop.Analyzers.SpacingRules.SA1024ColonsMustBeSpacedCorrectly;
1212
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1313
StyleCop.Analyzers.SpacingRules.SA1024ColonsMustBeSpacedCorrectly,
1414
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -43,10 +43,10 @@ public void TestMethod()
4343

4444
DiagnosticResult[] expected =
4545
{
46-
Diagnostic().WithLocation(7, 25).WithArguments(" not", "preceded", string.Empty),
47-
Diagnostic().WithLocation(7, 25).WithArguments(string.Empty, "followed", string.Empty),
48-
Diagnostic().WithLocation(7, 31).WithArguments(" not", "preceded", string.Empty),
49-
Diagnostic().WithLocation(7, 31).WithArguments(string.Empty, "followed", string.Empty),
46+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 25),
47+
Diagnostic(DescriptorFollowed).WithLocation(7, 25),
48+
Diagnostic(DescriptorNotPreceded).WithLocation(7, 31),
49+
Diagnostic(DescriptorFollowed).WithLocation(7, 31),
5050
};
5151

5252
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -90,8 +90,8 @@ public void TestMethod()
9090

9191
DiagnosticResult[] expected =
9292
{
93-
Diagnostic().WithLocation(9, 35).WithArguments(" not", "preceded", string.Empty),
94-
Diagnostic().WithLocation(11, 22).WithArguments(" not", "preceded", string.Empty),
93+
Diagnostic(DescriptorNotPreceded).WithLocation(9, 35),
94+
Diagnostic(DescriptorNotPreceded).WithLocation(11, 22),
9595
};
9696

9797
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1009CSharp8UnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis.CSharp;
99
using Microsoft.CodeAnalysis.Testing;
10-
using StyleCop.Analyzers.SpacingRules;
1110
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
1211
using StyleCop.Analyzers.Test.Verifiers;
1312
using Xunit;
13+
using static StyleCop.Analyzers.SpacingRules.SA1009ClosingParenthesisMustBeSpacedCorrectly;
1414
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1515
StyleCop.Analyzers.SpacingRules.SA1009ClosingParenthesisMustBeSpacedCorrectly,
1616
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -142,7 +142,7 @@ public string TestMethod()
142142
}
143143
}
144144
";
145-
DiagnosticResult expected = Diagnostic().WithSpan(28, 37, 28, 38).WithArguments(" not", "followed");
145+
DiagnosticResult expected = Diagnostic(DescriptorNotFollowed).WithSpan(28, 37, 28, 38);
146146
await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
147147
}
148148
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1019CSharp8UnitTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
99
using Microsoft.CodeAnalysis.Testing;
1010
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
1111
using Xunit;
12+
using static StyleCop.Analyzers.SpacingRules.SA1019MemberAccessSymbolsMustBeSpacedCorrectly;
1213
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1314
StyleCop.Analyzers.SpacingRules.SA1019MemberAccessSymbolsMustBeSpacedCorrectly,
1415
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -55,10 +56,10 @@ public void TestMethod(object?[] arguments)
5556

5657
DiagnosticResult[] expected =
5758
{
58-
Diagnostic().WithArguments(".", "preceded").WithLocation(8, 39),
59-
Diagnostic().WithArguments(".", "preceded").WithLocation(9, 40),
60-
Diagnostic().WithArguments("?", "preceded").WithLocation(11, 39),
61-
Diagnostic().WithArguments("?", "preceded").WithLocation(12, 40),
59+
Diagnostic(DescriptorNotPreceded).WithArguments(".").WithLocation(8, 39),
60+
Diagnostic(DescriptorNotPreceded).WithArguments(".").WithLocation(9, 40),
61+
Diagnostic(DescriptorNotPreceded).WithArguments("?").WithLocation(11, 39),
62+
Diagnostic(DescriptorNotPreceded).WithArguments("?").WithLocation(12, 40),
6263
};
6364

6465
await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1024CSharp8UnitTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
77
using System.Threading.Tasks;
88
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
99
using Xunit;
10+
using static StyleCop.Analyzers.SpacingRules.SA1024ColonsMustBeSpacedCorrectly;
1011
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1112
StyleCop.Analyzers.SpacingRules.SA1024ColonsMustBeSpacedCorrectly,
1213
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -49,7 +50,7 @@ public void TestMethod(object value)
4950
}
5051
}";
5152

52-
var expected = Diagnostic().WithSpan(9, 49, 9, 50).WithArguments(" not", "preceded", string.Empty);
53+
var expected = Diagnostic(DescriptorNotPreceded).WithSpan(9, 49, 9, 50);
5354
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
5455
}
5556
}

0 commit comments

Comments
 (0)