From: Daniel Jasper Date: Wed, 1 Aug 2012 08:40:24 +0000 (+0000) Subject: Add missing tests for class template specialization and template X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=371f9391329d488d9bc4098adc7f5cf73aede1c1;p=clang 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 --- 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 struct A {};" + "template<> struct A {};", + classTemplateSpecialization())); + EXPECT_TRUE(matches("template struct A {}; A a;", + classTemplateSpecialization())); + EXPECT_TRUE(notMatches("template struct A {};", + classTemplateSpecialization())); +} + +TEST(Matcher, MatchesTypeTemplateArgument) { + EXPECT_TRUE(matches( + "template struct B {};" + "B b;", + classTemplateSpecialization(hasAnyTemplateArgument(refersToType( + asString("int")))))); +} + +TEST(Matcher, MatchesDeclarationReferenceTemplateArgument) { + EXPECT_TRUE(matches( + "struct B { int next; };" + "template struct A {};" + "A<&B::next> a;", + classTemplateSpecialization(hasAnyTemplateArgument( + refersToDeclaration(field(hasName("next"))))))); +} + +TEST(Matcher, MatchesSpecificArgument) { + EXPECT_TRUE(matches( + "template class A {};" + "A a;", + classTemplateSpecialization(hasTemplateArgument( + 1, refersToType(asString("int")))))); + EXPECT_TRUE(notMatches( + "template class A {};" + "A a;", + classTemplateSpecialization(hasTemplateArgument( + 1, refersToType(asString("int")))))); +} + TEST(Matcher, ConstructorCall) { StatementMatcher Constructor = expression(constructorCall());