diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-03-06 17:02:57 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-03-06 17:02:57 +0000 |
commit | 6a19a97e57c8678adb0505a07c97d7ccadc8fe4e (patch) | |
tree | 2cd9322d7a522eeab9455a5ab8b0fe3d5e42241c /unittests/ASTMatchers/ASTMatchersTest.cpp | |
parent | 7e73f94c104070cf03c6f711a10f1928a550193f (diff) |
New ASTMatchers and enhancement to hasOverloadedOperatorName
Added two new narrowing matchers:
* hasMethod: aplies a matcher to a CXXRecordDecl's methods until a match is made
or there are no more methods.
* hasCanonicalType: applies a matcher to a QualType's canonicalType.
Enhanced hasOverloadedOperatorName to work on CXXMethodDecl as well as
CXXOperatorCallExpr.
Updated tests and docs.
Reviewers: klimek, gribozavr
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176556 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 4d369e5585..318d09c9bf 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -313,6 +313,13 @@ TEST(DeclarationMatcher, ClassIsDerived) { recordDecl(isDerivedFrom(recordDecl(hasName("X")).bind("test"))))); } +TEST(DeclarationMatcher, hasMethod) { + EXPECT_TRUE(matches("class A { void func(); };", + recordDecl(hasMethod(hasName("func"))))); + EXPECT_TRUE(notMatches("class A { void func(); };", + recordDecl(hasMethod(isPublic())))); +} + TEST(DeclarationMatcher, ClassDerivedFromDependentTemplateSpecialization) { EXPECT_TRUE(matches( "template <typename T> struct A {" @@ -1022,6 +1029,12 @@ TEST(Matcher, HasOperatorNameForOverloadedOperatorCall) { "bool operator&&(Y x, Y y) { return true; }; " "Y a; Y b; bool c = a && b;", OpCallLessLess)); + DeclarationMatcher ClassWithOpStar = + recordDecl(hasMethod(hasOverloadedOperatorName("*"))); + EXPECT_TRUE(matches("class Y { int operator*(); };", + ClassWithOpStar)); + EXPECT_TRUE(notMatches("class Y { void myOperator(); };", + ClassWithOpStar)) ; } TEST(Matcher, NestedOverloadedOperatorCalls) { @@ -1329,6 +1342,18 @@ TEST(Matcher, References) { notMatches("class X {}; void y(X *y) { X *&x = y; }", ReferenceClassX)); } +TEST(QualType, hasCanonicalType) { + EXPECT_TRUE(notMatches("typedef int &int_ref;" + "int a;" + "int_ref b = a;", + varDecl(hasType(qualType(referenceType()))))); + EXPECT_TRUE( + matches("typedef int &int_ref;" + "int a;" + "int_ref b = a;", + varDecl(hasType(qualType(hasCanonicalType(referenceType())))))); +} + TEST(HasParameter, CallsInnerMatcher) { EXPECT_TRUE(matches("class X { void x(int) {} };", methodDecl(hasParameter(0, varDecl())))); |