-
Notifications
You must be signed in to change notification settings - Fork 509
Add tests for mixed deconstruction in C# 10 #4081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,65 @@ | |
|
|
||
| namespace StyleCop.Analyzers.Test.CSharp10.MaintainabilityRules | ||
| { | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.Testing; | ||
| using StyleCop.Analyzers.Test.CSharp9.MaintainabilityRules; | ||
| using Xunit; | ||
| using static StyleCop.Analyzers.MaintainabilityRules.SA1119StatementMustNotUseUnnecessaryParenthesis; | ||
| using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< | ||
| StyleCop.Analyzers.MaintainabilityRules.SA1119StatementMustNotUseUnnecessaryParenthesis, | ||
| StyleCop.Analyzers.MaintainabilityRules.SA1119CodeFixProvider>; | ||
|
|
||
| public partial class SA1119CSharp10UnitTests : SA1119CSharp9UnitTests | ||
| { | ||
| [Fact] | ||
| [WorkItem(3990, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3990")] | ||
| public async Task TestMixedDeconstructionDoesNotReportUnnecessaryParenthesesAsync() | ||
| { | ||
| var testCode = @"public class TestClass | ||
| { | ||
| public void TestMethod() | ||
| { | ||
| int a = 1; | ||
| int b = 2; | ||
| (a, int c) = (3, 4); | ||
| } | ||
| }"; | ||
|
|
||
| await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); | ||
| } | ||
|
|
||
| [Fact] | ||
| [WorkItem(3990, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3990")] | ||
| public async Task TestMixedDeconstructionWithUnnecessaryParenthesesAsync() | ||
| { | ||
| var testCode = @"public class TestClass | ||
| { | ||
| public void TestMethod() | ||
| { | ||
| int a = 1; | ||
| (a, int c) = ((2, 3)); | ||
| } | ||
| }"; | ||
|
|
||
| var fixedCode = @"public class TestClass | ||
| { | ||
| public void TestMethod() | ||
| { | ||
| int a = 1; | ||
| (a, int c) = (2, 3); | ||
| } | ||
| }"; | ||
|
|
||
| DiagnosticResult[] expected = | ||
| { | ||
| Diagnostic(DiagnosticId).WithSpan(6, 22, 6, 30), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any specific reason why markups are not used instead? |
||
| Diagnostic(ParenthesesDiagnosticId).WithSpan(6, 22, 6, 23), | ||
| Diagnostic(ParenthesesDiagnosticId).WithSpan(6, 29, 6, 30), | ||
| }; | ||
|
|
||
| await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ namespace StyleCop.Analyzers.Test.CSharp10.SpacingRules | |
| { | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.Testing; | ||
| using StyleCop.Analyzers.Test.CSharp9.SpacingRules; | ||
| using Xunit; | ||
| using static StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly; | ||
|
|
@@ -108,5 +109,38 @@ void M() | |
| }, | ||
| }.RunAsync(CancellationToken.None).ConfigureAwait(false); | ||
| } | ||
|
|
||
| [Fact] | ||
| [WorkItem(3990, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3990")] | ||
| public async Task TestMixedDeconstructionOpeningParenthesisSpacingAsync() | ||
| { | ||
| var testCode = @"public class TestClass | ||
| { | ||
| public void TestMethod() | ||
| { | ||
| int value = 1; | ||
| {|#0:(|} value, int newValue) = (2, 3); | ||
| } | ||
| }"; | ||
|
|
||
| var fixedCode = @"public class TestClass | ||
| { | ||
| public void TestMethod() | ||
| { | ||
| int value = 1; | ||
| (value, int newValue) = (2, 3); | ||
| } | ||
| }"; | ||
|
|
||
| await new CSharpTest() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use VerifyCSharpFixAsync instead, as normal? I don't realize from reading this PR if there's a reason for doing it differently in this test. |
||
| { | ||
| ExpectedDiagnostics = | ||
| { | ||
| Diagnostic(DescriptorNotFollowed).WithLocation(0), | ||
| }, | ||
| TestCode = testCode, | ||
| FixedCode = fixedCode, | ||
| }.RunAsync(CancellationToken.None).ConfigureAwait(false); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ namespace StyleCop.Analyzers.Test.CSharp10.SpacingRules | |
| { | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.Testing; | ||
| using StyleCop.Analyzers.Test.CSharp9.SpacingRules; | ||
| using Xunit; | ||
| using static StyleCop.Analyzers.SpacingRules.SA1009ClosingParenthesisMustBeSpacedCorrectly; | ||
|
|
@@ -48,5 +49,38 @@ void M() | |
| }, | ||
| }.RunAsync(CancellationToken.None).ConfigureAwait(false); | ||
| } | ||
|
|
||
| [Fact] | ||
| [WorkItem(3990, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3990")] | ||
| public async Task TestMixedDeconstructionClosingParenthesisSpacingAsync() | ||
| { | ||
| var testCode = @"public class TestClass | ||
| { | ||
| public void TestMethod() | ||
| { | ||
| int value = 1; | ||
| (value, int newValue {|#0:)|} = (2, 3); | ||
| } | ||
| }"; | ||
|
|
||
| var fixedCode = @"public class TestClass | ||
| { | ||
| public void TestMethod() | ||
| { | ||
| int value = 1; | ||
| (value, int newValue) = (2, 3); | ||
| } | ||
| }"; | ||
|
|
||
| await new CSharpTest() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here |
||
| { | ||
| ExpectedDiagnostics = | ||
| { | ||
| Diagnostic(DescriptorNotPreceded).WithLocation(0), | ||
| }, | ||
| TestCode = testCode, | ||
| FixedCode = fixedCode, | ||
| }.RunAsync(CancellationToken.None).ConfigureAwait(false); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant because of the next test?