@@ -14,22 +14,24 @@ namespace StyleCop.Analyzers.Test.NamingRules
1414
1515 public class SA1308UnitTests : CodeFixVerifier
1616 {
17+ private const string UnderscoreEscapeSequence = @"\\u005F" ;
18+
1719 private readonly string [ ] modifiers = new [ ] { "public" , "private" , "protected" , "public readonly" , "internal readonly" , "public static" , "private static" } ;
1820
1921 public static IEnumerable < object [ ] > PrefixesData ( )
2022 {
2123 yield return new object [ ] { "m_" } ;
2224 yield return new object [ ] { "s_" } ;
2325 yield return new object [ ] { "t_" } ;
24- yield return new object [ ] { "m \\ u005F " } ;
25- yield return new object [ ] { "s \\ u005F " } ;
26- yield return new object [ ] { "t \\ u005F " } ;
26+ yield return new object [ ] { $ "m { UnderscoreEscapeSequence } " } ;
27+ yield return new object [ ] { $ "s { UnderscoreEscapeSequence } " } ;
28+ yield return new object [ ] { $ "t { UnderscoreEscapeSequence } " } ;
2729 }
2830
2931 public static IEnumerable < object [ ] > MultipleDistinctPrefixesData ( )
3032 {
3133 yield return new object [ ] { "m_t_s_" , "m_" } ;
32- yield return new object [ ] { "s \\ u005Fm \\ u005Ft \\ u005F ", "s_" } ;
34+ yield return new object [ ] { $ "s { UnderscoreEscapeSequence } m { UnderscoreEscapeSequence } t { UnderscoreEscapeSequence } ", "s_" } ;
3335 }
3436
3537 [ Fact ]
@@ -40,9 +42,9 @@ public async Task TestFieldStartingWithPrefixesToTriggerDiagnosticAsync()
4042 await this . TestFieldSpecifyingModifierAndPrefixAsync ( modifier , "m_" , "m_" ) . ConfigureAwait ( false ) ;
4143 await this . TestFieldSpecifyingModifierAndPrefixAsync ( modifier , "s_" , "s_" ) . ConfigureAwait ( false ) ;
4244 await this . TestFieldSpecifyingModifierAndPrefixAsync ( modifier , "t_" , "t_" ) . ConfigureAwait ( false ) ;
43- await this . TestFieldSpecifyingModifierAndPrefixAsync ( modifier , "m \\ u005F ", "m_" ) . ConfigureAwait ( false ) ;
44- await this . TestFieldSpecifyingModifierAndPrefixAsync ( modifier , "s \\ u005F ", "s_" ) . ConfigureAwait ( false ) ;
45- await this . TestFieldSpecifyingModifierAndPrefixAsync ( modifier , "t \\ u005F ", "t_" ) . ConfigureAwait ( false ) ;
45+ await this . TestFieldSpecifyingModifierAndPrefixAsync ( modifier , $ "m { UnderscoreEscapeSequence } ", "m_" ) . ConfigureAwait ( false ) ;
46+ await this . TestFieldSpecifyingModifierAndPrefixAsync ( modifier , $ "s { UnderscoreEscapeSequence } ", "s_" ) . ConfigureAwait ( false ) ;
47+ await this . TestFieldSpecifyingModifierAndPrefixAsync ( modifier , $ "t { UnderscoreEscapeSequence } ", "t_" ) . ConfigureAwait ( false ) ;
4648 }
4749 }
4850
@@ -100,10 +102,10 @@ public async Task TestFixingMultipleIdenticalPrefixesAsync(string prefix)
100102 private string { prefix } { prefix } bar = ""baz"";
101103}}" ;
102104
103- string diagnosticPrefix = prefix . Replace ( " \\ u005F" , "_" ) ;
105+ string diagnosticPrefix = UnescapeUnderscores ( prefix ) ;
104106 DiagnosticResult expected =
105107 this . CSharpDiagnostic ( )
106- . WithArguments ( $ "{ prefix } { prefix } bar", diagnosticPrefix )
108+ . WithArguments ( $ "{ diagnosticPrefix } { diagnosticPrefix } bar", diagnosticPrefix )
107109 . WithLocation ( 3 , 20 ) ;
108110
109111 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
@@ -121,9 +123,10 @@ public async Task TestMultipleIdenticalPrefixesOnlyAsync(string prefix)
121123 private string { prefix } { prefix } = ""baz"";
122124}}" ;
123125
126+ string diagnosticPrefix = UnescapeUnderscores ( prefix ) ;
124127 DiagnosticResult expected =
125128 this . CSharpDiagnostic ( )
126- . WithArguments ( $ "{ prefix } { prefix } ", prefix )
129+ . WithArguments ( $ "{ diagnosticPrefix } { diagnosticPrefix } ", diagnosticPrefix )
127130 . WithLocation ( 3 , 20 ) ;
128131
129132 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
@@ -149,9 +152,10 @@ public async Task TestFixingMultipleDistinctPrefixesAsync(string prefixes, strin
149152 private string { prefixes } bar = ""baz"";
150153}}" ;
151154
155+ string diagnosticPrefixes = UnescapeUnderscores ( prefixes ) ;
152156 DiagnosticResult expected =
153157 this . CSharpDiagnostic ( )
154- . WithArguments ( $ "{ prefixes } bar", diagnosticPrefix )
158+ . WithArguments ( $ "{ diagnosticPrefixes } bar", diagnosticPrefix )
155159 . WithLocation ( 3 , 20 ) ;
156160
157161 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
@@ -169,9 +173,10 @@ public async Task TestMultipleDistinctPrefixesOnlyAsync(string prefixes, string
169173 private string { prefixes } = ""baz"";
170174}}" ;
171175
176+ string diagnosticPrefixes = UnescapeUnderscores ( prefixes ) ;
172177 DiagnosticResult expected =
173178 this . CSharpDiagnostic ( )
174- . WithArguments ( prefixes , diagnosticPrefix )
179+ . WithArguments ( diagnosticPrefixes , diagnosticPrefix )
175180 . WithLocation ( 3 , 20 ) ;
176181
177182 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
@@ -190,6 +195,8 @@ protected override CodeFixProvider GetCSharpCodeFixProvider()
190195 return new SA1308CodeFixProvider ( ) ;
191196 }
192197
198+ private static string UnescapeUnderscores ( string identifier ) => identifier . Replace ( UnderscoreEscapeSequence , "_" ) ;
199+
193200 private async Task TestFieldSpecifyingModifierAndPrefixAsync ( string modifier , string codePrefix , string diagnosticPrefix )
194201 {
195202 var originalCode = @"public class Foo
0 commit comments