[clang] e963063 - [Syntax] Split syntax tests

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 20 01:56:19 PDT 2020


Author: Marcel Hlopko
Date: 2020-03-20T09:53:43+01:00
New Revision: e9630630ffa2a69bf3eabe154a3846deab694fa0

URL: https://github.com/llvm/llvm-project/commit/e9630630ffa2a69bf3eabe154a3846deab694fa0
DIFF: https://github.com/llvm/llvm-project/commit/e9630630ffa2a69bf3eabe154a3846deab694fa0.diff

LOG: [Syntax] Split syntax tests

Summary:
This patch split Basic test into multple individual tests to allow simpler
filtering and clearer signal into what's broken when it's broken.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76366

Added: 
    

Modified: 
    clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index cfed1eefbfe3..17b1f2274537 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -121,6 +121,16 @@ class SyntaxTreeTest : public ::testing::Test {
     return Root;
   }
 
+  void expectTreeDumpEqual(StringRef code, StringRef tree) {
+    SCOPED_TRACE(code);
+
+    auto *Root = buildTree(code);
+    std::string Expected = tree.trim().str();
+    std::string Actual =
+        std::string(llvm::StringRef(Root->dump(*Arena)).trim());
+    EXPECT_EQ(Expected, Actual) << "the resulting dump is:\n" << Actual;
+  }
+
   // Adds a file to the test VFS.
   void addFile(llvm::StringRef Path, llvm::StringRef Contents) {
     if (!FS->addFile(Path, time_t(),
@@ -164,14 +174,13 @@ class SyntaxTreeTest : public ::testing::Test {
   std::unique_ptr<syntax::Arena> Arena;
 };
 
-TEST_F(SyntaxTreeTest, Basic) {
-  std::pair</*Input*/ std::string, /*Expected*/ std::string> Cases[] = {
-      {
-          R"cpp(
+TEST_F(SyntaxTreeTest, Simple) {
+  expectTreeDumpEqual(
+      R"cpp(
 int main() {}
 void foo() {}
     )cpp",
-          R"txt(
+      R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-int
@@ -193,16 +202,18 @@ void foo() {}
   `-CompoundStatement
     |-{
     `-}
-)txt"},
-      // if.
-      {
-          R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, If) {
+  expectTreeDumpEqual(
+      R"cpp(
 int main() {
   if (true) {}
   if (true) {} else if (false) {}
 }
         )cpp",
-          R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-int
@@ -242,14 +253,17 @@ int main() {
     |     |-{
     |     `-}
     `-}
-        )txt"},
-      // for.
-      {R"cpp(
+        )txt");
+}
+
+TEST_F(SyntaxTreeTest, For) {
+  expectTreeDumpEqual(
+      R"cpp(
 void test() {
   for (;;)  {}
 }
 )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -270,10 +284,18 @@ void test() {
     |   |-{
     |   `-}
     `-}
-        )txt"},
-      // declaration statement.
-      {"void test() { int a = 10; }",
-       R"txt(
+        )txt");
+}
+
+TEST_F(SyntaxTreeTest, RangeBasedFor) {
+  expectTreeDumpEqual(
+      R"cpp(
+void test() {
+  int a[3];
+  for (int x : a) ;
+}
+      )cpp",
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -289,13 +311,32 @@ void test() {
     | | |-int
     | | `-SimpleDeclarator
     | |   |-a
-    | |   |-=
-    | |   `-UnknownExpression
-    | |     `-10
+    | |   `-ArraySubscript
+    | |     |-[
+    | |     |-UnknownExpression
+    | |     | `-3
+    | |     `-]
     | `-;
+    |-RangeBasedForStatement
+    | |-for
+    | |-(
+    | |-SimpleDeclaration
+    | | |-int
+    | | |-SimpleDeclarator
+    | | | `-x
+    | | `-:
+    | |-UnknownExpression
+    | | `-a
+    | |-)
+    | `-EmptyStatement
+    |   `-;
     `-}
-)txt"},
-      {"void test() { ; }", R"txt(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, DeclarationStatement) {
+  expectTreeDumpEqual("void test() { int a = 10; }",
+                      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -306,12 +347,22 @@ void test() {
   |   `-)
   `-CompoundStatement
     |-{
-    |-EmptyStatement
+    |-DeclarationStatement
+    | |-SimpleDeclaration
+    | | |-int
+    | | `-SimpleDeclarator
+    | |   |-a
+    | |   |-=
+    | |   `-UnknownExpression
+    | |     `-10
     | `-;
     `-}
-)txt"},
-      // switch, case and default.
-      {R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, Switch) {
+  expectTreeDumpEqual(
+      R"cpp(
 void test() {
   switch (true) {
     case 0:
@@ -319,7 +370,7 @@ void test() {
   }
 }
 )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -350,14 +401,17 @@ void test() {
     |   |     `-;
     |   `-}
     `-}
-)txt"},
-      // while.
-      {R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, While) {
+  expectTreeDumpEqual(
+      R"cpp(
 void test() {
   while (true) { continue; break; }
 }
 )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -384,77 +438,15 @@ void test() {
     |   | `-;
     |   `-}
     `-}
-)txt"},
-      // return.
-      {R"cpp(
-int test() { return 1; }
-      )cpp",
-       R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
-  |-int
-  |-SimpleDeclarator
-  | |-test
-  | `-ParametersAndQualifiers
-  |   |-(
-  |   `-)
-  `-CompoundStatement
-    |-{
-    |-ReturnStatement
-    | |-return
-    | |-UnknownExpression
-    | | `-1
-    | `-;
-    `-}
-)txt"},
-      // Range-based for.
-      {R"cpp(
-void test() {
-  int a[3];
-  for (int x : a) ;
+)txt");
 }
