Skip to content

Commit 3371d96

Browse files
committed
Update SA1008 tests for relational and logical patterns
1 parent 84706f3 commit 3371d96

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,46 @@ public async Task TestDeconstructionInTopLevelProgramAsync(string prefix)
110110
FixedCode = fixedCode,
111111
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
112112
}
113+
114+
[Fact]
115+
[WorkItem(3968, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3968")]
116+
public async Task TestLogicalPatternsWithParenthesesAsync()
117+
{
118+
const string testCode = @"
119+
class C
120+
{
121+
void M(int value)
122+
{
123+
_ = value is not{|#0:(|}> 0);
124+
_ = value is > 0 and{|#1:(|}< 5);
125+
_ = value is > 0 and {|#2:(|} < 5);
126+
_ = value is > 10 or{|#3:(|}< 5);
127+
_ = value is > 10 or {|#4:(|} < 5);
128+
}
129+
}";
130+
131+
const string fixedCode = @"
132+
class C
133+
{
134+
void M(int value)
135+
{
136+
_ = value is not (> 0);
137+
_ = value is > 0 and (< 5);
138+
_ = value is > 0 and (< 5);
139+
_ = value is > 10 or (< 5);
140+
_ = value is > 10 or (< 5);
141+
}
142+
}";
143+
144+
DiagnosticResult[] expected =
145+
{
146+
Diagnostic(DescriptorPreceded).WithLocation(0),
147+
Diagnostic(DescriptorPreceded).WithLocation(1),
148+
Diagnostic(DescriptorNotFollowed).WithLocation(2),
149+
Diagnostic(DescriptorPreceded).WithLocation(3),
150+
Diagnostic(DescriptorNotFollowed).WithLocation(4),
151+
};
152+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
153+
}
113154
}
114155
}

0 commit comments

Comments
 (0)