From d040ff365ee31f024da96db65e96fd8f5e1e5e20 Mon Sep 17 00:00:00 2001 From: DoctorKrolic <70431552+DoctorKrolic@users.noreply.github.com> Date: Fri, 3 Feb 2023 00:49:44 +0300 Subject: [PATCH] Split normalizer tests (#66590) --- .../Syntax/Syntax/SyntaxNormalizerTests.cs | 155 ++++++++++++++---- 1 file changed, 121 insertions(+), 34 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs index 5f89b3c97f47b..4689a85e75e00 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs @@ -345,7 +345,7 @@ Test with line } [Fact] - public void TestNormalizeExpression1() + public void TestNormalizeDifferentExpressions() { TestNormalizeExpression("!a", "!a"); TestNormalizeExpression("-a", "-a"); @@ -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;}", """ { @@ -447,8 +449,11 @@ public void TestNormalizeStatement1() b; } """); + } - // if + [Fact] + public void TestNormalizeIfStatements() + { TestNormalizeStatement( "if(a)b;", """ if (a) @@ -483,8 +488,11 @@ public void TestNormalizeStatement1() else if (c) d; """); + } - // while + [Fact] + public void TestNormalizeWhileStatements() + { TestNormalizeStatement( "while(a)b;", """ while (a) @@ -497,8 +505,11 @@ public void TestNormalizeStatement1() b; } """); + } - // do + [Fact] + public void TestNormalizeDoWhileStatement() + { TestNormalizeStatement( "do{a;}while(b);", """ do @@ -507,8 +518,11 @@ public void TestNormalizeStatement1() } while (b); """); + } - // for + [Fact] + public void TestNormalizeForStatements() + { TestNormalizeStatement( "for(a;b;c)d;", """ for (a; b; c) @@ -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 @@ -550,8 +570,11 @@ public void TestNormalizeStatement1() b; } """); + } - // other + [Fact] + public void TestNormalizeOtherStatements() + { TestNormalizeStatement( "lock(a)b;", """ lock (a) @@ -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( "{;;}", """ @@ -605,8 +634,11 @@ public void TestNormalizeStatement1() ; } """); + } - // labelled statements + [Fact] + public void TestNormalizeLabelStatements() + { TestNormalizeStatement( "goo:;", """ goo: @@ -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;"); @@ -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) @@ -695,8 +733,11 @@ public void TestNormalizeStatement1() } } """); + } - // curlies + [Fact] + public void TestNormalizeStatements_Curlies() + { TestNormalizeStatement( "{if(goo){}if(bar){}}", """ { @@ -710,7 +751,11 @@ public void TestNormalizeStatement1() } """); - // Queries + } + + [Fact] + public void TestNormalizeStatements_Queries() + { TestNormalizeStatement( "int i=from v in vals select v;", """ int i = @@ -740,8 +785,11 @@ group v by x into g where g > 10 select g; """); + } - // Generics + [Fact] + public void TestNormalizeStatements_Generics() + { TestNormalizeStatement("Func f = blah;", "Func f = blah;"); } @@ -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;"); @@ -933,8 +980,11 @@ class C { } """); + } - // namespace + [Fact] + public void TestNormalizeNamespaceDeclarations() + { TestNormalizeDeclaration( "namespace a{}", """ namespace a @@ -974,8 +1024,11 @@ namespace b { } """); + } - // type + [Fact] + public void TestNormalizeTypeDeclarations() + { TestNormalizeDeclaration( "class a{}", """ class a @@ -1011,8 +1064,11 @@ class a : b { } """); + } - // methods + [Fact] + public void TestNormalizeMethodDeclarations() + { TestNormalizeDeclaration( "class a{void b(){}}", """ class a @@ -1053,8 +1109,11 @@ class a } } """); + } - // operators + [Fact] + public void TestNormalizeOperatorDeclarations() + { TestNormalizeDeclaration( "class a{b operator checked-(c d){}}", """ class a @@ -1147,8 +1206,11 @@ class a } } """); + } - // properties + [Fact] + public void TestNormalizePropertyDeclarations() + { TestNormalizeDeclaration( "class a{b c{get;}}", """ class a @@ -1537,8 +1599,11 @@ int p } } """); + } - // properties with initializers + [Fact] + public void TestNormalizePropertyDeclarations_WithInitializers() + { TestNormalizeDeclaration(""" class i4 { @@ -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 @@ -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 @@ -2636,8 +2707,11 @@ int this[b c] } } """); + } - // events + [Fact] + public void TestNormalizeEventDeclarations() + { TestNormalizeDeclaration(""" class a { @@ -2838,8 +2912,11 @@ class i event w e { add; remove; } } """); + } - // fields + [Fact] + public void TestNormalizeFieldDeclarations() + { TestNormalizeDeclaration( "class a{b c;}", """ class a @@ -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 @@ -2912,8 +2995,12 @@ enum a b = c } """); + } - // attributes + [Fact] + public void TestNormalizeDeclarations_Attributes() + { + // declaration attributes TestNormalizeDeclaration( "[a]class b{}", """ [a]