[PATCH] D76366: [Syntax] Split syntax tests

2020-03-20 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 251571.
hlopko added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76366/new/

https://reviews.llvm.org/D76366

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

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -121,6 +121,16 @@
 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 @@
   std::unique_ptr Arena;
 };
 
-TEST_F(SyntaxTreeTest, Basic) {
-  std::pair 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 @@
   `-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 @@
 | |-{
 | `-}
 `-}
-)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 @@
 |   |-{
 |   `-}
 `-}
-)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 @@
 | | |-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 @@
   |   `-)
   `-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 @@
   }
 }
 )cpp",
-   R"txt(
+  R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -350,14 +401,17 @@
 |   | `-;
 |   `-}
 `-}
-)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 @@
 |   | `-;
 |   `-}
 `-}
-)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
-

[PATCH] D76366: [Syntax] Split syntax tests

2020-03-20 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe9630630ffa2: [Syntax] Split syntax tests (authored by 
hlopko, committed by gribozavr).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76366/new/

https://reviews.llvm.org/D76366

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

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -121,6 +121,16 @@
 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 @@
   std::unique_ptr Arena;
 };
 
-TEST_F(SyntaxTreeTest, Basic) {
-  std::pair 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 @@
   `-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 @@
 | |-{
 | `-}
 `-}
-)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 @@
 |   |-{
 |   `-}
 `-}
-)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 @@
 | | |-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 @@
   |   `-)
   `-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 @@
   }
 }
 )cpp",
-   R"txt(
+  R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -350,14 +401,17 @@
 |   | `-;
 |   `-}
 `-}
-)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 @@
 |   | `-;
 |   `-}
 `-}
-)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
-| 

[PATCH] D76366: [Syntax] Split syntax tests

2020-03-18 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76366/new/

https://reviews.llvm.org/D76366



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76366: [Syntax] Split syntax tests

2020-03-18 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 251102.
hlopko marked 5 inline comments as done.
hlopko added a comment.

Renaming some tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76366/new/

https://reviews.llvm.org/D76366

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

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -120,6 +120,16 @@
 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(),
@@ -163,14 +173,13 @@
   std::unique_ptr Arena;
 };
 
-TEST_F(SyntaxTreeTest, Basic) {
-  std::pair Cases[] = {
-  {
-  R"cpp(
+TEST_F(SyntaxTreeTest, Simple) {
+  expectTreeDumpEqual(
+  R"cpp(
 int main() {}
 void foo() {}
 )cpp",
-  R"txt(
+  R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-int
@@ -192,16 +201,18 @@
   `-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
@@ -241,14 +252,17 @@
 | |-{
 | `-}
 `-}
-)txt"},
-  // for.
-  {R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, For) {
+  expectTreeDumpEqual(
+  R"cpp(
 void test() {
   for (;;)  {}
 }
 )cpp",
-   R"txt(
+  R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -269,10 +283,18 @@
 |   |-{
 |   `-}
 `-}
-)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
@@ -288,13 +310,32 @@
 | | |-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
@@ -305,12 +346,22 @@
   |   `-)
   `-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:
@@ -318,7 +369,7 @@
   }
 }
 )cpp",
-   R"txt(
+  R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -349,14 +400,17 @@
 |   | `-;
 |   `-}
 `-}
-)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
@@ -383,77 +437,15 @@
 |   | `-;
 |   `-}
 `-}
-)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
-| | 

[PATCH] D76366: [Syntax] Split syntax tests

2020-03-18 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:642
+
+TEST_F(SyntaxTreeTest, UsingNamespaces) {
+  expectTreeDumpEqual(

"using directive"



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:664
+
+TEST_F(SyntaxTreeTest, UsingNamespaces2) {
+  expectTreeDumpEqual(

The construct in this test is called a "using declaration".



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1419
+
+TEST_F(SyntaxTreeTest, ExceptionSPecification) {
+  expectTreeDumpEqual(

SP -> Sp



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1648
+
+TEST_F(SyntaxTreeTest, Complex1) {
+  expectTreeDumpEqual(

"Complex declarator"?



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1684
+
+TEST_F(SyntaxTreeTest, Complex2) {
+  expectTreeDumpEqual(

"Complex declarator"?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76366/new/

https://reviews.llvm.org/D76366



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76366: [Syntax] Split syntax tests

2020-03-18 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko created this revision.
hlopko added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
hlopko added a parent revision: D76346: [Syntax] Build template declaration 
nodes.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76366

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

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -120,6 +120,16 @@
 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(),
@@ -163,14 +173,13 @@
   std::unique_ptr Arena;
 };
 
-TEST_F(SyntaxTreeTest, Basic) {
-  std::pair Cases[] = {
-  {
-  R"cpp(
+TEST_F(SyntaxTreeTest, Simple) {
+  expectTreeDumpEqual(
+  R"cpp(
 int main() {}
 void foo() {}
 )cpp",
-  R"txt(
+  R"txt(
 *: TranslationUnit
 |-SimpleDeclaration
 | |-int
@@ -192,16 +201,18 @@
   `-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
@@ -241,14 +252,17 @@
 | |-{
 | `-}
 `-}
-)txt"},
-  // for.
-  {R"cpp(
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, For) {
+  expectTreeDumpEqual(
+  R"cpp(
 void test() {
   for (;;)  {}
 }
 )cpp",
-   R"txt(
+  R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -269,10 +283,18 @@
 |   |-{
 |   `-}
 `-}
-)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
@@ -288,13 +310,32 @@
 | | |-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
@@ -305,12 +346,22 @@
   |   `-)
   `-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:
@@ -318,7 +369,7 @@
   }
 }
 )cpp",
-   R"txt(
+  R"txt(
 *: TranslationUnit
 `-SimpleDeclaration
   |-void
@@ -349,14 +400,17 @@
 |   | `-;
 |   `-}
 `-}
-)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
@@ -383,77 +437,15 @@
 |   | `-;
 |   `-}
 `-}
-)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
-  |