Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,55 @@

namespace StyleCop.Analyzers.Test.CSharp11.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp10.SpacingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.SpacingRules.SA1011ClosingSquareBracketsMustBeSpacedCorrectly,
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;

public class SA1011CSharp11UnitTests : SA1011CSharp10UnitTests
{
[Fact]
[WorkItem(3673, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3673")]
public async Task TestListPatternInSwitchCaseAsync()
{
var testCode = @"public class TestClass
{
public void TestMethod(object[] arg)
{
switch (arg)
{
case [string s{|#0:]|} :
break;
}
}}
";

var fixedCode = @"public class TestClass
{
public void TestMethod(object[] arg)
{
switch (arg)
{
case [string s]:
break;
}
}}
";

await new CSharpTest
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net70,
TestCode = testCode,
ExpectedDiagnostics =
{
Diagnostic().WithLocation(0).WithArguments(" not", "followed"),
},
FixedCode = fixedCode,
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ private static void HandleCloseBracketToken(SyntaxTreeAnalysisContext context, S
break;

case SyntaxKind.ColonToken:
precedesSpecialCharacter = nextToken.Parent.IsKind(SyntaxKind.InterpolationFormatClause);
precedesSpecialCharacter =
nextToken.Parent.IsKind(SyntaxKind.InterpolationFormatClause) ||
nextToken.Parent.IsKind(SyntaxKindEx.CasePatternSwitchLabel);
suppressFollowingSpaceError = false;
break;

Expand Down