Skip to content

Commit

Permalink
.NET 8 and C# 12: add repros and UTs for rules starting with S in Son…
Browse files Browse the repository at this point in the history
…arWay (#8126)
  • Loading branch information
antonioaversa authored Oct 5, 2023
1 parent f48c05b commit 40b2e83
Show file tree
Hide file tree
Showing 16 changed files with 497 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public void SelfAssignment_CSharp8() =>
public void SelfAssignment_CSharp10() =>
builderCS.AddPaths("SelfAssignment.CSharp10.cs").WithOptions(ParseOptionsHelper.FromCSharp10).WithTopLevelStatements().Verify();

[TestMethod]
public void SelfAssignment_CSharp12() =>
builderCS.AddPaths("SelfAssignment.CSharp12.cs").WithOptions(ParseOptionsHelper.FromCSharp12).Verify();

#endif

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public void SqlKeywordsDelimitedBySpace_CSharp11() =>
.WithOptions(ParseOptionsHelper.FromCSharp11)
.Verify();

[TestMethod]
public void SqlKeywordsDelimitedBySpace_CSharp12() =>
builder.AddPaths("SqlKeywordsDelimitedBySpace.CSharp12.cs")
.WithOptions(ParseOptionsHelper.FromCSharp12)
.WithConcurrentAnalysis(false)
.Verify();

#endif

[DataRow("System.Data")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,50 @@ public class StringFormatValidatorTest
[DataTestMethod]
[DataRow(ProjectType.Product)]
[DataRow(ProjectType.Test)]
public void StringFormatRuntimeExceptionFreeValidator(ProjectType projectType) =>
builder.AddPaths("StringFormatRuntimeExceptionFreeValidator.cs")
public void StringFormatValidator_RuntimeExceptionFree(ProjectType projectType) =>
builder.AddPaths("StringFormatValidator.RuntimeExceptionFree.cs")
.AddReferences(TestHelper.ProjectTypeReference(projectType))
.Verify();

[DataTestMethod]
[DataRow(ProjectType.Product)]
[DataRow(ProjectType.Test)]
public void StringFormatTypoFreeValidator(ProjectType projectType) =>
builder.AddPaths("StringFormatTypoFreeValidator.cs")
public void StringFormatValidator_TypoFree(ProjectType projectType) =>
builder.AddPaths("StringFormatValidator.TypoFree.cs")
.AddReferences(TestHelper.ProjectTypeReference(projectType))
.Verify();

[TestMethod]
public void StringFormatEdgeCasesValidator() =>
builder.AddPaths("StringFormatEdgeCasesValidator.cs").Verify();
public void StringFormatValidator_EdgeCases() =>
builder.AddPaths("StringFormatValidator.EdgeCases.cs").Verify();

#if NET

[DataTestMethod]
[DataRow(ProjectType.Product)]
[DataRow(ProjectType.Test)]
public void StringFormatRuntimeExceptionFreeValidator_CSharp11(ProjectType projectType) =>
builder.AddPaths("StringFormatRuntimeExceptionFreeValidator.CSharp11.cs")
public void StringFormatValidator_RuntimeExceptionFree_CSharp11(ProjectType projectType) =>
builder.AddPaths("StringFormatValidator.RuntimeExceptionFree.CSharp11.cs")
.AddReferences(TestHelper.ProjectTypeReference(projectType))
.WithOptions(ParseOptionsHelper.FromCSharp11)
.Verify();

[DataTestMethod]
[DataRow(ProjectType.Product)]
[DataRow(ProjectType.Test)]
public void StringFormatTypoFreeValidator_CSharp11(ProjectType projectType) =>
builder.AddPaths("StringFormatTypoFreeValidator.CSharp11.cs")
public void StringFormatValidator_TypoFree_CSharp11(ProjectType projectType) =>
builder.AddPaths("StringFormatValidator.TypoFree.CSharp11.cs")
.AddReferences(TestHelper.ProjectTypeReference(projectType))
.WithOptions(ParseOptionsHelper.FromCSharp11)
.Verify();

[TestMethod]
public void StringFormatValidator_CSharp12() =>
builder.AddPaths("StringFormatValidator.CSharp12.cs")
.AddReferences(TestHelper.ProjectTypeReference(ProjectType.Product))
.WithOptions(ParseOptionsHelper.FromCSharp12)
.Verify();

#endif

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class WithPrimaryConstructorParams(int unused, int usedInInlineInitialization, int usedInMethod)
{
int usedInInlineInitialization = usedInInlineInitialization; // Compliant: param to field assignment

WithPrimaryConstructorParams(int usedInMethod) : this(0, 0, usedInMethod)
{
this.usedInInlineInitialization = usedInInlineInitialization; // Compliant: field to field assignment
usedInMethod = usedInMethod; // Noncompliant: local to local assignment
// Secondary@-1
}

void AssigningParamToParam()
{
usedInMethod = usedInMethod; // Noncompliant: param to param assignment (promoted to unspeakable field behind the scenes)
// Secondary@-1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace SomeNamespace; // Required since use of default namespace results into FNs

class PrimaryConstructors
{
class C1(string sql = "SELECT x" + "FROM y"); // Noncompliant
struct S1(string sql = "SELECT x" + "FROM y"); // Noncompliant
record R1(string sql = "SELECT x" + "FROM y"); // Noncompliant
record struct RS1(string sql = "SELECT x" + "FROM y"); // Noncompliant
}

class DefaultLambdaParameters
{
void Test()
{
var f1 = (string s = "SELECT x" + "FROM y") => s; // Noncompliant
var f2 = (string s1 = "SELECT x", string s2 = "FROM y") => s1 + s2; // Compliant, different strings
}
}

class CollectionExpressions
{
void MonoDimensional()
{
IList<string> a;
a = ["SELECT x" + "FROM y"]; // Noncompliant
a = ["SELECT x" + """FROM y"""]; // Noncompliant
a = ["SELECT x", "FROM y"]; // Compliant, different strings
a = [$"SELECT x{"FROM y"}"]; // Noncompliant
a = [$$$""""SELECT x{{"FROM y"}}""""]; // Compliant
a = [$$""""SELECT x{{"FROM y"}}""""]; // Noncompliant
}

void MultiDimensional()
{
IList<IList<string>> a;
a = [
["SELECT x" + "FROM y", // Noncompliant
"SELECT x"],
["FROM y",
"SELECT x" + "FROM y"] // Noncompliant
];
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 40b2e83

Please sign in to comment.