Skip to content

Commit 644e443

Browse files
committed
Added tests to improve coverage in SA1009 (ClosingParenthesisMustBeSpacedCorrectly)
1 parent d50579c commit 644e443

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1009UnitTests.cs

Lines changed: 67 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;
@@ -735,6 +736,72 @@ public void TestMethod()
735736
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
736737
}
737738

739+
[Fact]
740+
public async Task TestFollowedByStickyColonAsync()
741+
{
742+
string testCode = @"
743+
class ClassName
744+
{
745+
void Method()
746+
{
747+
switch (0)
748+
{
749+
case(1) :
750+
default:
751+
break;
752+
}
753+
}
754+
}
755+
";
756+
string fixedCode = @"
757+
class ClassName
758+
{
759+
void Method()
760+
{
761+
switch (0)
762+
{
763+
case(1):
764+
default:
765+
break;
766+
}
767+
}
768+
}
769+
";
770+
771+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 15).WithArguments(" not", "followed");
772+
773+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
774+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
775+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
776+
}
777+
778+
[Fact]
779+
public async Task TestMissingTokenAsync()
780+
{
781+
string testCode = @"
782+
class ClassName
783+
{
784+
ClassName()
785+
: base(
786+
{
787+
}
788+
}
789+
";
790+
791+
DiagnosticResult[] expected =
792+
{
793+
new DiagnosticResult
794+
{
795+
Id = "CS1026",
796+
Severity = DiagnosticSeverity.Error,
797+
Message = ") expected",
798+
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 5, 16) }
799+
}
800+
};
801+
802+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
803+
}
804+
738805
/// <inheritdoc/>
739806
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
740807
{

0 commit comments

Comments
 (0)