aboutsummaryrefslogtreecommitdiff
path: root/unittests/ASTMatchers/ASTMatchersTest.cpp
diff options
context:
space:
mode:
authorSam Panzer <espanz@gmail.com>2012-08-16 17:20:59 +0000
committerSam Panzer <espanz@gmail.com>2012-08-16 17:20:59 +0000
commit425f41b370a8795fbca9ffc3b35e9b0ccbb15d97 (patch)
tree620f7af001819b6f38bf8d95e79ffdedcb1d8520 /unittests/ASTMatchers/ASTMatchersTest.cpp
parentf64c11815e68f025737dc41d8d94e31e1426274d (diff)
Matchers related to DeclStmt for matching the count of declarations, a particular declaration within the statement, and single-Decl DeclStmts.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162027 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r--unittests/ASTMatchers/ASTMatchersTest.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index bf80ad4a64..adf0e9479f 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -2377,6 +2377,40 @@ TEST(UsingDeclaration, ThroughUsingDeclaration) {
declarationReference(throughUsingDecl(anything()))));
}
+TEST(SingleDecl, IsSingleDecl) {
+ StatementMatcher SingleDeclStmt =
+ declarationStatement(hasSingleDecl(variable(hasInitializer(anything()))));
+ EXPECT_TRUE(matches("void f() {int a = 4;}", SingleDeclStmt));
+ EXPECT_TRUE(notMatches("void f() {int a;}", SingleDeclStmt));
+ EXPECT_TRUE(notMatches("void f() {int a = 4, b = 3;}",
+ SingleDeclStmt));
+}
+
+TEST(DeclStmt, ContainsDeclaration) {
+ DeclarationMatcher MatchesInit = variable(hasInitializer(anything()));
+
+ EXPECT_TRUE(matches("void f() {int a = 4;}",
+ declarationStatement(containsDeclaration(0,
+ MatchesInit))));
+ EXPECT_TRUE(matches("void f() {int a = 4, b = 3;}",
+ declarationStatement(containsDeclaration(0, MatchesInit),
+ containsDeclaration(1,
+ MatchesInit))));
+ unsigned WrongIndex = 42;
+ EXPECT_TRUE(notMatches("void f() {int a = 4, b = 3;}",
+ declarationStatement(containsDeclaration(WrongIndex,
+ MatchesInit))));
+}
+
+TEST(DeclCount, DeclCountIsCorrect) {
+ EXPECT_TRUE(matches("void f() {int i,j;}",
+ declarationStatement(declCountIs(2))));
+ EXPECT_TRUE(notMatches("void f() {int i,j; int k;}",
+ declarationStatement(declCountIs(3))));
+ EXPECT_TRUE(notMatches("void f() {int i,j, k, l;}",
+ declarationStatement(declCountIs(3))));
+}
+
TEST(While, MatchesWhileLoops) {
EXPECT_TRUE(notMatches("void x() {}", whileStmt()));
EXPECT_TRUE(matches("void x() { while(true); }", whileStmt()));