-      )cpp",
-       R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
-  |-void
-  |-SimpleDeclarator
-  | |-test
-  | `-ParametersAndQualifiers
-  |   |-(
-  |   `-)
-  `-CompoundStatement
-    |-{
-    |-DeclarationStatement
-    | |-SimpleDeclaration
-    | | |-int
-    | | `-SimpleDeclarator
-    | |   |-a
-    | |   `-ArraySubscript
-    | |     |-[
-    | |     |-UnknownExpression
-    | |     | `-3
-    | |     `-]
-    | `-;
-    |-RangeBasedForStatement
-    | |-for
-    | |-(
-    | |-SimpleDeclaration
-    | | |-int
-    | | |-SimpleDeclarator
-    | | | `-x
-    | | `-:
-    | |-UnknownExpression
-    | | `-a
-    | |-)
-    | `-EmptyStatement
-    |   `-;
-    `-}
-       )txt"},
-      // Unhandled statements should end up as 'unknown statement'.
-      // This example uses a 'label statement', which does not yet have a syntax
-      // counterpart.
-      {"void main() { foo: return 100; }", R"txt(
+
+TEST_F(SyntaxTreeTest, UnhandledStatement) {
+  // Unhandled statements should end up as 'unknown statement'.
+  // This example uses a 'label statement', which does not yet have a syntax
+  // counterpart.
+  expectTreeDumpEqual("void main() { foo: return 100; }",
+                      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -474,16 +466,20 @@ void test() {
     |   | `-100
     |   `-;
     `-}
-)txt"},
-      // expressions should be wrapped in 'ExpressionStatement' when they appear
-      // in a statement position.
-      {R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, Expressions) {
+  // expressions should be wrapped in 'ExpressionStatement' when they appear
+  // in a statement position.
+  expectTreeDumpEqual(
+      R"cpp(
 void test() {
   test();
   if (true) test(); else test();
 }
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -520,12 +516,15 @@ void test() {
     |   | `-)
     |   `-;
     `-}
-)txt"},
-      // Multiple declarators group into a single SimpleDeclaration.
-      {R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
+  expectTreeDumpEqual(
+      R"cpp(
       int *a, b;
   )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-int
@@ -536,11 +535,12 @@ void test() {
   |-SimpleDeclarator
   | `-b
   `-;
-  )txt"},
-      {R"cpp(
+  )txt");
+  expectTreeDumpEqual(
+      R"cpp(
     typedef int *a, b;
   )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-typedef
@@ -552,15 +552,18 @@ void test() {
   |-SimpleDeclarator
   | `-b
   `-;
-  )txt"},
-      // Multiple declarators inside a statement.
-      {R"cpp(
+  )txt");
+}
+
+TEST_F(SyntaxTreeTest, MultipleDeclaratorsInsideStatement) {
+  expectTreeDumpEqual(
+      R"cpp(
 void foo() {
       int *a, b;
       typedef int *ta, tb;
 }
   )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -593,15 +596,19 @@ void foo() {
     | |   `-tb
     | `-;
     `-}
-  )txt"},
-      {R"cpp(
+  )txt");
+}
+
+TEST_F(SyntaxTreeTest, Namespaces) {
+  expectTreeDumpEqual(
+      R"cpp(
 namespace a { namespace b {} }
 namespace a::b {}
 namespace {}
 
 namespace foo = a;
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-NamespaceDefinition
 | |-namespace
@@ -630,9 +637,62 @@ namespace foo = a;
   |-=
   |-a
   `-;
-)txt"},
-      // Free-standing classes, must live inside a SimpleDeclaration.
-      {R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, UsingDirective) {
+  expectTreeDumpEqual(
+      R"cpp(
+namespace ns {}
+using namespace ::ns;
+    )cpp",
+      R"txt(
+*: TranslationUnit
+|-NamespaceDefinition
+| |-namespace
+| |-ns
+| |-{
+| `-}
+`-UsingNamespaceDirective
+  |-using
+  |-namespace
+  |-::
+  |-ns
+  `-;
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, UsingDeclaration) {
+  expectTreeDumpEqual(
+      R"cpp(
+namespace ns { int a; }
+using ns::a;
+    )cpp",
+      R"txt(
+*: TranslationUnit
+|-NamespaceDefinition
+| |-namespace
+| |-ns
+| |-{
+| |-SimpleDeclaration
+| | |-int
+| | |-SimpleDeclarator
+| | | `-a
+| | `-;
+| `-}
+`-UsingDeclaration
+  |-using
+  |-ns
+  |-::
+  |-a
+  `-;
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, FreeStandingClasses) {
+  // Free-standing classes, must live inside a SimpleDeclaration.
+  expectTreeDumpEqual(
+      R"cpp(
 sturct X;
 struct X {};
 
@@ -641,7 +701,7 @@ struct Y {} *y2;
 
 struct {} *a1;
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-sturct
@@ -677,13 +737,17 @@ struct {} *a1;
   | |-*
   | `-a1
   `-;
-)txt"},
-      {R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, Templates) {
+  expectTreeDumpEqual(
+      R"cpp(
 template <class T> struct cls {};
 template <class T> int var = 10;
 template <class T> int fun() {}
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-TemplateDeclaration
 | |-template
@@ -730,15 +794,19 @@ template <class T> int fun() {}
     `-CompoundStatement
       |-{
       `-}
-)txt"},
-      {R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, NestedTemplates) {
+  expectTreeDumpEqual(
+      R"cpp(
 template <class T>
 struct X {
   template <class U>
   U foo();
 };
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-TemplateDeclaration
   |-template
@@ -768,85 +836,16 @@ struct X {
     |   `-;
     |-}
     `-;
-)txt"},
-      {R"cpp(
-template <class T> struct X {};
-template <class T> struct X<T*> {};
-template <> struct X<int> {};
+)txt");
+}
 
-template struct X<double>;
-extern template struct X<float>;
-)cpp",
-       R"txt(
-*: TranslationUnit
-|-TemplateDeclaration
-| |-template
-| |-<
-| |-UnknownDeclaration
-| | |-class
-| | `-T
-| |->
-| `-SimpleDeclaration
-|   |-struct
-|   |-X
-|   |-{
-|   |-}
-|   `-;
-|-TemplateDeclaration
-| |-template
-| |-<
-| |-UnknownDeclaration
-| | |-class
-| | `-T
-| |->
-| `-SimpleDeclaration
-|   |-struct
-|   |-X
-|   |-<
-|   |-T
-|   |-*
-|   |->
-|   |-{
-|   |-}
-|   `-;
-|-TemplateDeclaration
-| |-template
-| |-<
-| |->
-| `-SimpleDeclaration
-|   |-struct
-|   |-X
-|   |-<
-|   |-int
-|   |->
-|   |-{
-|   |-}
-|   `-;
-|-ExplicitTemplateInstantiation
-| |-template
-| `-SimpleDeclaration
-|   |-struct
-|   |-X
-|   |-<
-|   |-double
-|   |->
-|   `-;
-`-ExplicitTemplateInstantiation
-  |-extern
-  |-template
-  `-SimpleDeclaration
-    |-struct
-    |-X
-    |-<
-    |-float
-    |->
-    `-;
-)txt"},
-      {R"cpp(
+TEST_F(SyntaxTreeTest, Templates2) {
+  expectTreeDumpEqual(
+      R"cpp(
 template <class T> struct X { struct Y; };
 template <class T> struct X<T>::Y {};
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-TemplateDeclaration
 | |-template
@@ -883,55 +882,18 @@ template <class T> struct X<T>::Y {};
     |-{
     |-}
     `-;
-       )txt"},
-      {R"cpp(
-namespace ns {}
-using namespace ::ns;
-    )cpp",
-       R"txt(
-*: TranslationUnit
-|-NamespaceDefinition
-| |-namespace
-| |-ns
-| |-{
-| `-}
-`-UsingNamespaceDirective
-  |-using
-  |-namespace
-  |-::
-  |-ns
-  `-;
-       )txt"},
-      {R"cpp(
-namespace ns { int a; }
-using ns::a;
-    )cpp",
-       R"txt(
-*: TranslationUnit
-|-NamespaceDefinition
-| |-namespace
-| |-ns
-| |-{
-| |-SimpleDeclaration
-| | |-int
-| | |-SimpleDeclarator
-| | | `-a
-| | `-;
-| `-}
-`-UsingDeclaration
-  |-using
-  |-ns
-  |-::
-  |-a
-  `-;
-       )txt"},
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, TemplatesUsingUsing) {
+  expectTreeDumpEqual(
+      R"cpp(
 template <class T> struct X {
   using T::foo;
   using typename T::bar;
 };
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-TemplateDeclaration
   |-template
@@ -959,11 +921,92 @@ template <class T> struct X {
     | `-;
     |-}
     `-;
-       )txt"},
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, ExplicitTemplateInstantations) {
+  expectTreeDumpEqual(
+      R"cpp(
+template <class T> struct X {};
+template <class T> struct X<T*> {};
+template <> struct X<int> {};
+
+template struct X<double>;
+extern template struct X<float>;
+)cpp",
+      R"txt(
+*: TranslationUnit
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-{
+|   |-}
+|   `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-class
+| | `-T
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-<
+|   |-T
+|   |-*
+|   |->
+|   |-{
+|   |-}
+|   `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |->
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-<
+|   |-int
+|   |->
+|   |-{
+|   |-}
+|   `-;
+|-ExplicitTemplateInstantiation
+| |-template
+| `-SimpleDeclaration
+|   |-struct
+|   |-X
+|   |-<
+|   |-double
+|   |->
+|   `-;
+`-ExplicitTemplateInstantiation
+  |-extern
+  |-template
+  `-SimpleDeclaration
+    |-struct
+    |-X
+    |-<
+    |-float
+    |->
+    `-;
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, UsingType) {
+  expectTreeDumpEqual(
+      R"cpp(
 using type = int;
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-TypeAliasDeclaration
   |-using
@@ -971,20 +1014,28 @@ using type = int;
   |-=
   |-int
   `-;
-       )txt"},
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, EmptyDeclaration) {
+  expectTreeDumpEqual(
+      R"cpp(
 ;
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-EmptyDeclaration
   `-;
-       )txt"},
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, StaticAssert) {
+  expectTreeDumpEqual(
+      R"cpp(
 static_assert(true, "message");
 static_assert(true);
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-StaticAssertDeclaration
 | |-static_assert
@@ -1003,12 +1054,16 @@ static_assert(true);
   | `-true
   |-)
   `-;
-       )txt"},
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, ExternC) {
+  expectTreeDumpEqual(
+      R"cpp(
 extern "C" int a;
 extern "C" { int b; int c; }
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-LinkageSpecificationDeclaration
 | |-extern
@@ -1033,15 +1088,19 @@ extern "C" { int b; int c; }
   | | `-c
   | `-;
   `-}
