diff options
author | Manuel Klimek <klimek@google.com> | 2012-12-06 14:42:48 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2012-12-06 14:42:48 +0000 |
commit | 30ace3715015b4a9bc5fa538a6515481abed40f9 (patch) | |
tree | 343538bc68410142c2bed681e6d88337908b7ec5 /unittests/ASTMatchers/ASTMatchersTest.cpp | |
parent | 6781415fa6d98aed548e84a70f1cd3ec31bba7d3 (diff) |
Implements multiple parents in the parent map.
Previously we would match the last visited parent, which in the
case of template instantiations was the last instantiated template.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169508 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 32b1496252..8beff0f98a 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -3044,6 +3044,42 @@ TEST(HasParent, MatchesOnlyParent) { compoundStmt(hasParent(ifStmt())))); } +TEST(HasAncestor, MatchesAllAncestors) { + EXPECT_TRUE(matches( + "template <typename T> struct C { static void f() { 42; } };" + "void t() { C<int>::f(); }", + integerLiteral( + equals(42), + allOf(hasAncestor(recordDecl(isTemplateInstantiation())), + hasAncestor(recordDecl(unless(isTemplateInstantiation()))))))); +} + +TEST(HasParent, MatchesAllParents) { + EXPECT_TRUE(matches( + "template <typename T> struct C { static void f() { 42; } };" + "void t() { C<int>::f(); }", + integerLiteral( + equals(42), + hasParent(compoundStmt(hasParent(functionDecl( + hasParent(recordDecl(isTemplateInstantiation()))))))))); + EXPECT_TRUE(matches( + "template <typename T> struct C { static void f() { 42; } };" + "void t() { C<int>::f(); }", + integerLiteral( + equals(42), + hasParent(compoundStmt(hasParent(functionDecl( + hasParent(recordDecl(unless(isTemplateInstantiation())))))))))); + EXPECT_TRUE(matches( + "template <typename T> struct C { static void f() { 42; } };" + "void t() { C<int>::f(); }", + integerLiteral(equals(42), + hasParent(compoundStmt(allOf( + hasParent(functionDecl( + hasParent(recordDecl(isTemplateInstantiation())))), + hasParent(functionDecl(hasParent(recordDecl( + unless(isTemplateInstantiation()))))))))))); +} + TEST(TypeMatching, MatchesTypes) { EXPECT_TRUE(matches("struct S {};", qualType().bind("loc"))); } |