Skip to content

Commit

Permalink
Merge 8906e8e into a559b3e
Browse files Browse the repository at this point in the history
  • Loading branch information
pantosha authored Jul 19, 2021
2 parents a559b3e + 8906e8e commit 5485d35
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,78 @@ public unsafe void TestMethod()

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3370, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3370")]
public async Task TestRangeFollowedByMemberCallAsync()
{
const string testCode = @"using System;
public class TestClass
{
public void TestMethod()
{
var array = (1..10).ToString();
}
}
";

await new CSharpTest(LanguageVersion.CSharp8)
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
TestCode = testCode,
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3370, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3370")]
public async Task TestRangeAsync()
{
const string testCode = @"using System;
public class TestClass
{
public void TestMethod()
{
var a = new int[0];
var b = a[(..)];
var range = (1..10);
}
}
";

const string fixedCode = @"using System;
public class TestClass
{
public void TestMethod()
{
var a = new int[0];
var b = a[..];
var range = 1..10;
}
}
";

DiagnosticResult[] expected =
{
Diagnostic(DiagnosticId).WithSpan(8, 19, 8, 23),
Diagnostic(ParenthesesDiagnosticId).WithLocation(8, 19),
Diagnostic(ParenthesesDiagnosticId).WithLocation(8, 22),
Diagnostic(DiagnosticId).WithSpan(9, 21, 9, 28),
Diagnostic(ParenthesesDiagnosticId).WithLocation(9, 21),
Diagnostic(ParenthesesDiagnosticId).WithLocation(9, 27),
};

var test = new CSharpTest(LanguageVersion.CSharp8)
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
TestCode = testCode,
FixedCode = fixedCode,
};
test.ExpectedDiagnostics.AddRange(expected);

await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private static void HandleParenthesizedExpression(SyntaxNodeAnalysisContext cont
&& !node.Expression.IsKind(SyntaxKind.CoalesceExpression)
&& !node.Expression.IsKind(SyntaxKind.QueryExpression)
&& !node.Expression.IsKind(SyntaxKind.AwaitExpression)
&& !node.Expression.IsKind(SyntaxKindEx.RangeExpression)
&& !node.IsKind(SyntaxKind.ConstructorDeclaration))
{
if (node.Expression.IsKind(SyntaxKind.ConditionalAccessExpression)
Expand Down

0 comments on commit 5485d35

Please sign in to comment.