aboutsummaryrefslogtreecommitdiff
path: root/unittests/AST/ASTContextParentMapTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/AST/ASTContextParentMapTest.cpp')
-rw-r--r--unittests/AST/ASTContextParentMapTest.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/unittests/AST/ASTContextParentMapTest.cpp b/unittests/AST/ASTContextParentMapTest.cpp
index 0dcb175e07b3..b1d7db4164ef 100644
--- a/unittests/AST/ASTContextParentMapTest.cpp
+++ b/unittests/AST/ASTContextParentMapTest.cpp
@@ -27,8 +27,9 @@ using clang::tooling::FrontendActionFactory;
TEST(GetParents, ReturnsParentForDecl) {
MatchVerifier<Decl> Verifier;
- EXPECT_TRUE(Verifier.match("class C { void f(); };",
- methodDecl(hasParent(recordDecl(hasName("C"))))));
+ EXPECT_TRUE(
+ Verifier.match("class C { void f(); };",
+ cxxMethodDecl(hasParent(recordDecl(hasName("C"))))));
}
TEST(GetParents, ReturnsParentForStmt) {
@@ -37,24 +38,38 @@ TEST(GetParents, ReturnsParentForStmt) {
ifStmt(hasParent(compoundStmt()))));
}
+TEST(GetParents, ReturnsParentForTypeLoc) {
+ MatchVerifier<TypeLoc> Verifier;
+ EXPECT_TRUE(
+ Verifier.match("namespace a { class b {}; } void f(a::b) {}",
+ typeLoc(hasParent(typeLoc(hasParent(functionDecl()))))));
+}
+
+TEST(GetParents, ReturnsParentForNestedNameSpecifierLoc) {
+ MatchVerifier<NestedNameSpecifierLoc> Verifier;
+ EXPECT_TRUE(Verifier.match("namespace a { class b {}; } void f(a::b) {}",
+ nestedNameSpecifierLoc(hasParent(typeLoc()))));
+}
+
TEST(GetParents, ReturnsParentInsideTemplateInstantiations) {
MatchVerifier<Decl> DeclVerifier;
EXPECT_TRUE(DeclVerifier.match(
"template<typename T> struct C { void f() {} };"
"void g() { C<int> c; c.f(); }",
- methodDecl(hasName("f"),
- hasParent(recordDecl(isTemplateInstantiation())))));
+ cxxMethodDecl(hasName("f"),
+ hasParent(cxxRecordDecl(isTemplateInstantiation())))));
EXPECT_TRUE(DeclVerifier.match(
"template<typename T> struct C { void f() {} };"
"void g() { C<int> c; c.f(); }",
- methodDecl(hasName("f"),
- hasParent(recordDecl(unless(isTemplateInstantiation()))))));
+ cxxMethodDecl(hasName("f"),
+ hasParent(cxxRecordDecl(unless(isTemplateInstantiation()))))));
EXPECT_FALSE(DeclVerifier.match(
"template<typename T> struct C { void f() {} };"
"void g() { C<int> c; c.f(); }",
- methodDecl(hasName("f"),
- allOf(hasParent(recordDecl(unless(isTemplateInstantiation()))),
- hasParent(recordDecl(isTemplateInstantiation()))))));
+ cxxMethodDecl(
+ hasName("f"),
+ allOf(hasParent(cxxRecordDecl(unless(isTemplateInstantiation()))),
+ hasParent(cxxRecordDecl(isTemplateInstantiation()))))));
}
TEST(GetParents, ReturnsMultipleParentsInTemplateInstantiations) {
@@ -62,9 +77,9 @@ TEST(GetParents, ReturnsMultipleParentsInTemplateInstantiations) {
EXPECT_TRUE(TemplateVerifier.match(
"template<typename T> struct C { void f() {} };"
"void g() { C<int> c; c.f(); }",
- compoundStmt(
- allOf(hasAncestor(recordDecl(isTemplateInstantiation())),
- hasAncestor(recordDecl(unless(isTemplateInstantiation())))))));
+ compoundStmt(allOf(
+ hasAncestor(cxxRecordDecl(isTemplateInstantiation())),
+ hasAncestor(cxxRecordDecl(unless(isTemplateInstantiation())))))));
}
} // end namespace ast_matchers