eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85713
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
@@ -168,6 +168,35 @@
return ::testing::AssertionSuccess();
}
+ ::testing::AssertionResult
+ treeDumpEqualOnAnnotations(StringRef CodeWithAnnotations,
+ ArrayRef<StringRef> TreeDumps) {
+ SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " "));
+
+ auto AnnotatedCode = llvm::Annotations(CodeWithAnnotations);
+ auto *Root = buildTree(AnnotatedCode.code(), GetParam());
+
+ if (Diags->getClient()->getNumErrors() != 0) {
+ return ::testing::AssertionFailure()
+ << "Source file has syntax errors, they were printed to the test "
+ "log";
+ }
+
+ auto AnnotatedRanges = AnnotatedCode.ranges();
+ assert(AnnotatedRanges.size() == TreeDumps.size());
+ for (auto i = 0u; i < AnnotatedRanges.size(); i++) {
+ auto *AnnotatedNode = nodeByRange(AnnotatedRanges[i], Root);
+ assert(AnnotatedNode);
+ auto AnnotatedNodeDump =
+ std::string(StringRef(AnnotatedNode->dump(*Arena)).trim());
+ // EXPECT_EQ shows the diff between the two strings if they are different.
+ EXPECT_EQ(TreeDumps[i].trim().str(), AnnotatedNodeDump);
+ if (AnnotatedNodeDump != TreeDumps[i].trim().str())
+ return ::testing::AssertionFailure();
+ }
+ return ::testing::AssertionSuccess();
+ }
+
// Adds a file to the test VFS.
void addFile(StringRef Path, StringRef Contents) {
if (!FS->addFile(Path, time_t(),
@@ -214,34 +243,23 @@
};
TEST_P(SyntaxTreeTest, Simple) {
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
int main() {}
-void foo() {}
+[[void foo() {}]]
)cpp",
- R"txt(
-*: TranslationUnit
-|-SimpleDeclaration
-| |-int
-| |-SimpleDeclarator
-| | |-main
-| | `-ParametersAndQualifiers
-| | |-(
-| | `-)
-| `-CompoundStatement
-| |-{
-| `-}
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-foo
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- `-}
-)txt"));
+ {R"txt(
+SimpleDeclaration
+|-void
+|-SimpleDeclarator
+| |-foo
+| `-ParametersAndQualifiers
+| |-(
+| `-)
+`-CompoundStatement
+ |-{
+ `-}
+)txt"}));
}
TEST_P(SyntaxTreeTest, SimpleVariable) {
@@ -871,7 +889,7 @@
if (!GetParam().isCXX()) {
return;
}
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
namespace n {
struct S {
@@ -889,194 +907,71 @@
};
};
void test() {
- :: // global-namespace-specifier
- n:: // namespace-specifier
- S:: // type-name-specifier
- template ST<int>:: // type-template-instantiation-specifier
- f();
-
- n:: // namespace-specifier
- S:: // type-name-specifier
- ST<int>:: // type-template-instantiation-specifier
- f();
-
- ST<int>:: // type-name-specifier
- S:: // type-name-specifier
- f<int>();
-
- ST<int>:: // type-name-specifier
- S:: // type-name-specifier
- template f<int>();
+[[::n::S::template ST<int>::]]f();
+
+[[n::S::ST<int>::]]f();
+
+[[ST<int>::S::]]f<int>();
+
+[[ST<int>::S::]]template f<int>();
}
)cpp",
- R"txt(
-*: TranslationUnit
-|-NamespaceDefinition
-| |-namespace
-| |-n
-| |-{
-| |-SimpleDeclaration
-| | |-struct
-| | |-S
-| | |-{
-| | |-TemplateDeclaration
-| | | |-template
-| | | |-<
-| | | |-UnknownDeclaration
-| | | | |-typename
-| | | | `-T
-| | | |->
-| | | `-SimpleDeclaration
-| | | |-struct
-| | | |-ST
-| | | |-{
-| | | |-SimpleDeclaration
-| | | | |-static
-| | | | |-void
-| | | | |-SimpleDeclarator
-| | | | | |-f
-| | | | | `-ParametersAndQualifiers
-| | | | | |-(
-| | | | | `-)
-| | | | `-;
-| | | |-}
-| | | `-;
-| | |-}
-| | `-;
-| `-}
-|-TemplateDeclaration
+ {R"txt(
+NestedNameSpecifier
+|-::
+|-IdentifierNameSpecifier
+| `-n
+|-::
+|-IdentifierNameSpecifier
+| `-S
+|-::
+|-SimpleTemplateNameSpecifier
| |-template
+| |-ST
| |-<
-| |-UnknownDeclaration
-| | |-typename
-| | `-T
-| |->
-| `-SimpleDeclaration
-| |-struct
-| |-ST
-| |-{
-| |-SimpleDeclaration
-| | |-struct
-| | |-S
-| | |-{
-| | |-TemplateDeclaration
-| | | |-template
-| | | |-<
-| | | |-UnknownDeclaration
-| | | | |-typename
-| | | | `-U
-| | | |->
-| | | `-SimpleDeclaration
-| | | |-static
-| | | |-U
-| | | |-SimpleDeclarator
-| | | | |-f
-| | | | `-ParametersAndQualifiers
-| | | | |-(
-| | | | `-)
-| | | `-;
-| | |-}
-| | `-;
-| |-}
-| `-;
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-test
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-ExpressionStatement
- | |-UnknownExpression
- | | |-IdExpression
- | | | |-NestedNameSpecifier
- | | | | |-::
- | | | | |-IdentifierNameSpecifier
- | | | | | `-n
- | | | | |-::
- | | | | |-IdentifierNameSpecifier
- | | | | | `-S
- | | | | |-::
- | | | | |-SimpleTemplateNameSpecifier
- | | | | | |-template
- | | | | | |-ST
- | | | | | |-<
- | | | | | |-int
- | | | | | `->
- | | | | `-::
- | | | `-UnqualifiedId
- | | | `-f
- | | |-(
- | | `-)
- | `-;
- |-ExpressionStatement
- | |-UnknownExpression
- | | |-IdExpression
- | | | |-NestedNameSpecifier
- | | | | |-IdentifierNameSpecifier
- | | | | | `-n
- | | | | |-::
- | | | | |-IdentifierNameSpecifier
- | | | | | `-S
- | | | | |-::
- | | | | |-SimpleTemplateNameSpecifier
- | | | | | |-ST
- | | | | | |-<
- | | | | | |-int
- | | | | | `->
- | | | | `-::
- | | | `-UnqualifiedId
- | | | `-f
- | | |-(
- | | `-)
- | `-;
- |-ExpressionStatement
- | |-UnknownExpression
- | | |-IdExpression
- | | | |-NestedNameSpecifier
- | | | | |-SimpleTemplateNameSpecifier
- | | | | | |-ST
- | | | | | |-<
- | | | | | |-int
- | | | | | `->
- | | | | |-::
- | | | | |-IdentifierNameSpecifier
- | | | | | `-S
- | | | | `-::
- | | | `-UnqualifiedId
- | | | |-f
- | | | |-<
- | | | |-int
- | | | `->
- | | |-(
- | | `-)
- | `-;
- |-ExpressionStatement
- | |-UnknownExpression
- | | |-IdExpression
- | | | |-NestedNameSpecifier
- | | | | |-SimpleTemplateNameSpecifier
- | | | | | |-ST
- | | | | | |-<
- | | | | | |-int
- | | | | | `->
- | | | | |-::
- | | | | |-IdentifierNameSpecifier
- | | | | | `-S
- | | | | `-::
- | | | |-template
- | | | `-UnqualifiedId
- | | | |-f
- | | | |-<
- | | | |-int
- | | | `->
- | | |-(
- | | `-)
- | `-;
- `-}
-)txt"));
+| |-int
+| `->
+`-::
+)txt",
+ R"txt(
+NestedNameSpecifier
+|-IdentifierNameSpecifier
+| `-n
+|-::
+|-IdentifierNameSpecifier
+| `-S
+|-::
+|-SimpleTemplateNameSpecifier
+| |-ST
+| |-<
+| |-int
+| `->
+`-::
+)txt",
+ R"txt(
+NestedNameSpecifier
+|-SimpleTemplateNameSpecifier
+| |-ST
+| |-<
+| |-int
+| `->
+|-::
+|-IdentifierNameSpecifier
+| `-S
+`-::
+)txt",
+ R"txt(
+NestedNameSpecifier
+|-SimpleTemplateNameSpecifier
+| |-ST
+| |-<
+| |-int
+| `->
+|-::
+|-IdentifierNameSpecifier
+| `-S
+`-::
+)txt"}));
}
TEST_P(SyntaxTreeTest, QualifiedIdWithDependentType) {
@@ -1476,34 +1371,21 @@
if (!GetParam().isCXX11OrLater()) {
return;
}
- EXPECT_TRUE(treeDumpEqual(
+ EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
void test() {
- 12ll;
- 12ull;
+ [[12ll]];
+ [[12ull]];
}
)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-test
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12ll
- | `-;
- |-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12ull
- | `-;
- `-}
-)txt"));
+ {R"txt(
+IntegerLiteralExpression
+`-12ll
+)txt",
+ R"txt(
+IntegerLiteralExpression
+`-12ull
+)txt"}));
}
TEST_P(SyntaxTreeTest, IntegerLiteralBinary) {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits