[cfe-commits] r161102 - /cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Daniel Jasper djasper at google.com
Wed Aug 1 01:40:24 PDT 2012


Author: djasper
Date: Wed Aug  1 03:40:24 2012
New Revision: 161102

URL: http://llvm.org/viewvc/llvm-project?rev=161102&view=rev
Log:
Add missing tests for class template specialization and template
argument matchers.

Modified:
    cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=161102&r1=161101&r2=161102&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Wed Aug  1 03:40:24 2012
@@ -1116,6 +1116,46 @@
       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());
 





More information about the cfe-commits mailing list