-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility analyzer's UTs for C#12 syntax (#8135)
- Loading branch information
1 parent
6360ba4
commit 8520778
Showing
9 changed files
with
202 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...ests/SonarAnalyzer.UnitTest/TestCases/Utilities/CopyPasteTokenAnalyzer/Unique.CSharp12.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class PrimaryConstructor(string a = "a", char b = 'b', /* Comment */ double c = 1) | ||
{ | ||
void Method() | ||
{ | ||
var lambdaWithDefaultValues = (string x = "y", | ||
char y = 'z', // Comment | ||
double z = 1) => x; | ||
string[] collectionExpressionStr = ["Hello", | ||
"World"]; | ||
char[] collectionExpressionChar = ['a', | ||
'b']; | ||
double[] collectionExpressionDouble = [1, // Comment | ||
2]; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...zers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/MetricsAnalyzer/Metrics.CSharp12.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class PrimaryConstructor(bool condition /* comment */) | ||
{ | ||
bool Field = condition; | ||
|
||
int Method() | ||
{ | ||
if (condition) | ||
{ | ||
return 42; | ||
} | ||
return 0; | ||
} | ||
|
||
PrimaryConstructor(bool condition, int n) : this(condition) { } | ||
} |
26 changes: 26 additions & 0 deletions
26
.../SonarAnalyzer.UnitTest/TestCases/Utilities/SymbolReferenceAnalyzer/PrimaryConstructor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
static class A | ||
{ | ||
public const int I = 1; | ||
} | ||
|
||
class PrimaryConstructor(int a1 = A.I) { } | ||
|
||
class SubClass(int b1) : PrimaryConstructor(1) | ||
{ | ||
private int Field = b1; | ||
private int Property { get; set; } = b1; | ||
private int b1 = b1; | ||
|
||
int Method() => b1; | ||
} | ||
|
||
class B(int b1) | ||
{ | ||
private int Field = b1; | ||
private int Property { get; set; } = b1; | ||
public B(int b1, int b2) : this(b1) | ||
{ | ||
var f = (int i = A.I) => i; | ||
} | ||
int Method() => b1; | ||
} |
16 changes: 16 additions & 0 deletions
16
...ers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/TokenTypeAnalyzer/Tokens.CSharp12.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Point = (int, int); | ||
|
||
class PrimaryConstructor(System.String p1, string p2 = "default value that should be tokenized as string" /* a comment */, int p3 = 1) | ||
{ | ||
void Method() | ||
{ | ||
var lambdaWithDefaultValues = (string l1 = "default value that should be tokenized as string", int l2 = 2) => l1; | ||
var usingAliasDirective = new Point(0, 0); | ||
string[] collectionExpression = ["Hello", "World"]; | ||
} | ||
} | ||
|
||
class SubClass() : PrimaryConstructor("something") | ||
{ | ||
public SubClass(int p1) : this() { } | ||
} |