aboutsummaryrefslogtreecommitdiff
path: root/unittests/ASTMatchers/ASTMatchersTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r--unittests/ASTMatchers/ASTMatchersTest.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index dc8b15fde1..8668b4970e 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -2854,6 +2854,34 @@ TEST(ForEachDescendant, BindsCorrectNodes) {
new VerifyIdIsBoundTo<FunctionDecl>("decl", 1)));
}
+TEST(FindAll, BindsNodeOnMatch) {
+ EXPECT_TRUE(matchAndVerifyResultTrue(
+ "class A {};",
+ recordDecl(hasName("::A"), findAll(recordDecl(hasName("::A")).bind("v"))),
+ new VerifyIdIsBoundTo<CXXRecordDecl>("v", 1)));
+}
+
+TEST(FindAll, BindsDescendantNodeOnMatch) {
+ EXPECT_TRUE(matchAndVerifyResultTrue(
+ "class A { int a; int b; };",
+ recordDecl(hasName("::A"), findAll(fieldDecl().bind("v"))),
+ new VerifyIdIsBoundTo<FieldDecl>("v", 2)));
+}
+
+TEST(FindAll, BindsNodeAndDescendantNodesOnOneMatch) {
+ EXPECT_TRUE(matchAndVerifyResultTrue(
+ "class A { int a; int b; };",
+ recordDecl(hasName("::A"),
+ findAll(decl(anyOf(recordDecl(hasName("::A")).bind("v"),
+ fieldDecl().bind("v"))))),
+ new VerifyIdIsBoundTo<Decl>("v", 3)));
+
+ EXPECT_TRUE(matchAndVerifyResultTrue(
+ "class A { class B {}; class C {}; };",
+ recordDecl(hasName("::A"), findAll(recordDecl(isDefinition()).bind("v"))),
+ new VerifyIdIsBoundTo<CXXRecordDecl>("v", 3)));
+}
+
TEST(EachOf, TriggersForEachMatch) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"class A { int a; int b; };",