diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:37 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:11:37 +0000 |
commit | 461a67fa15370a9ec88f8f8a240bf7c123bb2029 (patch) | |
tree | 6942083d7d56bba40ec790a453ca58ad3baf6832 /unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | |
parent | 75c3240472ba6ac2669ee72ca67eb72d4e2851fc (diff) |
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp index 7bc8421bab2ff..7e7d02707112a 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 |