Skip to content

Commit f76adf3

Browse files
committed
Add additional test cases
1 parent c74913b commit f76adf3

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1008CSharp12UnitTests.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,67 @@ class TestClass
5050

5151
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
5252
}
53+
54+
[Fact]
55+
[WorkItem(3931, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3931")]
56+
public async Task TestLambdaAfterCommaInCollectionExpressionAsync()
57+
{
58+
var testCode = @"
59+
class TestClass
60+
{
61+
private System.Func<int, int, int>[] functions = [(x, y) => x + y,{|#0:(|}x, y) => x - y];
62+
}
63+
";
64+
65+
var fixedCode = @"
66+
class TestClass
67+
{
68+
private System.Func<int, int, int>[] functions = [(x, y) => x + y, (x, y) => x - y];
69+
}
70+
";
71+
72+
var expected = Diagnostic(DescriptorPreceded).WithLocation(0);
73+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
74+
}
75+
76+
[Fact]
77+
[WorkItem(3931, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3931")]
78+
public async Task TestLambdaAfterSpreadInCollectionExpressionAsync()
79+
{
80+
var testCode = @"
81+
class TestClass
82+
{
83+
private static System.Func<int, int, int>[] existing = [(x, y) => x + y];
84+
private System.Func<int, int, int>[] functions = [..existing,{|#0:(|}x, y) => x - y];
85+
}
86+
";
87+
88+
var fixedCode = @"
89+
class TestClass
90+
{
91+
private static System.Func<int, int, int>[] existing = [(x, y) => x + y];
92+
private System.Func<int, int, int>[] functions = [..existing, (x, y) => x - y];
93+
}
94+
";
95+
96+
var expected = Diagnostic(DescriptorPreceded).WithLocation(0);
97+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
98+
}
99+
100+
[Fact]
101+
[WorkItem(3931, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3931")]
102+
public async Task TestLambdaWithBracketOnPreviousLineAsync()
103+
{
104+
var testCode = @"
105+
class TestClass
106+
{
107+
private System.Func<int, int, int>[] functions = [
108+
(x, y) => x + y
109+
];
110+
}
111+
";
112+
113+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
114+
}
53115
}
54116
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1008UnitTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,34 @@ public void TestMethod1()
18951895
await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
18961896
}
18971897

1898+
[Fact]
1899+
[WorkItem(3931, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3931")]
1900+
public async Task TestLambdaInCollectionInitializerAsync()
1901+
{
1902+
var testCode = @"
1903+
using System;
1904+
using System.Collections.Generic;
1905+
1906+
class TestClass
1907+
{
1908+
private List<Action<int, int>> actions = new List<Action<int, int>>() {{|#0:(|}x, y) => { } };
1909+
}
1910+
";
1911+
1912+
var fixedCode = @"
1913+
using System;
1914+
using System.Collections.Generic;
1915+
1916+
class TestClass
1917+
{
1918+
private List<Action<int, int>> actions = new List<Action<int, int>>() { (x, y) => { } };
1919+
}
1920+
";
1921+
1922+
var expected = Diagnostic(DescriptorPreceded).WithLocation(0);
1923+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
1924+
}
1925+
18981926
/// <summary>
18991927
/// Verifies that multi-line comments are handled properly.
19001928
/// </summary>

0 commit comments

Comments
 (0)