diff options
Diffstat (limited to 'clang/unittests/ASTMatchers/Dynamic')
-rw-r--r-- | clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp | 45 |
2 files changed, 47 insertions, 2 deletions
diff --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp index 71b0f87e027..9116ab8a9f3 100644 --- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -137,9 +137,9 @@ bool matchesRange(const SourceRange &Range, unsigned StartLine, Range.Start.Column == StartColumn && Range.End.Column == EndColumn; } -const DynTypedMatcher *getSingleMatcher(const VariantValue &value) { +const DynTypedMatcher *getSingleMatcher(const VariantValue &Value) { const DynTypedMatcher *Out; - EXPECT_TRUE(value.getMatcher().getSingleMatcher(Out)); + EXPECT_TRUE(Value.getMatcher().getSingleMatcher(Out)); return Out; } diff --git a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp index 55490a5bab9..874a4f35a0b 100644 --- a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp +++ b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp @@ -261,6 +261,33 @@ TEST_F(RegistryTest, Adaptative) { EXPECT_FALSE(matches("void foo() { if (true) return; }", S)); } +TEST_F(RegistryTest, VariadicOp) { + Matcher<Decl> D = constructMatcher( + "anyOf", constructMatcher("recordDecl"), + constructMatcher("namedDecl", + constructMatcher("hasName", std::string("foo")))) + .getTypedMatcher<Decl>(); + + EXPECT_TRUE(matches("void foo(){}", D)); + EXPECT_TRUE(matches("struct Foo{};", D)); + EXPECT_FALSE(matches("int i = 0;", D)); + + D = constructMatcher( + "allOf", constructMatcher("recordDecl"), + constructMatcher( + "namedDecl", + constructMatcher("anyOf", + constructMatcher("hasName", std::string("Foo")), + constructMatcher("hasName", std::string("Bar"))))) + .getTypedMatcher<Decl>(); + + EXPECT_FALSE(matches("void foo(){}", D)); + EXPECT_TRUE(matches("struct Foo{};", D)); + EXPECT_FALSE(matches("int i = 0;", D)); + EXPECT_TRUE(matches("class Bar{};", D)); + EXPECT_FALSE(matches("class OtherBar{};", D)); +} + TEST_F(RegistryTest, Errors) { // Incorrect argument count. OwningPtr<Diagnostics> Error(new Diagnostics()); @@ -285,6 +312,24 @@ TEST_F(RegistryTest, Errors) { EXPECT_EQ("Incorrect type for arg 2. (Expected = Matcher<CXXRecordDecl>) != " "(Actual = Matcher<FunctionDecl>)", Error->toString()); + + // Bad argument type with variadic. + Error.reset(new Diagnostics()); + EXPECT_TRUE(constructMatcher("anyOf", std::string(), Error.get()).isNull()); + EXPECT_EQ( + "Incorrect type for arg 1. (Expected = Matcher<>) != (Actual = String)", + Error->toString()); + Error.reset(new Diagnostics()); + EXPECT_TRUE(constructMatcher( + "recordDecl", + constructMatcher("allOf", + constructMatcher("isDerivedFrom", std::string("FOO")), + constructMatcher("isArrow")), + Error.get()).isNull()); + EXPECT_EQ("Incorrect type for arg 1. " + "(Expected = Matcher<CXXRecordDecl>) != " + "(Actual = Matcher<CXXRecordDecl>&Matcher<MemberExpr>)", + Error->toString()); } } // end anonymous namespace |