-       )txt"},
-      // Some nodes are non-modifiable, they are marked with 'I:'.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, NonModifiableNodes) {
+  // Some nodes are non-modifiable, they are marked with 'I:'.
+  expectTreeDumpEqual(
+      R"cpp(
 #define HALF_IF if (1+
 #define HALF_IF_2 1) {}
 void test() {
   HALF_IF HALF_IF_2 else {}
 })cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -1068,9 +1127,10 @@ void test() {
     |   |-{
     |   `-}
     `-}
-       )txt"},
-      // All nodes can be mutated.
-      {R"cpp(
+       )txt");
+  // All nodes can be mutated.
+  expectTreeDumpEqual(
+      R"cpp(
 #define OPEN {
 #define CLOSE }
 
@@ -1084,7 +1144,7 @@ void test() {
   }
 }
 )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -1110,15 +1170,18 @@ void test() {
     | | `-;
     | `-}
     `-}
-       )txt"},
-      // Array subscripts in declarators.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, ArraySubscriptsInDeclarators) {
+  expectTreeDumpEqual(
+      R"cpp(
 int a[10];
 int b[1][2][3];
 int c[] = {1,2,3};
 void f(int xs[static 10]);
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-int
@@ -1185,9 +1248,12 @@ void f(int xs[static 10]);
   |   |     `-]
   |   `-)
   `-;
