[clang] 1beb11c - [SyntaxTree] Use annotations in Statement tests
Eduardo Caldas via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 21 07:51:49 PDT 2020
Author: Eduardo Caldas
Date: 2020-08-21T14:42:33Z
New Revision: 1beb11c61ae4b0130cb87ed56b9e010ef6a06691
URL: https://github.com/llvm/llvm-project/commit/1beb11c61ae4b0130cb87ed56b9e010ef6a06691
DIFF: https://github.com/llvm/llvm-project/commit/1beb11c61ae4b0130cb87ed56b9e010ef6a06691.diff
LOG: [SyntaxTree] Use annotations in Statement tests
Differential Revision: https://reviews.llvm.org/D86345
Added:
Modified:
clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
Removed:
################################################################################
diff --git a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
index d4e2684934f3..994dd68028ea 100644
--- a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -102,282 +102,196 @@ void foo(int a, int b) {}
}
TEST_P(SyntaxTreeTest, If) {
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
-int main() {
- if (1) {}
- if (1) {} else if (0) {}
+void test() {
+ [[if (1) {}]]
+ [[if (1) {} else if (0) {}]]
}
)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-int
- |-SimpleDeclarator
- | |-main
- | `-ParametersAndQualifiers
- | |-(
- | `-)
+ {R"txt(
+IfStatement
+|-if
+|-(
+|-IntegerLiteralExpression
+| `-1
+|-)
+`-CompoundStatement
+ |-{
+ `-}
+ )txt",
+ R"txt(
+IfStatement
+|-if
+|-(
+|-IntegerLiteralExpression
+| `-1
+|-)
+|-CompoundStatement
+| |-{
+| `-}
+|-else
+`-IfStatement
+ |-if
+ |-(
+ |-IntegerLiteralExpression
+ | `-0
+ |-)
`-CompoundStatement
|-{
- |-IfStatement
- | |-if
- | |-(
- | |-IntegerLiteralExpression
- | | `-1
- | |-)
- | `-CompoundStatement
- | |-{
- | `-}
- |-IfStatement
- | |-if
- | |-(
- | |-IntegerLiteralExpression
- | | `-1
- | |-)
- | |-CompoundStatement
- | | |-{
- | | `-}
- | |-else
- | `-IfStatement
- | |-if
- | |-(
- | |-IntegerLiteralExpression
- | | `-0
- | |-)
- | `-CompoundStatement
- | |-{
- | `-}
`-}
-)txt"));
+)txt"}));
}
TEST_P(SyntaxTreeTest, For) {
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
void test() {
- for (;;) {}
+ [[for (;;) {}]]
}
)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-test
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-ForStatement
- | |-for
- | |-(
- | |-;
- | |-;
- | |-)
- | `-CompoundStatement
- | |-{
- | `-}
- `-}
-)txt"));
+ {R"txt(
+ForStatement
+|-for
+|-(
+|-;
+|-;
+|-)
+`-CompoundStatement
+ |-{
+ `-}
+)txt"}));
}
TEST_P(SyntaxTreeTest, RangeBasedFor) {
if (!GetParam().isCXX11OrLater()) {
return;
}
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
void test() {
int a[3];
- for (int x : a)
- ;
+ [[for (int x : a)
+ ;]]
}
)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-test
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-DeclarationStatement
- | |-SimpleDeclaration
- | | |-int
- | | `-SimpleDeclarator
- | | |-a
- | | `-ArraySubscript
- | | |-[
- | | |-IntegerLiteralExpression
- | | | `-3
- | | `-]
- | `-;
- |-RangeBasedForStatement
- | |-for
- | |-(
- | |-SimpleDeclaration
- | | |-int
- | | |-SimpleDeclarator
- | | | `-x
- | | `-:
- | |-IdExpression
- | | `-UnqualifiedId
- | | `-a
- | |-)
- | `-EmptyStatement
- | `-;
- `-}
-)txt"));
+ {R"txt(
+RangeBasedForStatement
+|-for
+|-(
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | `-x
+| `-:
+|-IdExpression
+| `-UnqualifiedId
+| `-a
+|-)
+`-EmptyStatement
+ `-;
+)txt"}));
}
TEST_P(SyntaxTreeTest, DeclarationStatement) {
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
void test() {
- int a = 10;
+ [[int a = 10;]]
}
)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-test
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-DeclarationStatement
- | |-SimpleDeclaration
- | | |-int
- | | `-SimpleDeclarator
- | | |-a
- | | |-=
- | | `-IntegerLiteralExpression
- | | `-10
- | `-;
- `-}
-)txt"));
+ {R"txt(
+DeclarationStatement
+|-SimpleDeclaration
+| |-int
+| `-SimpleDeclarator
+| |-a
+| |-=
+| `-IntegerLiteralExpression
+| `-10
+`-;
+)txt"}));
}
TEST_P(SyntaxTreeTest, Switch) {
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
void test() {
- switch (1) {
+ [[switch (1) {
case 0:
default:;
- }
+ }]]
}
)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-test
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-SwitchStatement
- | |-switch
- | |-(
- | |-IntegerLiteralExpression
- | | `-1
- | |-)
- | `-CompoundStatement
- | |-{
- | |-CaseStatement
- | | |-case
- | | |-IntegerLiteralExpression
- | | | `-0
- | | |-:
- | | `-DefaultStatement
- | | |-default
- | | |-:
- | | `-EmptyStatement
- | | `-;
- | `-}
- `-}
-)txt"));
+ {R"txt(
+SwitchStatement
+|-switch
+|-(
+|-IntegerLiteralExpression
+| `-1
+|-)
+`-CompoundStatement
+ |-{
+ |-CaseStatement
+ | |-case
+ | |-IntegerLiteralExpression
+ | | `-0
+ | |-:
+ | `-DefaultStatement
+ | |-default
+ | |-:
+ | `-EmptyStatement
+ | `-;
+ `-}
+)txt"}));
}
TEST_P(SyntaxTreeTest, While) {
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
void test() {
- while (1) { continue; break; }
+ [[while (1) { continue; break; }]]
}
)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-test
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-WhileStatement
- | |-while
- | |-(
- | |-IntegerLiteralExpression
- | | `-1
- | |-)
- | `-CompoundStatement
- | |-{
- | |-ContinueStatement
- | | |-continue
- | | `-;
- | |-BreakStatement
- | | |-break
- | | `-;
- | `-}
- `-}
-)txt"));
+ {R"txt(
+WhileStatement
+|-while
+|-(
+|-IntegerLiteralExpression
+| `-1
+|-)
+`-CompoundStatement
+ |-{
+ |-ContinueStatement
+ | |-continue
+ | `-;
+ |-BreakStatement
+ | |-break
+ | `-;
+ `-}
+)txt"}));
}
TEST_P(SyntaxTreeTest, UnhandledStatement) {
// Unhandled statements should end up as 'unknown statement'.
// This example uses a 'label statement', which does not yet have a syntax
// counterpart.
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
-int main() {
- foo: return 100;
+int test() {
+ [[foo: return 100;]]
}
)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-int
- |-SimpleDeclarator
- | |-main
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-UnknownStatement
- | |-foo
- | |-:
- | `-ReturnStatement
- | |-return
- | |-IntegerLiteralExpression
- | | `-100
- | `-;
- `-}
-)txt"));
+ {R"txt(
+UnknownStatement
+|-foo
+|-:
+`-ReturnStatement
+ |-return
+ |-IntegerLiteralExpression
+ | `-100
+ `-;
+)txt"}));
}
TEST_P(SyntaxTreeTest, Expressions) {
More information about the cfe-commits
mailing list