summaryrefslogtreecommitdiff
path: root/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp')
-rw-r--r--unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 7bc8421bab2f..7e7d02707112 100644
--- a/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1315,6 +1315,14 @@ TEST(Matcher, IsDefinition) {
cxxMethodDecl(hasName("a"), isDefinition());
EXPECT_TRUE(matches("class A { void a() {} };", DefinitionOfMethodA));
EXPECT_TRUE(notMatches("class A { void a(); };", DefinitionOfMethodA));
+
+ DeclarationMatcher DefinitionOfObjCMethodA =
+ objcMethodDecl(hasName("a"), isDefinition());
+ EXPECT_TRUE(matchesObjC("@interface A @end "
+ "@implementation A; -(void)a {} @end",
+ DefinitionOfObjCMethodA));
+ EXPECT_TRUE(notMatchesObjC("@interface A; - (void)a; @end",
+ DefinitionOfObjCMethodA));
}
TEST(Matcher, HandlesNullQualTypes) {
@@ -1983,5 +1991,43 @@ TEST(HasExternalFormalLinkage, Basic) {
namedDecl(hasExternalFormalLinkage())));
}
+TEST(HasDefaultArgument, Basic) {
+ EXPECT_TRUE(matches("void x(int val = 0) {}",
+ parmVarDecl(hasDefaultArgument())));
+ EXPECT_TRUE(notMatches("void x(int val) {}",
+ parmVarDecl(hasDefaultArgument())));
+}
+
+TEST(IsArray, Basic) {
+ EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
+ cxxNewExpr(isArray())));
+}
+
+TEST(HasArraySize, Basic) {
+ EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
+ cxxNewExpr(hasArraySize(integerLiteral(equals(10))))));
+}
+
+TEST(HasDefinition, MatchesStructDefinition) {
+ EXPECT_TRUE(matches("struct x {};",
+ cxxRecordDecl(hasDefinition())));
+ EXPECT_TRUE(notMatches("struct x;",
+ cxxRecordDecl(hasDefinition())));
+}
+
+TEST(HasDefinition, MatchesClassDefinition) {
+ EXPECT_TRUE(matches("class x {};",
+ cxxRecordDecl(hasDefinition())));
+ EXPECT_TRUE(notMatches("class x;",
+ cxxRecordDecl(hasDefinition())));
+}
+
+TEST(HasDefinition, MatchesUnionDefinition) {
+ EXPECT_TRUE(matches("union x {};",
+ cxxRecordDecl(hasDefinition())));
+ EXPECT_TRUE(notMatches("union x;",
+ cxxRecordDecl(hasDefinition())));
+}
+
} // namespace ast_matchers
} // namespace clang