Skip to content
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

Add c# 12 test project #3734

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -3,9 +3,58 @@

namespace StyleCop.Analyzers.Test.CSharp12.ReadabilityRules
{
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp11.ReadabilityRules;

using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.ReadabilityRules.SA1130UseLambdaSyntax,
StyleCop.Analyzers.ReadabilityRules.SA1130CodeFixProvider>;

public partial class SA1130CSharp12UnitTests : SA1130CSharp11UnitTests
{
protected override DiagnosticResult[] GetExpectedResultCodeFixSpecialCases()
{
return new[]
{
Diagnostic().WithLocation(8, 20),
Diagnostic().WithLocation(9, 20),
Diagnostic().WithLocation(10, 25),
Diagnostic().WithLocation(11, 30),
Diagnostic().WithLocation(12, 30),
DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42),
DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47),
};
}

protected override DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases()
{
return new DiagnosticResult[]
{
Diagnostic().WithLocation(12, 30),
DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42),
DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47),
};
}

protected override DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions()
{
return new[]
{
Diagnostic().WithSpan(4, 50, 4, 58),
DiagnosticResult.CompilerError("CS1660").WithLocation(4, 50),
};
}
}
}
Expand Up @@ -3,9 +3,19 @@

namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
{
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;

public partial class SA1015CSharp12UnitTests : SA1015CSharp11UnitTests
{
protected override DiagnosticResult[] GetExpectedResultMissingToken()
{
return new[]
{
DiagnosticResult.CompilerError("CS1003").WithLocation(7, 35).WithArguments(","),
DiagnosticResult.CompilerError("CS1003").WithLocation(7, 36).WithArguments(">"),
DiagnosticResult.CompilerError("CS1026").WithLocation(7, 36),
};
}
}
}
Expand Up @@ -3,9 +3,21 @@

namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
{
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;

public partial class SA1018CSharp12UnitTests : SA1018CSharp11UnitTests
{
protected override DiagnosticResult[] GetExpectedResultSyntaxErrorAtEndOfFile()
{
return new[]
{
DiagnosticResult.CompilerError("CS1031").WithLocation(10, 2),
DiagnosticResult.CompilerError("CS8803").WithLocation(11, 1),
DiagnosticResult.CompilerError("CS8805").WithLocation(11, 1),
DiagnosticResult.CompilerError("CS1001").WithLocation(11, 2),
DiagnosticResult.CompilerError("CS1002").WithLocation(11, 2),
};
}
}
}
Expand Up @@ -218,33 +218,10 @@ private void Method(object o)
Action<int> h = delegate (int x, __arglist) { Console.WriteLine(); };
}
}";
var expected = new[]
{
Diagnostic().WithLocation(8, 20),
Diagnostic().WithLocation(9, 20),
Diagnostic().WithLocation(10, 25),
Diagnostic().WithLocation(11, 30),
Diagnostic().WithLocation(12, 30),
Diagnostic(CS1065).WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
Diagnostic(CS7014).WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
Diagnostic(CS1670).WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
Diagnostic(CS1669).WithLocation(15, 42),
};

var expectedAfterFix = new[]
{
Diagnostic().WithLocation(12, 30),
Diagnostic(CS1065).WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
Diagnostic(CS7014).WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
Diagnostic(CS1670).WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
Diagnostic(CS1669).WithLocation(15, 42),
};
var expected = this.GetExpectedResultCodeFixSpecialCases();

var expectedAfterFix = this.GetExpectedResultAfterFixCodeFixSpecialCases();

var test = new CSharpTest
{
Expand Down Expand Up @@ -828,11 +805,7 @@ public class TestClass
}
";

DiagnosticResult[] expected =
{
Diagnostic().WithSpan(4, 50, 4, 58),
DiagnosticResult.CompilerError("CS1660").WithMessage("Cannot convert anonymous method to type 'EventHandler[]' because it is not a delegate type").WithSpan(4, 50, 4, 62),
};
var expected = this.GetExpectedResultVerifyInvalidCodeConstructions();

var test = new CSharpTest
{
Expand Down Expand Up @@ -1010,5 +983,48 @@ public void Test()

await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

protected virtual DiagnosticResult[] GetExpectedResultCodeFixSpecialCases()
{
return new[]
{
Diagnostic().WithLocation(8, 20),
Diagnostic().WithLocation(9, 20),
Diagnostic().WithLocation(10, 25),
Diagnostic().WithLocation(11, 30),
Diagnostic().WithLocation(12, 30),
Diagnostic(CS1065).WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
Diagnostic(CS7014).WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
Diagnostic(CS1670).WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
Diagnostic(CS1669).WithLocation(15, 42),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Let's move all the Diagnostic() items back into the test itself, and only have the CS* diagnostics in this virtual method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I thought of that too briefly, but ended up not doing it. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added them as annotations in the tested code instead. This removed the need for two methods before and after the fix. Ok simplification?

};
}

protected virtual DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases()
{
return new[]
{
Diagnostic().WithLocation(12, 30),
Diagnostic(CS1065).WithLocation(12, 53),
Diagnostic().WithLocation(13, 30),
Diagnostic(CS7014).WithLocation(13, 47),
Diagnostic().WithLocation(14, 30),
Diagnostic(CS1670).WithLocation(14, 47),
Diagnostic().WithLocation(15, 25),
Diagnostic(CS1669).WithLocation(15, 42),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Same applies for Diagnostic() here

};
}

protected virtual DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions()
{
return new[]
{
Diagnostic().WithSpan(4, 50, 4, 58),
DiagnosticResult.CompilerError("CS1660").WithMessage("Cannot convert anonymous method to type 'EventHandler[]' because it is not a delegate type").WithSpan(4, 50, 4, 62),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the only thing differing was the span, so I simplified to only check the start location. Ok simplification?

};
}
}
}
Expand Up @@ -376,10 +376,7 @@ void Method()
}
";

DiagnosticResult[] expected =
{
DiagnosticResult.CompilerError("CS1003").WithMessage("Syntax error, '>' expected").WithLocation(7, 35),
};
var expected = this.GetExpectedResultMissingToken();

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}
Expand Down Expand Up @@ -432,5 +429,13 @@ public void TestMethod2(object input)

await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

protected virtual DiagnosticResult[] GetExpectedResultMissingToken()
{
return new[]
{
DiagnosticResult.CompilerError("CS1003").WithMessage("Syntax error, '>' expected").WithLocation(7, 35),
};
}
}
}
Expand Up @@ -129,12 +129,17 @@ private void Test()
?
";

DiagnosticResult[] expected =
var expected = this.GetExpectedResultSyntaxErrorAtEndOfFile();

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

protected virtual DiagnosticResult[] GetExpectedResultSyntaxErrorAtEndOfFile()
{
return new[]
{
DiagnosticResult.CompilerError("CS1031").WithMessage("Type expected").WithLocation(10, 2),
};

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}
}
}