Skip to content
Open
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 @@ -5,6 +5,7 @@ namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;
using Xunit;

Expand All @@ -28,5 +29,48 @@ public async Task TestTupleUsingAliasAsync()
var expected = Diagnostic(DescriptorPreceded).WithLocation(0);
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3894, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3894")]
public async Task TestCollectionExpressionAsync()
{
var testCode = @"
namespace TestNamespace
{
public class TestClass
{
public void TestMethod()
{
int[] x = [ {|#0:(|} 0 + 0)];
}
}
}
";

var fixedCode = @"
namespace TestNamespace
{
public class TestClass
{
public void TestMethod()
{
int[] x = [(0 + 0)];
}
}
}
";

DiagnosticResult[] expectedResults =
{
Diagnostic(DescriptorNotPreceded).WithLocation(0),
Diagnostic(DescriptorNotFollowed).WithLocation(0),
};

await VerifyCSharpFixAsync(
testCode,
expectedResults,
fixedCode,
CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,48 @@ await VerifyCSharpFixAsync(
fixedCode,
CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3894, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3894")]
public async Task TestLeftOperandInRangeExpressionAsync()
{
var testCode = @"
namespace TestNamespace
{
public class TestClass
{
public void TestMethod()
{
var x ={|#0:(|} 0 + 0)..1;
}
}
}
";

var fixedCode = @"
namespace TestNamespace
{
public class TestClass
{
public void TestMethod()
{
var x = (0 + 0)..1;
}
}
}
";

DiagnosticResult[] expectedResults =
{
Diagnostic(DescriptorPreceded).WithLocation(0),
Diagnostic(DescriptorNotFollowed).WithLocation(0),
};

await VerifyCSharpFixAsync(
testCode,
expectedResults,
fixedCode,
CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt
case SyntaxKind.ParenthesizedExpression:
case SyntaxKindEx.TupleExpression:
if (prevToken.Parent.IsKind(SyntaxKind.Interpolation)
|| token.Parent.Parent.IsKind(SyntaxKindEx.RangeExpression))
|| (token.Parent.Parent.IsKind(SyntaxKindEx.RangeExpression) && ((RangeExpressionSyntaxWrapper)token.Parent.Parent).RightOperand == token.Parent))
{
haveLeadingSpace = false;
break;
Expand Down
Loading