summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2017-06-08 22:00:58 +0000
committerPeter Wu <peter@lekensteyn.nl>2017-06-08 22:00:58 +0000
commit32dfbce6613679d1b1e01e92c67ad1d53ab59258 (patch)
treed4d8895e9330b72fd41fe901ceddd213d5815c1e /unittests
parent6b87ef832eba600ca72655f462b6e3d5088ec375 (diff)
[ASTMatchers] Add clang-query support for equals matcher
Summary: This allows the clang-query tool to use matchers like "integerLiteral(equals(32))". For this to work, an overloaded function is added for each possible parameter type. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D33094 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305022 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ASTMatchers/Dynamic/RegistryTest.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/Dynamic/RegistryTest.cpp b/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
index 6bbbc2bd35..84e31f721a 100644
--- a/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ b/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -511,6 +511,46 @@ TEST_F(RegistryTest, ParenExpr) {
EXPECT_FALSE(matches("int i = 1;", Value));
}
+TEST_F(RegistryTest, EqualsMatcher) {
+ Matcher<Stmt> BooleanStmt = constructMatcher(
+ "cxxBoolLiteral", constructMatcher("equals", VariantValue(true)))
+ .getTypedMatcher<Stmt>();
+ EXPECT_TRUE(matches("bool x = true;", BooleanStmt));
+ EXPECT_FALSE(matches("bool x = false;", BooleanStmt));
+ EXPECT_FALSE(matches("bool x = 0;", BooleanStmt));
+
+ BooleanStmt = constructMatcher(
+ "cxxBoolLiteral", constructMatcher("equals", VariantValue(0)))
+ .getTypedMatcher<Stmt>();
+ EXPECT_TRUE(matches("bool x = false;", BooleanStmt));
+ EXPECT_FALSE(matches("bool x = true;", BooleanStmt));
+ EXPECT_FALSE(matches("bool x = 0;", BooleanStmt));
+
+ Matcher<Stmt> DoubleStmt = constructMatcher(
+ "floatLiteral", constructMatcher("equals", VariantValue(1.2)))
+ .getTypedMatcher<Stmt>();
+ EXPECT_TRUE(matches("double x = 1.2;", DoubleStmt));
+ EXPECT_TRUE(matches("double x = 1.2f;", DoubleStmt));
+ EXPECT_TRUE(matches("double x = 1.2l;", DoubleStmt));
+ EXPECT_TRUE(matches("double x = 12e-1;", DoubleStmt));
+ EXPECT_FALSE(matches("double x = 1.23;", DoubleStmt));
+
+ Matcher<Stmt> IntegerStmt = constructMatcher(
+ "integerLiteral", constructMatcher("equals", VariantValue(42)))
+ .getTypedMatcher<Stmt>();
+ EXPECT_TRUE(matches("int x = 42;", IntegerStmt));
+ EXPECT_FALSE(matches("int x = 1;", IntegerStmt));
+
+ Matcher<Stmt> CharStmt = constructMatcher(
+ "characterLiteral", constructMatcher("equals", VariantValue('x')))
+ .getTypedMatcher<Stmt>();
+ EXPECT_TRUE(matches("int x = 'x';", CharStmt));
+ EXPECT_TRUE(matches("int x = L'x';", CharStmt));
+ EXPECT_TRUE(matches("int x = u'x';", CharStmt));
+ EXPECT_TRUE(matches("int x = U'x';", CharStmt));
+ EXPECT_FALSE(matches("int x = 120;", CharStmt));
+}
+
} // end anonymous namespace
} // end namespace dynamic
} // end namespace ast_matchers