aboutsummaryrefslogtreecommitdiff
path: root/unittests/AST/DeclPrinterTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/AST/DeclPrinterTest.cpp')
-rw-r--r--unittests/AST/DeclPrinterTest.cpp126
1 files changed, 31 insertions, 95 deletions
diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp
index d06fbfea6f5e..e5a09a31f69f 100644
--- a/unittests/AST/DeclPrinterTest.cpp
+++ b/unittests/AST/DeclPrinterTest.cpp
@@ -45,7 +45,7 @@ public:
PrintMatch() : NumFoundDecls(0) {}
void run(const MatchFinder::MatchResult &Result) override {
- const Decl *D = Result.Nodes.getDeclAs<Decl>("id");
+ const Decl *D = Result.Nodes.getNodeAs<Decl>("id");
if (!D || D->isImplicit())
return;
NumFoundDecls++;
@@ -254,24 +254,21 @@ TEST(DeclPrinter, TestCXXRecordDecl1) {
ASSERT_TRUE(PrintedDeclCXX98Matches(
"class A { int a; };",
"A",
- "class A {\n}"));
- // Should be: with semicolon, with { ... }
+ "class A {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl2) {
ASSERT_TRUE(PrintedDeclCXX98Matches(
"struct A { int a; };",
"A",
- "struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "struct A {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl3) {
ASSERT_TRUE(PrintedDeclCXX98Matches(
"union A { int a; };",
"A",
- "union A {\n}"));
- // Should be: with semicolon, with { ... }
+ "union A {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl4) {
@@ -279,8 +276,7 @@ TEST(DeclPrinter, TestCXXRecordDecl4) {
"class Z { int a; };"
"class A : Z { int b; };",
"A",
- "class A : Z {\n}"));
- // Should be: with semicolon, with { ... }
+ "class A : Z {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl5) {
@@ -288,8 +284,7 @@ TEST(DeclPrinter, TestCXXRecordDecl5) {
"struct Z { int a; };"
"struct A : Z { int b; };",
"A",
- "struct A : Z {\n}"));
- // Should be: with semicolon, with { ... }
+ "struct A : Z {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl6) {
@@ -297,8 +292,7 @@ TEST(DeclPrinter, TestCXXRecordDecl6) {
"class Z { int a; };"
"class A : public Z { int b; };",
"A",
- "class A : public Z {\n}"));
- // Should be: with semicolon, with { ... }
+ "class A : public Z {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl7) {
@@ -306,8 +300,7 @@ TEST(DeclPrinter, TestCXXRecordDecl7) {
"class Z { int a; };"
"class A : protected Z { int b; };",
"A",
- "class A : protected Z {\n}"));
- // Should be: with semicolon, with { ... }
+ "class A : protected Z {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl8) {
@@ -315,8 +308,7 @@ TEST(DeclPrinter, TestCXXRecordDecl8) {
"class Z { int a; };"
"class A : private Z { int b; };",
"A",
- "class A : private Z {\n}"));
- // Should be: with semicolon, with { ... }
+ "class A : private Z {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl9) {
@@ -324,8 +316,7 @@ TEST(DeclPrinter, TestCXXRecordDecl9) {
"class Z { int a; };"
"class A : virtual Z { int b; };",
"A",
- "class A : virtual Z {\n}"));
- // Should be: with semicolon, with { ... }
+ "class A : virtual Z {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl10) {
@@ -333,8 +324,7 @@ TEST(DeclPrinter, TestCXXRecordDecl10) {
"class Z { int a; };"
"class A : virtual public Z { int b; };",
"A",
- "class A : virtual public Z {\n}"));
- // Should be: with semicolon, with { ... }
+ "class A : virtual public Z {}"));
}
TEST(DeclPrinter, TestCXXRecordDecl11) {
@@ -343,8 +333,7 @@ TEST(DeclPrinter, TestCXXRecordDecl11) {
"class Y : virtual public Z { int b; };"
"class A : virtual public Z, private Y { int c; };",
"A",
- "class A : virtual public Z, private Y {\n}"));
- // Should be: with semicolon, with { ... }
+ "class A : virtual public Z, private Y {}"));
}
TEST(DeclPrinter, TestFunctionDecl1) {
@@ -352,7 +341,6 @@ TEST(DeclPrinter, TestFunctionDecl1) {
"void A();",
"A",
"void A()"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl2) {
@@ -360,7 +348,6 @@ TEST(DeclPrinter, TestFunctionDecl2) {
"void A() {}",
"A",
"void A()"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl3) {
@@ -369,7 +356,6 @@ TEST(DeclPrinter, TestFunctionDecl3) {
"void A() { Z(); }",
"A",
"void A()"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl4) {
@@ -377,7 +363,6 @@ TEST(DeclPrinter, TestFunctionDecl4) {
"extern void A();",
"A",
"extern void A()"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl5) {
@@ -385,7 +370,6 @@ TEST(DeclPrinter, TestFunctionDecl5) {
"static void A();",
"A",
"static void A()"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl6) {
@@ -393,7 +377,6 @@ TEST(DeclPrinter, TestFunctionDecl6) {
"inline void A();",
"A",
"inline void A()"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl7) {
@@ -401,7 +384,6 @@ TEST(DeclPrinter, TestFunctionDecl7) {
"constexpr int A(int a);",
"A",
"constexpr int A(int a)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl8) {
@@ -409,7 +391,6 @@ TEST(DeclPrinter, TestFunctionDecl8) {
"void A(int a);",
"A",
"void A(int a)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl9) {
@@ -417,7 +398,6 @@ TEST(DeclPrinter, TestFunctionDecl9) {
"void A(...);",
"A",
"void A(...)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl10) {
@@ -425,7 +405,6 @@ TEST(DeclPrinter, TestFunctionDecl10) {
"void A(int a, ...);",
"A",
"void A(int a, ...)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl11) {
@@ -435,7 +414,6 @@ TEST(DeclPrinter, TestFunctionDecl11) {
"void A(int a, pInt b, ssize_t c);",
"A",
"void A(int a, pInt b, ssize_t c)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl12) {
@@ -443,7 +421,6 @@ TEST(DeclPrinter, TestFunctionDecl12) {
"void A(int a, int b = 0);",
"A",
"void A(int a, int b = 0)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl13) {
@@ -451,7 +428,7 @@ TEST(DeclPrinter, TestFunctionDecl13) {
"void (*A(int a))(int b);",
"A",
"void (*A(int a))(int)"));
- // Should be: with semicolon, with parameter name (?)
+ // Should be: with parameter name (?)
}
TEST(DeclPrinter, TestFunctionDecl14) {
@@ -461,8 +438,7 @@ TEST(DeclPrinter, TestFunctionDecl14) {
"template<>"
"void A(int N) { }",
functionDecl(hasName("A"), isExplicitTemplateSpecialization()).bind("id"),
- "void A(int N)"));
- // WRONG; Should be: "template <> void A(int N);"));
+ "template<> void A<int>(int N)"));
}
@@ -555,7 +531,6 @@ TEST(DeclPrinter, TestCXXConstructorDecl10) {
"};",
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
"A<T...>(const A<T...> &a)"));
- // WRONG; Should be: "A(const A<T...> &a);"
}
TEST(DeclPrinter, TestCXXConstructorDecl11) {
@@ -565,8 +540,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl11) {
" A(T&&... ts) : T(ts)... {}"
"};",
cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
- "A<T...>(T &&...ts) : T(ts)..."));
- // WRONG; Should be: "A(T &&...ts) : T(ts)... {}"
+ "A<T...>(T &&...ts) : T(ts)... {}"));
}
TEST(DeclPrinter, TestCXXDestructorDecl1) {
@@ -623,7 +597,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) {
"};",
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
"void *operator new(std::size_t)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) {
@@ -634,7 +607,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) {
"};",
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
"void *operator new[](std::size_t)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) {
@@ -644,7 +616,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) {
"};",
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
"void operator delete(void *) noexcept"));
- // Should be: with semicolon, without noexcept?
+ // Should be: without noexcept?
}
TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) {
@@ -654,7 +626,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) {
"};",
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
"void operator delete(void *)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) {
@@ -664,7 +635,7 @@ TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) {
"};",
cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
"void operator delete[](void *) noexcept"));
- // Should be: with semicolon, without noexcept?
+ // Should be: without noexcept?
}
TEST(DeclPrinter, TestCXXMethodDecl_Operator1) {
@@ -686,7 +657,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator1) {
Expected.append("void operator");
Expected.append(OperatorNames[i]);
Expected.append("(Z z)");
- // Should be: with semicolon
ASSERT_TRUE(PrintedDeclCXX98Matches(
Code,
@@ -710,7 +680,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_Operator2) {
Expected.append("void operator");
Expected.append(OperatorNames[i]);
Expected.append("()");
- // Should be: with semicolon
ASSERT_TRUE(PrintedDeclCXX98Matches(
Code,
@@ -726,7 +695,6 @@ TEST(DeclPrinter, TestCXXMethodDecl1) {
"};",
"A",
"void A(int a)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl2) {
@@ -736,7 +704,6 @@ TEST(DeclPrinter, TestCXXMethodDecl2) {
"};",
"A",
"virtual void A(int a)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl3) {
@@ -749,7 +716,6 @@ TEST(DeclPrinter, TestCXXMethodDecl3) {
"};",
"ZZ::A",
"void A(int a)"));
- // Should be: with semicolon
// TODO: should we print "virtual"?
}
@@ -760,7 +726,6 @@ TEST(DeclPrinter, TestCXXMethodDecl4) {
"};",
"A",
"inline void A(int a)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl5) {
@@ -770,7 +735,6 @@ TEST(DeclPrinter, TestCXXMethodDecl5) {
"};",
"A",
"virtual void A(int a) = 0"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier1) {
@@ -780,7 +744,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier1) {
"};",
"A",
"void A(int a) const"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier2) {
@@ -790,7 +753,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier2) {
"};",
"A",
"void A(int a) volatile"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier3) {
@@ -800,7 +762,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier3) {
"};",
"A",
"void A(int a) const volatile"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) {
@@ -810,7 +771,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) {
"};",
"A",
"void A(int a) &"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) {
@@ -820,7 +780,6 @@ TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) {
"};",
"A",
"void A(int a) &&"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) {
@@ -830,7 +789,6 @@ TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) {
"};",
"A",
"void A(int a) throw()"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification2) {
@@ -840,7 +798,6 @@ TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification2) {
"};",
"A",
"void A(int a) throw(int)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification3) {
@@ -851,7 +808,6 @@ TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification3) {
"};",
"A",
"void A(int a) throw(ZZ, int)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification4) {
@@ -861,7 +817,6 @@ TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification4) {
"};",
"A",
"void A(int a) noexcept"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification5) {
@@ -942,8 +897,7 @@ TEST(DeclPrinter, TestClassTemplateDecl1) {
"template<typename T>"
"struct A { T a; };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <typename T> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <typename T> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl2) {
@@ -951,8 +905,7 @@ TEST(DeclPrinter, TestClassTemplateDecl2) {
"template<typename T = int>"
"struct A { T a; };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <typename T = int> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <typename T = int> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl3) {
@@ -960,8 +913,7 @@ TEST(DeclPrinter, TestClassTemplateDecl3) {
"template<class T>"
"struct A { T a; };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <class T> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <class T> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl4) {
@@ -969,8 +921,7 @@ TEST(DeclPrinter, TestClassTemplateDecl4) {
"template<typename T, typename U>"
"struct A { T a; U b; };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <typename T, typename U> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <typename T, typename U> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl5) {
@@ -978,8 +929,7 @@ TEST(DeclPrinter, TestClassTemplateDecl5) {
"template<int N>"
"struct A { int a[N]; };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <int N> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <int N> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl6) {
@@ -987,8 +937,7 @@ TEST(DeclPrinter, TestClassTemplateDecl6) {
"template<int N = 42>"
"struct A { int a[N]; };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <int N = 42> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <int N = 42> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl7) {
@@ -997,16 +946,14 @@ TEST(DeclPrinter, TestClassTemplateDecl7) {
"template<MyInt N>"
"struct A { int a[N]; };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <MyInt N> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <MyInt N> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl8) {
ASSERT_TRUE(PrintedDeclCXX98Matches(
"template<template<typename U> class T> struct A { };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <template <typename U> class T> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <template <typename U> class T> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl9) {
@@ -1014,8 +961,7 @@ TEST(DeclPrinter, TestClassTemplateDecl9) {
"template<typename T> struct Z { };"
"template<template<typename U> class T = Z> struct A { };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <template <typename U> class T> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <template <typename U> class T> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl10) {
@@ -1023,8 +969,7 @@ TEST(DeclPrinter, TestClassTemplateDecl10) {
"template<typename... T>"
"struct A { int a; };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <typename ...T> struct A {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <typename ...T> struct A {}"));
}
TEST(DeclPrinter, TestClassTemplateDecl11) {
@@ -1032,8 +977,7 @@ TEST(DeclPrinter, TestClassTemplateDecl11) {
"template<typename... T>"
"struct A : public T... { int a; };",
classTemplateDecl(hasName("A")).bind("id"),
- "template <typename ...T> struct A : public T... {\n}"));
- // Should be: with semicolon, with { ... }
+ "template <typename ...T> struct A : public T... {}"));
}
TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) {
@@ -1043,8 +987,7 @@ TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) {
"template<typename T>"
"struct A<T, int> { T a; };",
classTemplateSpecializationDecl().bind("id"),
- "struct A {\n}"));
- // WRONG; Should be: "template<typename T> struct A<T, int> { ... }"
+ "template <typename T> struct A<T, int> {}"));
}
TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) {
@@ -1054,7 +997,7 @@ TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) {
"template<typename T>"
"struct A<T *> { T a; };",
classTemplateSpecializationDecl().bind("id"),
- "struct A {\n}"));
+ "template <typename T> struct A<type-parameter-0-0 *> {}"));
// WRONG; Should be: "template<typename T> struct A<T *> { ... }"
}
@@ -1065,8 +1008,7 @@ TEST(DeclPrinter, TestClassTemplateSpecializationDecl1) {
"template<>"
"struct A<int> { int a; };",
classTemplateSpecializationDecl().bind("id"),
- "struct A {\n}"));
- // WRONG; Should be: "template<> struct A<int> { ... }"
+ "template<> struct A<int> {}"));
}
TEST(DeclPrinter, TestFunctionTemplateDecl1) {
@@ -1075,7 +1017,6 @@ TEST(DeclPrinter, TestFunctionTemplateDecl1) {
"void A(T &t);",
functionTemplateDecl(hasName("A")).bind("id"),
"template <typename T> void A(T &t)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionTemplateDecl2) {
@@ -1084,7 +1025,6 @@ TEST(DeclPrinter, TestFunctionTemplateDecl2) {
"void A(T &t) { }",
functionTemplateDecl(hasName("A")).bind("id"),
"template <typename T> void A(T &t)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionTemplateDecl3) {
@@ -1093,7 +1033,6 @@ TEST(DeclPrinter, TestFunctionTemplateDecl3) {
"void A(T... a);",
functionTemplateDecl(hasName("A")).bind("id"),
"template <typename ...T> void A(T ...a)"));
- // Should be: with semicolon.
}
TEST(DeclPrinter, TestFunctionTemplateDecl4) {
@@ -1101,7 +1040,6 @@ TEST(DeclPrinter, TestFunctionTemplateDecl4) {
"struct Z { template<typename T> void A(T t); };",
functionTemplateDecl(hasName("A")).bind("id"),
"template <typename T> void A(T t)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionTemplateDecl5) {
@@ -1109,7 +1047,6 @@ TEST(DeclPrinter, TestFunctionTemplateDecl5) {
"struct Z { template<typename T> void A(T t) {} };",
functionTemplateDecl(hasName("A")).bind("id"),
"template <typename T> void A(T t)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionTemplateDecl6) {
@@ -1119,7 +1056,6 @@ TEST(DeclPrinter, TestFunctionTemplateDecl6) {
"};",
functionTemplateDecl(hasName("A")).bind("id"),
"template <typename U> void A(U t)"));
- // Should be: with semicolon
}
TEST(DeclPrinter, TestTemplateArgumentList1) {