diff --git a/analyzers/tests/SonarAnalyzer.TestFramework.Test/TestCases/Dummy.SecondaryLocation_CSharp10.razor b/analyzers/tests/SonarAnalyzer.TestFramework.Test/TestCases/Dummy.SecondaryLocation_CSharp10.razor new file mode 100644 index 00000000000..ffec581da31 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.TestFramework.Test/TestCases/Dummy.SecondaryLocation_CSharp10.razor @@ -0,0 +1,15 @@ + +

The solution to all problems is: @(RaiseHere(21))

+@* ^^^^^^^^^ *@ +@* ^^ Secondary@-1 *@ + +@code +{ + private int magicNumber = RaiseHere(42); +// ^^^^^^^^^ +// ^^ Secondary@-1 + private static int RaiseHere(int nb) + { + return nb; + } +} \ No newline at end of file diff --git a/analyzers/tests/SonarAnalyzer.TestFramework.Test/TestCases/DummyExpressions_CSharp10.razor b/analyzers/tests/SonarAnalyzer.TestFramework.Test/TestCases/DummyExpressions_CSharp10.razor new file mode 100644 index 00000000000..65c637639c2 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.TestFramework.Test/TestCases/DummyExpressions_CSharp10.razor @@ -0,0 +1,33 @@ +

Explicit expression: @(RaiseHere())

@* Noncompliant *@ +@* ^^^^^^^^^ *@ + +

Implicit expression: @RaiseHere()

@* Noncompliant *@ +@* ^^^^^^^^^ *@ + +

Multi-statement block: @{ var result = RaiseHere(); }

+@* ^^^^^^^^^ *@ + +

Control structures: @if(RaiseHere() == 42) { 42 }

+@* ^^^^^^^^^ *@ + +

Loops: @for(var i = 0; i < RaiseHere(); i++) { @i }

+@* ^^^^^^^^^ *@ + +

Code blocks: @{ RaiseHere(); }

+@* ^^^^^^^^^ *@ + +

Lambda expression: @((Func)(() => RaiseHere()))()

@* Noncompliant *@ +@* ^^^^^^^^^ *@ + +

Nested multi-statement block: @{ var result2 = RaiseHere(); var result3 = RaiseHere(); }

+@* ^^^^^^^^^ *@ +@* ^^^^^^^^^@-1 *@ + +

Nested control structures: @if(RaiseHere() == 42) { @(RaiseHere() + 1) }

+@* ^^^^^^^^^ *@ +@* ^^^^^^^^^@-1 *@ + +@code +{ + private static int RaiseHere() { return 42; } +} \ No newline at end of file diff --git a/analyzers/tests/SonarAnalyzer.TestFramework.Test/Verification/VerifierTest.cs b/analyzers/tests/SonarAnalyzer.TestFramework.Test/Verification/VerifierTest.cs index 4daeecaec7e..fabbad812c6 100644 --- a/analyzers/tests/SonarAnalyzer.TestFramework.Test/Verification/VerifierTest.cs +++ b/analyzers/tests/SonarAnalyzer.TestFramework.Test/Verification/VerifierTest.cs @@ -159,9 +159,23 @@ public class Sample [DataRow("Dummy.SecondaryLocation.cshtml")] public void Verify_RazorWithAdditionalLocation(string path) => DummyWithLocation.AddPaths(path) + .WithOptions(ParseOptionsHelper.BeforeCSharp10) .WithAdditionalFilePath(AnalysisScaffolding.CreateSonarProjectConfig(TestContext, ProjectType.Product)) .Verify(); +#if NET + + [DataTestMethod] + [DataRow("Dummy.SecondaryLocation_CSharp10.razor")] + [DataRow("Dummy.SecondaryLocation.cshtml")] + public void Verify_RazorWithAdditionalLocation_CSharp10(string path) => + DummyWithLocation.AddPaths(path) + .WithOptions(ParseOptionsHelper.FromCSharp10) + .WithAdditionalFilePath(AnalysisScaffolding.CreateSonarProjectConfig(TestContext, ProjectType.Product)) + .Verify(); + +#endif + [TestMethod] [DataRow("Dummy.razor")] [DataRow("Dummy.cshtml")] @@ -180,6 +194,20 @@ public class Sample .WithAdditionalFilePath(AnalysisScaffolding.CreateSonarProjectConfig(TestContext, ProjectType.Product)) .Verify(); +#if NET + + [TestMethod] + [DataRow("DummyExpressions_CSharp10.razor")] + [DataRow("DummyExpressions.cshtml")] + public void Verify_RazorExpressions_Locations_CSharp10(string path) => + DummyWithLocation + .AddPaths(path) + .WithOptions(ParseOptionsHelper.FromCSharp10) + .WithAdditionalFilePath(AnalysisScaffolding.CreateSonarProjectConfig(TestContext, ProjectType.Product)) + .Verify(); + +#endif + [DataTestMethod] [DataRow("Dummy.razor")] [DataRow("Dummy.cshtml")]