Skip to content

Commit 37835ba

Browse files
committed
Add test for SA1009 with suppression operator
Closes #3143
1 parent dc163bf commit 37835ba

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,62 @@ public void TestMethod<T>()
4545
await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
4646
}
4747

48+
[Fact]
49+
[WorkItem(3143, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3143")]
50+
public async Task TestFollowedBySuppressionOperator2Async()
51+
{
52+
const string testCode = @"
53+
using System;
54+
55+
public class Base
56+
{
57+
protected Base(Func<string, int> to, Func<int, string> from) => throw null;
58+
}
59+
60+
public class Derived : Base
61+
{
62+
public Derived()
63+
: base(
64+
(v) => int.Parse(v{|#0:)|} !,
65+
(v) => v.ToString({|#1:)|} ! {|#2:)|}
66+
{
67+
}
68+
}
69+
";
70+
const string fixedCode = @"
71+
using System;
72+
73+
public class Base
74+
{
75+
protected Base(Func<string, int> to, Func<int, string> from) => throw null;
76+
}
77+
78+
public class Derived : Base
79+
{
80+
public Derived()
81+
: base(
82+
(v) => int.Parse(v)!,
83+
(v) => v.ToString()!)
84+
{
85+
}
86+
}
87+
";
88+
89+
DiagnosticResult[] expected =
90+
{
91+
// /0/Test0.cs(13,31): warning SA1009: Closing parenthesis should not be followed by a space
92+
Diagnostic(DescriptorNotFollowed).WithLocation(0),
93+
94+
// /0/Test0.cs(14,31): warning SA1009: Closing parenthesis should not be followed by a space
95+
Diagnostic(DescriptorNotFollowed).WithLocation(1),
96+
97+
// /0/Test0.cs(14,35): warning SA1009: Closing parenthesis should not be preceded by a space
98+
Diagnostic(DescriptorNotPreceded).WithLocation(2),
99+
};
100+
101+
await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
102+
}
103+
48104
[Fact]
49105
[WorkItem(2968, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2968")]
50106
public async Task TestExpressionBodyEndsWithSuppressionAsync()

0 commit comments

Comments
 (0)