Skip to content

Commit 61b5930

Browse files
committed
Update SA1013 tests to use spans instead of locations
1 parent 49ef1d5 commit 61b5930

5 files changed

Lines changed: 38 additions & 48 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1013CSharp10UnitTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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.CSharp10.SpacingRules
75
{
86
using StyleCop.Analyzers.Test.CSharp9.SpacingRules;

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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.CSharp7.SpacingRules
75
{
86
using System.Threading;
@@ -32,7 +30,7 @@ public class Foo
3230
{
3331
public void TestMethod()
3432
{
35-
var values = (new[] { 3} , new[] { 3} );
33+
var values = (new[] { 3{|#0:}|} , new[] { 3{|#1:}|} );
3634
}
3735
}";
3836
const string fixedCode = @"using System;
@@ -47,8 +45,8 @@ public void TestMethod()
4745

4846
DiagnosticResult[] expected =
4947
{
50-
Diagnostic().WithLocation(7, 32).WithArguments(string.Empty, "preceded"),
51-
Diagnostic().WithLocation(7, 45).WithArguments(string.Empty, "preceded"),
48+
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
49+
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
5250
};
5351

5452
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -65,12 +63,12 @@ public unsafe void TestMethod()
6563
{
6664
int* data1 = stackalloc int[] { 1 , 1 } ;
6765
int* data2 = stackalloc int[] { 1 , 1 };
68-
int* data3 = stackalloc int[] { 1 , 1} ;
69-
int* data4 = stackalloc int[] { 1 , 1};
66+
int* data3 = stackalloc int[] { 1 , 1{|#0:}|} ;
67+
int* data4 = stackalloc int[] { 1 , 1{|#1:}|};
7068
int* data5 = stackalloc int[] { 1 , 1
7169
};
7270
int* data6 = stackalloc int[]
73-
{ 1 , 1};
71+
{ 1 , 1{|#2:}|};
7472
int* data7 = stackalloc int[]
7573
{
7674
1 , 1 } ;
@@ -103,9 +101,9 @@ public unsafe void TestMethod()
103101

104102
DiagnosticResult[] expected =
105103
{
106-
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(9, 50),
107-
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(10, 50),
108-
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(14, 20),
104+
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
105+
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
106+
Diagnostic().WithLocation(2).WithArguments(string.Empty, "preceded"),
109107
};
110108

111109
await VerifyCSharpFixAsync(LanguageVersion.CSharp7_3, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -122,12 +120,12 @@ public unsafe void TestMethod()
122120
{
123121
int* data1 = stackalloc[] { 1 , 1 } ;
124122
int* data2 = stackalloc[] { 1 , 1 };
125-
int* data3 = stackalloc[] { 1 , 1} ;
126-
int* data4 = stackalloc[] { 1 , 1};
123+
int* data3 = stackalloc[] { 1 , 1{|#0:}|} ;
124+
int* data4 = stackalloc[] { 1 , 1{|#1:}|};
127125
int* data5 = stackalloc[] { 1 , 1
128126
};
129127
int* data6 = stackalloc[]
130-
{ 1 , 1};
128+
{ 1 , 1{|#2:}|};
131129
int* data7 = stackalloc[]
132130
{
133131
1 , 1 } ;
@@ -160,9 +158,9 @@ public unsafe void TestMethod()
160158

161159
DiagnosticResult[] expected =
162160
{
163-
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(9, 46),
164-
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(10, 46),
165-
Diagnostic().WithArguments(string.Empty, "preceded").WithLocation(14, 20),
161+
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
162+
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
163+
Diagnostic().WithLocation(2).WithArguments(string.Empty, "preceded"),
166164
};
167165

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

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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.CSharp8.SpacingRules
75
{
86
using System.Threading;
@@ -43,7 +41,7 @@ public void TestMethod(object value)
4341
break;
4442
4543
// The space before 'message' is checked
46-
case Exception { Message: { }message }:
44+
case Exception { Message: { {|#0:}|}message }:
4745
break;
4846
}
4947
}
@@ -67,7 +65,7 @@ public void TestMethod(object value)
6765
}
6866
}";
6967

70-
var expected = Diagnostic().WithSpan(14, 37, 14, 38).WithArguments(string.Empty, "followed");
68+
var expected = Diagnostic().WithLocation(0).WithArguments(string.Empty, "followed");
7169
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
7270
}
7371

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/SpacingRules/SA1013CSharp9UnitTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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.CSharp9.SpacingRules
75
{
86
using StyleCop.Analyzers.Test.CSharp8.SpacingRules;

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1013UnitTests.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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.SpacingRules
75
{
86
using System.Threading;
@@ -61,8 +59,8 @@ public void TestMethod()
6159
x = $""{test}"";
6260
x = $""({test})"";
6361
x = $""({test} )"";
64-
x = $""{test }"";
65-
x = $""{test } "";
62+
x = $""{test {|#0:}|}"";
63+
x = $""{test {|#1:}|} "";
6664
}
6765
}
6866
}
@@ -88,8 +86,8 @@ public void TestMethod()
8886

8987
DiagnosticResult[] expected =
9088
{
91-
Diagnostic().WithLocation(12, 25).WithArguments(" not", "preceded"),
92-
Diagnostic().WithLocation(13, 25).WithArguments(" not", "preceded"),
89+
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
90+
Diagnostic().WithLocation(1).WithArguments(" not", "preceded"),
9391
};
9492

9593
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -107,7 +105,7 @@ public async Task TestPropertyDeclarationAsync()
107105
public class TestClass
108106
{
109107
public int TestProperty1 { get; set; }
110-
public int TestProperty2 { get; set;}
108+
public int TestProperty2 { get; set;{|#0:}|}
111109
}
112110
}
113111
";
@@ -124,7 +122,7 @@ public class TestClass
124122

125123
DiagnosticResult[] expected =
126124
{
127-
Diagnostic().WithLocation(6, 45).WithArguments(string.Empty, "preceded"),
125+
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
128126
};
129127

130128
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -146,9 +144,9 @@ public class TestClass
146144
public void TestMethod()
147145
{
148146
new Dictionary<int, int> { { 1, 1 } };
149-
new Dictionary<int, int> { { 1, 1} };
150-
new Dictionary<int, int> { { 1, 1 }};
151-
new Dictionary<int, int> { { 1, 1}};
147+
new Dictionary<int, int> { { 1, 1{|#0:}|} };
148+
new Dictionary<int, int> { { 1, 1 {|#1:}|}{|#2:}|};
149+
new Dictionary<int, int> { { 1, 1{|#3:}|}{|#4:}|};
152150
}
153151
}
154152
}
@@ -173,12 +171,12 @@ public void TestMethod()
173171

174172
DiagnosticResult[] expected =
175173
{
176-
Diagnostic().WithLocation(10, 46).WithArguments(string.Empty, "preceded"),
177-
Diagnostic().WithLocation(11, 47).WithArguments(string.Empty, "followed"),
178-
Diagnostic().WithLocation(11, 48).WithArguments(string.Empty, "preceded"),
179-
Diagnostic().WithLocation(12, 46).WithArguments(string.Empty, "preceded"),
180-
Diagnostic().WithLocation(12, 46).WithArguments(string.Empty, "followed"),
181-
Diagnostic().WithLocation(12, 47).WithArguments(string.Empty, "preceded"),
174+
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
175+
Diagnostic().WithLocation(1).WithArguments(string.Empty, "followed"),
176+
Diagnostic().WithLocation(2).WithArguments(string.Empty, "preceded"),
177+
Diagnostic().WithLocation(3).WithArguments(string.Empty, "preceded"),
178+
Diagnostic().WithLocation(3).WithArguments(string.Empty, "followed"),
179+
Diagnostic().WithLocation(4).WithArguments(string.Empty, "preceded"),
182180
};
183181

184182
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -297,9 +295,9 @@ public void TestMethod1(object[] a)
297295
public void TestMethod2()
298296
{
299297
TestMethod1(new object[] { });
300-
TestMethod1(new object[] {});
298+
TestMethod1(new object[] {{|#0:}|});
301299
TestMethod1(new object[] { } );
302-
TestMethod1(new object[] {} );
300+
TestMethod1(new object[] {{|#1:}|} );
303301
}
304302
}
305303
}
@@ -327,8 +325,8 @@ public void TestMethod2()
327325
// space between closing brace and closing parenthesis should be reported by SA1009
328326
DiagnosticResult[] expected =
329327
{
330-
Diagnostic().WithLocation(12, 39).WithArguments(string.Empty, "preceded"),
331-
Diagnostic().WithLocation(14, 39).WithArguments(string.Empty, "preceded"),
328+
Diagnostic().WithLocation(0).WithArguments(string.Empty, "preceded"),
329+
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
332330
};
333331

334332
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -383,12 +381,12 @@ public async Task TestMissingTokenAsync()
383381
{
384382
string testCode = @"
385383
class ClassName
386-
{
384+
{{|#0:|}
387385
";
388386

389387
DiagnosticResult[] expected =
390388
{
391-
DiagnosticResult.CompilerError("CS1513").WithMessage("} expected").WithLocation(3, 2),
389+
DiagnosticResult.CompilerError("CS1513").WithMessage("} expected").WithLocation(0),
392390
};
393391

394392
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

0 commit comments

Comments
 (0)