diff options
author | Daniel Jasper <djasper@google.com> | 2012-10-22 16:26:51 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-10-22 16:26:51 +0000 |
commit | c99a3ad8c2bf29da45a0c64b88d58bfbd2f78ef2 (patch) | |
tree | 46666ad15f3d32214b14a00619023b24cb63ad6e /unittests/ASTMatchers/ASTMatchersTest.cpp | |
parent | 03e6fda61f48a6f11fb3c9459d5ac3d5b1db2809 (diff) |
Implement hasParent()-matcher.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166421 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 9676fde96b..5c97f3abac 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -2884,6 +2884,18 @@ TEST(HasAncestor, MatchesInImplicitCode) { hasAncestor(recordDecl(hasName("A"))))))))); } +TEST(HasParent, MatchesOnlyParent) { + EXPECT_TRUE(matches( + "void f() { if (true) { int x = 42; } }", + compoundStmt(hasParent(ifStmt())))); + EXPECT_TRUE(notMatches( + "void f() { for (;;) { int x = 42; } }", + compoundStmt(hasParent(ifStmt())))); + EXPECT_TRUE(notMatches( + "void f() { if (true) for (;;) { int x = 42; } }", + compoundStmt(hasParent(ifStmt())))); +} + TEST(TypeMatching, MatchesTypes) { EXPECT_TRUE(matches("struct S {};", qualType().bind("loc"))); } |