Skip to content

Commit d50579c

Browse files
committed
Added tests to improve coverage in SA1008 (OpeningParenthesisMustBeSpacedCorrectly)
1 parent 925ff16 commit d50579c

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace StyleCop.Analyzers.Test.SpacingRules
66
using System.Collections.Generic;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
using Microsoft.CodeAnalysis;
910
using Microsoft.CodeAnalysis.CodeFixes;
1011
using Microsoft.CodeAnalysis.Diagnostics;
1112
using StyleCop.Analyzers.SpacingRules;
@@ -1727,6 +1728,33 @@ public void TestMethod()
17271728
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
17281729
}
17291730

1731+
[Fact]
1732+
public async Task TestMissingTokenAsync()
1733+
{
1734+
string testCode = @"
1735+
class ClassName
1736+
{
1737+
ClassName()
1738+
: base)
1739+
{
1740+
}
1741+
}
1742+
";
1743+
1744+
DiagnosticResult[] expected =
1745+
{
1746+
new DiagnosticResult
1747+
{
1748+
Id = "CS1003",
1749+
Severity = DiagnosticSeverity.Error,
1750+
Message = "Syntax error, '(' expected",
1751+
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 5, 15) }
1752+
}
1753+
};
1754+
1755+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1756+
}
1757+
17301758
/// <inheritdoc/>
17311759
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
17321760
{

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt
152152
case SyntaxKind.DefaultExpression:
153153
case SyntaxKind.SizeOfExpression:
154154
case SyntaxKind.TypeOfExpression:
155+
default:
155156
haveLeadingSpace = false;
156157
break;
157158

@@ -182,10 +183,6 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt
182183
var partOfLambdaExpression = token.Parent.Parent.IsKind(SyntaxKind.ParenthesizedLambdaExpression);
183184
haveLeadingSpace = partOfLambdaExpression;
184185
break;
185-
186-
default:
187-
haveLeadingSpace = false;
188-
break;
189186
}
190187

191188
// Ignore spacing before if another opening parenthesis is before this.

0 commit comments

Comments
 (0)