diff options
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersNodeTest.cpp')
| -rw-r--r-- | unittests/ASTMatchers/ASTMatchersNodeTest.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/unittests/ASTMatchers/ASTMatchersNodeTest.cpp index 59fadadbedc7..e521940983b2 100644 --- a/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -160,6 +160,16 @@ TEST(ValueDecl, Matches) { valueDecl(hasType(asString("void (void)"))))); } +TEST(FriendDecl, Matches) { + EXPECT_TRUE(matches("class Y { friend class X; };", + friendDecl(hasType(asString("class X"))))); + EXPECT_TRUE(matches("class Y { friend class X; };", + friendDecl(hasType(recordDecl(hasName("X")))))); + + EXPECT_TRUE(matches("class Y { friend void f(); };", + functionDecl(hasName("f"), hasParent(friendDecl())))); +} + TEST(Enum, DoesNotMatchClasses) { EXPECT_TRUE(notMatches("class X {};", enumDecl(hasName("X")))); } @@ -1196,6 +1206,12 @@ TEST(TypeMatching, MatchesAutoTypes) { // autoType(hasDeducedType(isInteger())))); } +TEST(TypeMatching, MatchesDeclTypes) { + EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;", decltypeType())); + EXPECT_TRUE(matches("decltype(1 + 1) sum = 1 + 1;", + decltypeType(hasUnderlyingType(isInteger())))); +} + TEST(TypeMatching, MatchesFunctionTypes) { EXPECT_TRUE(matches("int (*f)(int);", functionType())); EXPECT_TRUE(matches("void f(int i) {}", functionType())); @@ -1450,6 +1466,10 @@ TEST(NNS, MatchesNestedNameSpecifierPrefixes) { "struct A { struct B { struct C {}; }; }; A::B::C c;", nestedNameSpecifierLoc(hasPrefix( specifiesTypeLoc(loc(qualType(asString("struct A")))))))); + EXPECT_TRUE(matches( + "namespace N { struct A { struct B { struct C {}; }; }; } N::A::B::C c;", + nestedNameSpecifierLoc(hasPrefix( + specifiesTypeLoc(loc(qualType(asString("struct N::A")))))))); } @@ -1565,11 +1585,22 @@ TEST(ObjCMessageExprMatcher, SimpleExprs) { EXPECT_TRUE(matchesObjC( Objc1String, objcMessageExpr(anything()))); + EXPECT_TRUE(matchesObjC(Objc1String, + objcMessageExpr(hasAnySelector({ + "contents", "meth:"})) + + )); EXPECT_TRUE(matchesObjC( Objc1String, objcMessageExpr(hasSelector("contents")))); EXPECT_TRUE(matchesObjC( Objc1String, + objcMessageExpr(hasAnySelector("contents", "contentsA")))); + EXPECT_FALSE(matchesObjC( + Objc1String, + objcMessageExpr(hasAnySelector("contentsB", "contentsC")))); + EXPECT_TRUE(matchesObjC( + Objc1String, objcMessageExpr(matchesSelector("cont*")))); EXPECT_FALSE(matchesObjC( Objc1String, @@ -1662,5 +1693,17 @@ TEST(ObjCStmtMatcher, ExceptionStmts) { objcFinallyStmt())); } +TEST(ObjCAutoreleaseMatcher, AutoreleasePool) { + std::string ObjCString = + "void f() {" + "@autoreleasepool {" + " int x = 1;" + "}" + "}"; + EXPECT_TRUE(matchesObjC(ObjCString, autoreleasePoolStmt())); + std::string ObjCStringNoPool = "void f() { int x = 1; }"; + EXPECT_FALSE(matchesObjC(ObjCStringNoPool, autoreleasePoolStmt())); +} + } // namespace ast_matchers } // namespace clang |