-       )txt"},
-      // Parameter lists in declarators.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, ParameterListsInDeclarators) {
+  expectTreeDumpEqual(
+      R"cpp(
 int a() const;
 int b() volatile;
 int c() &;
@@ -1202,7 +1268,7 @@ int foo(
   int&& f
 );
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-int
@@ -1301,14 +1367,17 @@ int foo(
   |   |   `-f
   |   `-)
   `-;
-       )txt"},
-      // Trailing const qualifier.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, TrailingConst) {
+  expectTreeDumpEqual(
+      R"cpp(
 struct X {
   int foo() const;
 }
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-struct
@@ -1324,12 +1393,15 @@ struct X {
   | |   `-const
   | `-;
   `-}
-    )txt"},
-      // Trailing return type in parameter lists.
-      {R"cpp(
+    )txt");
+}
+
+TEST_F(SyntaxTreeTest, TrailingReturn) {
+  expectTreeDumpEqual(
+      R"cpp(
 auto foo() -> int;
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-auto
@@ -1342,14 +1414,17 @@ auto foo() -> int;
   |     |-->
   |     `-int
   `-;
-       )txt"},
-      // Exception specification in parameter lists.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, ExceptionSpecification) {
+  expectTreeDumpEqual(
+      R"cpp(
 int a() noexcept;
 int b() noexcept(true);
 int c() throw();
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-int
@@ -1384,15 +1459,18 @@ int c() throw();
   |   |-(
   |   `-)
   `-;
-       )txt"},
-      // Declarators in parentheses.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, DeclaratorsInParentheses) {
+  expectTreeDumpEqual(
+      R"cpp(
 int (a);
 int *(b);
 int (*c)(int);
 int *(d)(int);
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-int
@@ -1439,15 +1517,18 @@ int *(d)(int);
   |   | `-int
   |   `-)
   `-;
-       )txt"},
-      // CV qualifiers.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, ConstVolatileQualifiers) {
+  expectTreeDumpEqual(
+      R"cpp(
 const int west = -1;
 int const east = 1;
 const int const universal = 0;
 const int const *const *volatile b;
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-const
@@ -1489,12 +1570,15 @@ const int const *const *volatile b;
   | |-volatile
   | `-b
   `-;
-       )txt"},
-      // Ranges of declarators with trailing return types.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, RangesOfDeclaratorsWithTrailingReturnTypes) {
+  expectTreeDumpEqual(
+      R"cpp(
 auto foo() -> auto(*)(int) -> double*;
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-auto
@@ -1522,14 +1606,17 @@ auto foo() -> auto(*)(int) -> double*;
   |           `-SimpleDeclarator
   |             `-*
   `-;
-       )txt"},
-      // Member pointers.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, MemberPointers) {
+  expectTreeDumpEqual(
+      R"cpp(
 struct X {};
 int X::* a;
 const int X::* b;
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-struct
@@ -1556,12 +1643,15 @@ const int X::* b;
   | | `-*
   | `-b
   `-;
-       )txt"},
-      // All-in-one tests.
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, ComplexDeclarator) {
+  expectTreeDumpEqual(
+      R"cpp(
 void x(char a, short (*b)(int));
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -1589,11 +1679,15 @@ void x(char a, short (*b)(int));
   |   |     `-)
   |   `-)
   `-;
-       )txt"},
-      {R"cpp(
+       )txt");
+}
+
+TEST_F(SyntaxTreeTest, ComplexDeclarator2) {
+  expectTreeDumpEqual(
+      R"cpp(
 void x(char a, short (*b)(int), long (**c)(long long));
     )cpp",
-       R"txt(
+      R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -1637,18 +1731,7 @@ void x(char a, short (*b)(int), long (**c)(long long));
   |   |     `-)
   |   `-)
   `-;
-       )txt"},
-  };
-
-  for (const auto &T : Cases) {
-    SCOPED_TRACE(T.first);
-
-    auto *Root = buildTree(T.first);
-    std::string Expected = llvm::StringRef(T.second).trim().str();
-    std::string Actual =
-        std::string(llvm::StringRef(Root->dump(*Arena)).trim());
-    EXPECT_EQ(Expected, Actual) << "the resulting dump is:\n" << Actual;
-  }
+       )txt");
 }
 
 TEST_F(SyntaxTreeTest, Mutations) {


        


More information about the cfe-commits mailing list