Skip to content

Commit

Permalink
Fix Razor location UTs (#9242)
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianAmbrosini committed May 2, 2024
1 parent 24ec493 commit 7e0dada
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<p>The solution to all problems is: @(RaiseHere(21))</p>
@* ^^^^^^^^^ *@
@* ^^ Secondary@-1 *@

@code
{
private int magicNumber = RaiseHere(42);
// ^^^^^^^^^
// ^^ Secondary@-1
private static int RaiseHere(int nb)
{
return nb;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

<p>The solution to all problems is: @(RaiseHere())</p> @* Noncompliant, wrong location *@
@* ^^^^^^^^^ *@
<p>The solution to all problems is: @(RaiseHere())</p> @* Noncompliant *@

@code
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<p>Explicit expression: @(RaiseHere())</p> @* Noncompliant *@
@* ^^^^^^^^^ *@

<p>Implicit expression: @RaiseHere()</p> @* Noncompliant *@
@* ^^^^^^^^^ *@

<p>Multi-statement block: @{ var result = RaiseHere(); }</p>
@* ^^^^^^^^^ *@

<p>Control structures: @if(RaiseHere() == 42) { <text>42</text> }</p>
@* ^^^^^^^^^ *@

<p>Loops: @for(var i = 0; i < RaiseHere(); i++) { <text>@i</text> }</p>
@* ^^^^^^^^^ *@

<p>Code blocks: @{ RaiseHere(); }</p>
@* ^^^^^^^^^ *@

<p>Lambda expression: @((Func<int>)(() => RaiseHere()))()</p> @* Noncompliant *@
@* ^^^^^^^^^ *@

<p>Nested multi-statement block: @{ var result2 = RaiseHere(); var result3 = RaiseHere(); }</p>
@* ^^^^^^^^^ *@
@* ^^^^^^^^^@-1 *@

<p>Nested control structures: @if(RaiseHere() == 42) { <text>@(RaiseHere() + 1)</text> }</p>
@* ^^^^^^^^^ *@
@* ^^^^^^^^^@-1 *@

@code
{
private static int RaiseHere() { return 42; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@

@functions
{
private static int RaiseHere() => 42;
private static int RaiseHere() { return 42; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@

@code
{
private static int RaiseHere() => 42;
private static int RaiseHere() { return 42; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ 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();

[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();

Expand All @@ -176,6 +186,17 @@ public void Verify_Razor(string path) =>
public void Verify_RazorExpressions_Locations(string path) =>
DummyWithLocation
.AddPaths(path)
.WithOptions(ParseOptionsHelper.BeforeCSharp10)
.WithAdditionalFilePath(AnalysisScaffolding.CreateSonarProjectConfig(TestContext, ProjectType.Product))
.Verify();

[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();

Expand Down

0 comments on commit 7e0dada

Please sign in to comment.