diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/MaintainabilityRules/SA1119CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/MaintainabilityRules/SA1119CSharp10UnitTests.cs index 62d03cfcf..09376872d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/MaintainabilityRules/SA1119CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/MaintainabilityRules/SA1119CSharp10UnitTests.cs @@ -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), + Diagnostic(ParenthesesDiagnosticId).WithSpan(6, 22, 6, 23), + Diagnostic(ParenthesesDiagnosticId).WithSpan(6, 29, 6, 30), + }; + + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1305CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1305CSharp10UnitTests.cs index b341a89fd..90f9376c0 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1305CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1305CSharp10UnitTests.cs @@ -3,9 +3,34 @@ namespace StyleCop.Analyzers.Test.CSharp10.NamingRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.NamingRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopDiagnosticVerifier; public partial class SA1305CSharp10UnitTests : SA1305CSharp9UnitTests { + [Fact] + [WorkItem(3990, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3990")] + public async Task TestMixedDeconstructionHungarianNotationAsync() + { + var testCode = @"public class TestClass +{ + public void TestMethod() + { + int value = 1; + (value, int {|#0:iCount|}) = (2, 3); + } +}"; + + DiagnosticResult[] expected = + { + Diagnostic().WithLocation(0).WithArguments("variable", "iCount"), + }; + + await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1312CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1312CSharp10UnitTests.cs index 576d7565e..56efa6aa8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1312CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1312CSharp10UnitTests.cs @@ -3,9 +3,48 @@ namespace StyleCop.Analyzers.Test.CSharp10.NamingRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.NamingRules; + using StyleCop.Analyzers.Test.Helpers; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.NamingRules.SA1312VariableNamesMustBeginWithLowerCaseLetter, + StyleCop.Analyzers.NamingRules.RenameToLowerCaseCodeFixProvider>; public partial class SA1312CSharp10UnitTests : SA1312CSharp9UnitTests { + [Fact] + [WorkItem(3990, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3990")] + public async Task TestMixedDeconstructionAssignmentAsync() + { + var testCode = @"public class TestClass +{ + public void TestMethod() + { + int existing = 0; + (existing, int {|#0:NewValue|}) = (1, 2); + existing = existing + NewValue; + } +}"; + + var fixedCode = @"public class TestClass +{ + public void TestMethod() + { + int existing = 0; + (existing, int newValue) = (1, 2); + existing = existing + newValue; + } +}"; + + DiagnosticResult[] expected = + { + Diagnostic().WithArguments("NewValue").WithLocation(0), + }; + + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1316CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1316CSharp10UnitTests.cs index 87ce3e6f3..986394e8b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1316CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1316CSharp10UnitTests.cs @@ -3,9 +3,32 @@ namespace StyleCop.Analyzers.Test.CSharp10.NamingRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.NamingRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.NamingRules.SA1316TupleElementNamesShouldUseCorrectCasing, + StyleCop.Analyzers.NamingRules.SA1316CodeFixProvider>; public partial class SA1316CSharp10UnitTests : SA1316CSharp9UnitTests { + [Fact] + [WorkItem(3990, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3990")] + public async Task TestMixedDeconstructionIsIgnoredAsync() + { + var testCode = @"public class TestClass +{ + public void TestMethod() + { + var tuple = (ValueA: 1, ValueB: 2); + int existing = 0; + (existing, int ValueC) = tuple; + } +}"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1001CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1001CSharp10UnitTests.cs index 6d39da657..955c4a2ae 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1001CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1001CSharp10UnitTests.cs @@ -3,9 +3,47 @@ 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.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.SpacingRules.SA1001CommasMustBeSpacedCorrectly, + StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>; public partial class SA1001CSharp10UnitTests : SA1001CSharp9UnitTests { + [Fact] + [WorkItem(3990, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3990")] + public async Task TestMixedDeconstructionCommaSpacingAsync() + { + var testCode = @"public class TestClass +{ + public void TestMethod() + { + int value = 1; + (value {|#0:,|}int newValue) = (2, 3); + } +}"; + + var fixedCode = @"public class TestClass +{ + public void TestMethod() + { + int value = 1; + (value, int newValue) = (2, 3); + } +}"; + + DiagnosticResult[] expected = + { + Diagnostic().WithLocation(0).WithArguments(" not", "preceded"), + Diagnostic().WithLocation(0).WithArguments(string.Empty, "followed"), + }; + + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1008CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1008CSharp10UnitTests.cs index c4f64bf2d..d0dcf60d0 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1008CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1008CSharp10UnitTests.cs @@ -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() + { + ExpectedDiagnostics = + { + Diagnostic(DescriptorNotFollowed).WithLocation(0), + }, + TestCode = testCode, + FixedCode = fixedCode, + }.RunAsync(CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1009CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1009CSharp10UnitTests.cs index 978675123..0005b191b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1009CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1009CSharp10UnitTests.cs @@ -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() + { + ExpectedDiagnostics = + { + Diagnostic(DescriptorNotPreceded).WithLocation(0), + }, + TestCode = testCode, + FixedCode = fixedCode, + }.RunAsync(CancellationToken.None).ConfigureAwait(false); + } } }