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 @@ -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()
Copy link
Copy Markdown
Contributor

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?

{
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),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Expand Up @@ -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<StyleCop.Analyzers.NamingRules.SA1305FieldNamesMustNotUseHungarianNotation>;

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
}
}
}
Loading