Skip to content

Commit 84706f3

Browse files
committed
Update SA1000 tests for relational and logical patterns
1 parent ff14d11 commit 84706f3

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
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 System.Threading.Tasks;
97
using Microsoft.CodeAnalysis.Testing;
108
using StyleCop.Analyzers.Test.CSharp8.SpacingRules;
119
using Xunit;
12-
1310
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1411
StyleCop.Analyzers.SpacingRules.SA1000KeywordsMustBeSpacedCorrectly,
1512
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
@@ -24,47 +21,58 @@ public async Task TestTargetTypedNewAsync()
2421
await this.TestKeywordStatementAsync(statementWithoutSpace, DiagnosticResult.EmptyDiagnosticResults, statementWithoutSpace).ConfigureAwait(false);
2522
}
2623

27-
[Fact]
24+
[Theory]
2825
[WorkItem(3508, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3508")]
29-
public async Task TestIsBeforeRelationalPatternAsync()
26+
[InlineData("<")]
27+
[InlineData("<=")]
28+
[InlineData(">")]
29+
[InlineData(">=")]
30+
public async Task TestIsBeforeRelationalPatternAsync(string @operator)
3031
{
31-
var statementWithoutSpace = "_ = 1 {|#0:is|}>1;";
32-
var statementWithSpace = "_ = 1 is >1;";
32+
var statementWithoutSpace = $"_ = 1 {{|#0:is|}}{@operator}1;";
33+
var statementWithSpace = $"_ = 1 is {@operator}1;";
3334

3435
var expected = Diagnostic().WithArguments("is", string.Empty, "followed").WithLocation(0);
3536
await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace).ConfigureAwait(false);
3637
}
3738

38-
[Fact]
39+
[Theory]
3940
[WorkItem(3508, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3508")]
40-
public async Task TestNotBeforeRelationalPatternAsync()
41+
[InlineData("<")]
42+
[InlineData("<=")]
43+
[InlineData(">")]
44+
[InlineData(">=")]
45+
public async Task TestNotBeforeRelationalPatternAsync(string relationalOperator)
4146
{
42-
var statementWithoutSpace = "_ = 1 is {|#0:not|}>1;";
43-
var statementWithSpace = "_ = 1 is not >1;";
47+
var statementWithoutSpace = $"_ = 1 is {{|#0:not|}}{relationalOperator}1;";
48+
var statementWithSpace = $"_ = 1 is not {relationalOperator}1;";
4449

4550
var expected = Diagnostic().WithArguments("not", string.Empty, "followed").WithLocation(0);
4651
await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace).ConfigureAwait(false);
4752
}
4853

49-
[Fact]
54+
[Theory]
5055
[WorkItem(3508, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3508")]
51-
public async Task TestAndBeforeRelationalPatternAsync()
56+
[CombinatorialData]
57+
public async Task TestAndBeforeRelationalPatternAsync(
58+
[CombinatorialValues("and", "or")] string logicalOperator,
59+
[CombinatorialValues("<", "<=", ">", ">=")] string relationalOperator)
5260
{
53-
var statementWithoutSpace = "_ = 1 is 1 {|#0:and|}>0;";
54-
var statementWithSpace = "_ = 1 is 1 and >0;";
61+
var statementWithoutSpace = $"_ = (int?)1 is not null {{|#0:{logicalOperator}|}}{relationalOperator}1;";
62+
var statementWithSpace = $"_ = (int?)1 is not null {logicalOperator} {relationalOperator}1;";
5563

56-
var expected = Diagnostic().WithArguments("and", string.Empty, "followed").WithLocation(0);
64+
var expected = Diagnostic().WithArguments(logicalOperator, string.Empty, "followed").WithLocation(0);
5765
await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace).ConfigureAwait(false);
5866
}
5967

6068
[Fact]
61-
[WorkItem(3508, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3508")]
62-
public async Task TestOrBeforeRelationalPatternAsync()
69+
[WorkItem(3968, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3968")]
70+
public async Task TestNotBeforeConstantPatternMissingSpaceAsync()
6371
{
64-
var statementWithoutSpace = "_ = 1 is 1 {|#0:or|}>1;";
65-
var statementWithSpace = "_ = 1 is 1 or >1;";
72+
var statementWithoutSpace = "_ = new object() is {|#0:not|}(null);";
73+
var statementWithSpace = "_ = new object() is not (null);";
6674

67-
var expected = Diagnostic().WithArguments("or", string.Empty, "followed").WithLocation(0);
75+
var expected = Diagnostic().WithArguments("not", string.Empty, "followed").WithLocation(0);
6876
await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace).ConfigureAwait(false);
6977
}
7078
}

0 commit comments

Comments
 (0)