diff options
Diffstat (limited to 'clang/unittests/ASTMatchers/Dynamic')
| -rw-r--r-- | clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp | 9 | ||||
| -rw-r--r-- | clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp | 24 |
2 files changed, 33 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp index 9ccd3dc0413..d9b2d3c87f4 100644 --- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -256,6 +256,15 @@ TEST(ParserTest, Errors) { ParseMatcherWithError("hasBody(stmt())")); } +TEST(ParserTest, OverloadErrors) { + EXPECT_EQ("1:1: Error building matcher callee.\n" + "1:8: Candidate 1: Incorrect type for arg 1. " + "(Expected = Matcher<Stmt>) != (Actual = String)\n" + "1:8: Candidate 2: Incorrect type for arg 1. " + "(Expected = Matcher<Decl>) != (Actual = String)", + ParseWithError("callee(\"A\")")); +} + } // end anonymous namespace } // end namespace dynamic } // end namespace ast_matchers diff --git a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp index 178a64a9fbf..e69017e531d 100644 --- a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp +++ b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp @@ -124,6 +124,30 @@ TEST_F(RegistryTest, ConstructWithMatcherArgs) { EXPECT_FALSE(matches("void f(int x, int a);", HasParameter)); } +TEST_F(RegistryTest, OverloadedMatchers) { + Matcher<Stmt> CallExpr0 = constructMatcher( + "callExpr", + constructMatcher("callee", constructMatcher("memberExpr", + constructMatcher("isArrow")))) + .getTypedMatcher<Stmt>(); + + Matcher<Stmt> CallExpr1 = constructMatcher( + "callExpr", + constructMatcher( + "callee", + constructMatcher("methodDecl", + constructMatcher("hasName", std::string("x"))))) + .getTypedMatcher<Stmt>(); + + std::string Code = "class Y { public: void x(); }; void z() { Y y; y.x(); }"; + EXPECT_FALSE(matches(Code, CallExpr0)); + EXPECT_TRUE(matches(Code, CallExpr1)); + + Code = "class Z { public: void z() { this->z(); } };"; + EXPECT_TRUE(matches(Code, CallExpr0)); + EXPECT_FALSE(matches(Code, CallExpr1)); +} + TEST_F(RegistryTest, PolymorphicMatchers) { const MatcherList IsDefinition = constructMatcher("isDefinition"); Matcher<Decl> Var = |

