diff options
author | Eduardo Caldas <ecaldas@google.com> | 2020-06-25 16:10:19 +0000 |
---|---|---|
committer | Eduardo Caldas <ecaldas@google.com> | 2020-06-25 17:05:08 +0000 |
commit | 221d7bbe49cceb0e408f0f46d9f8371e6c9fee2c (patch) | |
tree | c625bc28d029539426348f75c435b9bc0856b4ac /clang/unittests/Tooling/Syntax/TreeTest.cpp | |
parent | c4b1daed1d6adfa726682ab4576f0f4a07ccdeac (diff) | |
download | llvm-221d7bbe49cceb0e408f0f46d9f8371e6c9fee2c.zip llvm-221d7bbe49cceb0e408f0f46d9f8371e6c9fee2c.tar.gz llvm-221d7bbe49cceb0e408f0f46d9f8371e6c9fee2c.tar.bz2 |
Add `CharLiteral` to SyntaxTree
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82312
Diffstat (limited to 'clang/unittests/Tooling/Syntax/TreeTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/Syntax/TreeTest.cpp | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp index d32ce62..0a20950 100644 --- a/clang/unittests/Tooling/Syntax/TreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp @@ -73,6 +73,10 @@ struct TestClangConfig { return Language == Lang_C89 || Language == Lang_C99; } + bool isCXX17OrLater() const { + return Language == Lang_CXX17 || Language == Lang_CXX20; + } + bool supportsCXXDynamicExceptionSpecification() const { return Language == Lang_CXX03 || Language == Lang_CXX11 || Language == Lang_CXX14; @@ -1232,6 +1236,135 @@ void test() { )txt")); } +TEST_P(SyntaxTreeTest, CharacterLiteral) { + EXPECT_TRUE(treeDumpEqual( + R"cpp( +void test() { + 'a'; + '\n'; + '\x20'; + '\0'; + L'a'; + L'α'; +} +)cpp", + R"txt( +*: TranslationUnit +`-SimpleDeclaration + |-void + |-SimpleDeclarator + | |-test + | `-ParametersAndQualifiers + | |-( + | `-) + `-CompoundStatement + |-{ + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-'a' + | `-; + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-'\n' + | `-; + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-'\x20' + | `-; + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-'\0' + | `-; + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-L'a' + | `-; + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-L'α' + | `-; + `-} +)txt")); +} + +TEST_P(SyntaxTreeTest, CharacterLiteralUtf) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +void test() { + u'a'; + u'構'; + U'a'; + U'🌲'; +} +)cpp", + R"txt( +*: TranslationUnit +`-SimpleDeclaration + |-void + |-SimpleDeclarator + | |-test + | `-ParametersAndQualifiers + | |-( + | `-) + `-CompoundStatement + |-{ + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-u'a' + | `-; + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-u'構' + | `-; + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-U'a' + | `-; + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-U'🌲' + | `-; + `-} +)txt")); +} + +TEST_P(SyntaxTreeTest, CharacterLiteralUtf8) { + if (!GetParam().isCXX17OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +void test() { + u8'a'; + u8'\x7f'; +} +)cpp", + R"txt( +*: TranslationUnit +`-SimpleDeclaration + |-void + |-SimpleDeclarator + | |-test + | `-ParametersAndQualifiers + | |-( + | `-) + `-CompoundStatement + |-{ + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-u8'a' + | `-; + |-ExpressionStatement + | |-CharacterLiteralExpression + | | `-u8'\x7f' + | `-; + `-} +)txt")); +} + TEST_P(SyntaxTreeTest, BoolLiteral) { if (GetParam().hasBoolType()) { return; |