diff options
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ASTMatchers/Dynamic/RegistryTest.cpp | 40 |
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 |