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

Split normalizer tests #66590

Merged
merged 3 commits into from
Feb 2, 2023
Merged
Changes from all 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
155 changes: 121 additions & 34 deletions src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ Test with line
}

[Fact]
public void TestNormalizeExpression1()
public void TestNormalizeDifferentExpressions()
{
TestNormalizeExpression("!a", "!a");
TestNormalizeExpression("-a", "-a");
Expand Down Expand Up @@ -415,12 +415,14 @@ private static void TestNormalizeExpression(string text, string expected)
}

[Fact]
public void TestNormalizeStatement1()
public void TestNormalizeExpressionStatement()
{
// expressions
TestNormalizeStatement("a;", "a;");
}

// blocks
[Fact]
public void TestNormalizeBlockStatements()
{
TestNormalizeStatement(
"{a;}", """
{
Expand All @@ -447,8 +449,11 @@ public void TestNormalizeStatement1()
b;
}
""");
}

// if
[Fact]
public void TestNormalizeIfStatements()
{
TestNormalizeStatement(
"if(a)b;", """
if (a)
Expand Down Expand Up @@ -483,8 +488,11 @@ public void TestNormalizeStatement1()
else if (c)
d;
""");
}

// while
[Fact]
public void TestNormalizeWhileStatements()
{
TestNormalizeStatement(
"while(a)b;", """
while (a)
Expand All @@ -497,8 +505,11 @@ public void TestNormalizeStatement1()
b;
}
""");
}

// do
[Fact]
public void TestNormalizeDoWhileStatement()
{
TestNormalizeStatement(
"do{a;}while(b);", """
do
Expand All @@ -507,8 +518,11 @@ public void TestNormalizeStatement1()
}
while (b);
""");
}

// for
[Fact]
public void TestNormalizeForStatements()
{
TestNormalizeStatement(
"for(a;b;c)d;", """
for (a; b; c)
Expand All @@ -519,15 +533,21 @@ public void TestNormalizeStatement1()
for (;;)
a;
""");
}

// foreach
[Fact]
public void TestNormalizeForeachStatement()
{
TestNormalizeStatement(
"foreach(a in b)c;", """
foreach (a in b)
c;
""");
}

// try
[Fact]
public void TestNormalizeTryStatements()
{
TestNormalizeStatement(
"try{a;}catch(b){c;}", """
try
Expand All @@ -550,8 +570,11 @@ public void TestNormalizeStatement1()
b;
}
""");
}

// other
[Fact]
public void TestNormalizeOtherStatements()
{
TestNormalizeStatement(
"lock(a)b;", """
lock (a)
Expand Down Expand Up @@ -588,15 +611,21 @@ public void TestNormalizeStatement1()
a;
}
""");
}

// declaration statements
[Fact]
public void TestNormalizeDeclarationStatements()
{
TestNormalizeStatement("a b;", "a b;");
TestNormalizeStatement("a?b;", "a? b;");
TestNormalizeStatement("a b,c;", "a b, c;");
TestNormalizeStatement("a b=c;", "a b = c;");
TestNormalizeStatement("a b=c,d=e;", "a b = c, d = e;");
}

// empty statements
[Fact]
public void TestNormalizeEmptyStatements()
{
TestNormalizeStatement(";", ";");
TestNormalizeStatement(
"{;;}", """
Expand All @@ -605,8 +634,11 @@ public void TestNormalizeStatement1()
;
}
""");
}

// labelled statements
[Fact]
public void TestNormalizeLabelStatements()
{
TestNormalizeStatement(
"goo:;", """
goo:
Expand All @@ -617,8 +649,11 @@ public void TestNormalizeStatement1()
goo:
a;
""");
}

// return/goto
[Fact]
public void TestNormalizeReturnAndGotoStatements()
{
TestNormalizeStatement("return;", "return;");
TestNormalizeStatement("return(a);", "return (a);");
TestNormalizeStatement("continue;", "continue;");
Expand All @@ -630,8 +665,11 @@ public void TestNormalizeStatement1()
TestNormalizeStatement("throw;", "throw;");
TestNormalizeStatement("throw a;", "throw a;");
TestNormalizeStatement("return this.Bar()", "return this.Bar()");
}

// switch
[Fact]
public void TestNormalizeSwitchStatements()
{
TestNormalizeStatement(
"switch(a){case b:c;}", """
switch (a)
Expand Down Expand Up @@ -695,8 +733,11 @@ public void TestNormalizeStatement1()
}
}
""");
}

