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

Fix Razor location UTs #9242

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Copy link
Contributor

Choose a reason for hiding this comment

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

The file should be called Dummy.SecondaryLocation.CSharp10.razor to follow our naming scheme.

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
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; }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to DummyExpressions.CSharp10.razor

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

Choose a reason for hiding this comment

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

Is this required to not fail in the pipeline?

Copy link
Contributor Author

@CristianAmbrosini CristianAmbrosini May 2, 2024

Choose a reason for hiding this comment

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

Actually, all razor tests are already within a #if NET directive, so we can remove them


[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")]
Expand All @@ -176,9 +190,24 @@ public class Sample
public void Verify_RazorExpressions_Locations(string path) =>
DummyWithLocation
.AddPaths(path)
.WithOptions(ParseOptionsHelper.BeforeCSharp10)
.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")]
Expand Down
Loading