diff options
author | Daniel Jasper <djasper@google.com> | 2012-08-01 08:40:24 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2012-08-01 08:40:24 +0000 |
commit | 371f9391329d488d9bc4098adc7f5cf73aede1c1 (patch) | |
tree | 5eb3f36110a566e8f4b7d57c8c4630c4eac047c4 /unittests/ASTMatchers/ASTMatchersTest.cpp | |
parent | 7916c997127fe616ba255ba4cade10e5de0c8812 (diff) |
Add missing tests for class template specialization and template
argument matchers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161102 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.cpp')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 8768baf186..cf37c7d27a 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1116,6 +1116,46 @@ TEST(HasName, MatchesParameterVariableDeclartions) { method(hasAnyParameter(hasName("x"))))); } +TEST(Matcher, MatchesClassTemplateSpecialization) { + EXPECT_TRUE(matches("template<typename T> struct A {};" + "template<> struct A<int> {};", + classTemplateSpecialization())); + EXPECT_TRUE(matches("template<typename T> struct A {}; A<int> a;", + classTemplateSpecialization())); + EXPECT_TRUE(notMatches("template<typename T> struct A {};", + classTemplateSpecialization())); +} + +TEST(Matcher, MatchesTypeTemplateArgument) { + EXPECT_TRUE(matches( + "template<typename T> struct B {};" + "B<int> b;", + classTemplateSpecialization(hasAnyTemplateArgument(refersToType( + asString("int")))))); +} + +TEST(Matcher, MatchesDeclarationReferenceTemplateArgument) { + EXPECT_TRUE(matches( + "struct B { int next; };" + "template<int(B::*next_ptr)> struct A {};" + "A<&B::next> a;", + classTemplateSpecialization(hasAnyTemplateArgument( + refersToDeclaration(field(hasName("next"))))))); +} + +TEST(Matcher, MatchesSpecificArgument) { + EXPECT_TRUE(matches( + "template<typename T, typename U> class A {};" + "A<bool, int> a;", + classTemplateSpecialization(hasTemplateArgument( + 1, refersToType(asString("int")))))); + EXPECT_TRUE(notMatches( + "template<typename T, typename U> class A {};" + "A<int, bool> a;", + classTemplateSpecialization(hasTemplateArgument( + 1, refersToType(asString("int")))))); +} + TEST(Matcher, ConstructorCall) { StatementMatcher Constructor = expression(constructorCall()); |