Skip to content

Commit 16ff759

Browse files
committed
Update SA1119 for indices and ranges
1 parent 7ffed65 commit 16ff759

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/MaintainabilityRules/SA1119CSharp8UnitTests.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,5 +328,82 @@ public void TestMethod()
328328

329329
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
330330
}
331+
332+
[Fact]
333+
[WorkItem(3008, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3008")]
334+
public async Task TestParenthesizedRangeExpressionsAreAcceptedAsync()
335+
{
336+
const string testCode = @"using System;
337+
338+
public class TestClass
339+
{
340+
public Range TestMethod(int length)
341+
{
342+
Range local = {|#0:{|#1:(|}1..^3{|#2:)|}|};
343+
return {|#3:{|#4:(|}1..^length{|#5:)|}|};
344+
}
345+
}
346+
";
347+
const string fixedCode = @"using System;
348+
349+
public class TestClass
350+
{
351+
public Range TestMethod(int length)
352+
{
353+
Range local = 1..^3;
354+
return 1..^length;
355+
}
356+
}
357+
";
358+
359+
DiagnosticResult[] expected =
360+
{
361+
Diagnostic(DiagnosticId).WithLocation(0),
362+
Diagnostic(ParenthesesDiagnosticId).WithLocation(1),
363+
Diagnostic(ParenthesesDiagnosticId).WithLocation(2),
364+
Diagnostic(DiagnosticId).WithLocation(3),
365+
Diagnostic(ParenthesesDiagnosticId).WithLocation(4),
366+
Diagnostic(ParenthesesDiagnosticId).WithLocation(5),
367+
};
368+
369+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
370+
}
371+
372+
[Fact]
373+
[WorkItem(3008, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3008")]
374+
public async Task TestParenthesizedIndexExpressionsAreAcceptedAsync()
375+
{
376+
const string testCode = @"using System;
377+
378+
public class TestClass
379+
{
380+
public int TestMethod(int length)
381+
{
382+
Index index = {|#0:{|#1:(|}^5{|#2:)|}|};
383+
return (^2).GetOffset(length);
384+
}
385+
}
386+
";
387+
const string fixedCode = @"using System;
388+
389+
public class TestClass
390+
{
391+
public int TestMethod(int length)
392+
{
393+
Index index = ^5;
394+
return (^2).GetOffset(length);
395+
}
396+
}
397+
";
398+
399+
DiagnosticResult[] expected =
400+
{
401+
Diagnostic(DiagnosticId).WithLocation(0),
402+
Diagnostic(ParenthesesDiagnosticId).WithLocation(1),
403+
Diagnostic(ParenthesesDiagnosticId).WithLocation(2),
404+
};
405+
406+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
407+
}
331408
}
332409
}

0 commit comments

Comments
 (0)