// curlies
[Fact]
public void TestNormalizeStatements_Curlies()
{
TestNormalizeStatement(
"{if(goo){}if(bar){}}", """
{
Expand All @@ -710,7 +751,11 @@ public void TestNormalizeStatement1()
}
""");

// Queries
}

[Fact]
public void TestNormalizeStatements_Queries()
{
TestNormalizeStatement(
"int i=from v in vals select v;", """
int i =
Expand Down Expand Up @@ -740,8 +785,11 @@ group v by x into g
where g > 10
select g;
""");
}

// Generics
[Fact]
public void TestNormalizeStatements_Generics()
{
TestNormalizeStatement("Func<string, int> f = blah;", "Func<string, int> f = blah;");
}

Expand Down Expand Up @@ -887,9 +935,8 @@ private static void TestNormalizeStatement(string text, string expected)
}

[Fact]
public void TestNormalizeDeclaration1()
public void TestNormalizeUsingDeclarations()
{
// usings
TestNormalizeDeclaration("using a;", "using a;");
TestNormalizeDeclaration("using a=b;", "using a = b;");
TestNormalizeDeclaration("using a.b;", "using a.b;");
Expand Down Expand Up @@ -933,8 +980,11 @@ class C
{
}
""");
}

// namespace
[Fact]
public void TestNormalizeNamespaceDeclarations()
{
TestNormalizeDeclaration(
"namespace a{}", """
namespace a
Expand Down Expand Up @@ -974,8 +1024,11 @@ namespace b
{
}
""");
}

// type
[Fact]
public void TestNormalizeTypeDeclarations()
{
TestNormalizeDeclaration(
"class a{}", """
class a
Expand Down Expand Up @@ -1011,8 +1064,11 @@ class a : b
{
}
""");
}

// methods
[Fact]
public void TestNormalizeMethodDeclarations()
{
TestNormalizeDeclaration(
"class a{void b(){}}", """
class a
Expand Down Expand Up @@ -1053,8 +1109,11 @@ class a
}
}
""");
}

// operators
[Fact]
public void TestNormalizeOperatorDeclarations()
{
TestNormalizeDeclaration(
"class a{b operator checked-(c d){}}", """
class a
Expand Down Expand Up @@ -1147,8 +1206,11 @@ class a
}
}
""");
}

// properties
[Fact]
public void TestNormalizePropertyDeclarations()
{
TestNormalizeDeclaration(
"class a{b c{get;}}", """
class a
Expand Down Expand Up @@ -1537,8 +1599,11 @@ int p
}
}
""");
}

// properties with initializers
[Fact]
public void TestNormalizePropertyDeclarations_WithInitializers()
{
TestNormalizeDeclaration("""
class i4
{
Expand Down Expand Up @@ -1702,8 +1767,11 @@ int p
} = 1;
}
""");
}

// line breaks between property and other member
[Fact]
public void TestNormalizePropertyDeclarations_LineBreaksBetweenPropertyAndOtherMembers()
{
TestNormalizeDeclaration(
"class A{public string Prop{get;}public int f;}", """
class A
Expand Down Expand Up @@ -2414,8 +2482,11 @@ class A
public delegate int D();
}
""");
}

// indexers
[Fact]
public void TestNormalizeIndexerDeclarations()
{
TestNormalizeDeclaration(
"class a{b this[c d]{get;}}", """
class a
Expand Down Expand Up @@ -2636,8 +2707,11 @@ int this[b c]
}
}
""");
}

// events
[Fact]
public void TestNormalizeEventDeclarations()
{
TestNormalizeDeclaration("""
class a
{
Expand Down Expand Up @@ -2838,8 +2912,11 @@ class i
event w e { add; remove; }
}
""");
}

// fields
[Fact]
public void TestNormalizeFieldDeclarations()
{
TestNormalizeDeclaration(
"class a{b c;}", """
class a
Expand Down Expand Up @@ -2877,13 +2954,19 @@ class a
e f = g;
}
""");
}

// delegate
[Fact]
public void TestNormalizeDelegateDeclarations()
{
TestNormalizeDeclaration("delegate a b();", "delegate a b();");
TestNormalizeDeclaration("delegate a b(c);", "delegate a b(c);");
TestNormalizeDeclaration("delegate a b(c,d);", "delegate a b(c, d);");
}

// enums
[Fact]
public void TestNormalizeEnumDeclarations()
{
TestNormalizeDeclaration(
"enum a{}", """
enum a
Expand Down Expand Up @@ -2912,8 +2995,12 @@ enum a
b = c
}
""");
}

// attributes
[Fact]
public void TestNormalizeDeclarations_Attributes()
{
// declaration attributes
TestNormalizeDeclaration(
"[a]class b{}", """
[a]
Expand Down