Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1 | //===- unittests/AST/DeclPrinterTest.cpp --- Declaration printer tests ----===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains tests for Decl::print() and related methods. |
| 11 | // |
| 12 | // Search this file for WRONG to see test cases that are producing something |
| 13 | // completely wrong, invalid C++ or just misleading. |
| 14 | // |
| 15 | // These tests have a coding convention: |
| 16 | // * declaration to be printed is named 'A' unless it should have some special |
| 17 | // name (e.g., 'operator+'); |
| 18 | // * additional helper declarations are 'Z', 'Y', 'X' and so on. |
| 19 | // |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
| 22 | #include "clang/AST/ASTContext.h" |
| 23 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
| 24 | #include "clang/Tooling/Tooling.h" |
Daniel Jasper | 6ed1f85 | 2012-08-24 05:50:27 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallString.h" |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 26 | #include "gtest/gtest.h" |
| 27 | |
| 28 | using namespace clang; |
| 29 | using namespace ast_matchers; |
| 30 | using namespace tooling; |
| 31 | |
| 32 | namespace { |
| 33 | |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 34 | using PrintingPolicyModifier = void (*)(PrintingPolicy &policy); |
| 35 | |
| 36 | void PrintDecl(raw_ostream &Out, const ASTContext *Context, const Decl *D, |
| 37 | PrintingPolicyModifier PolicyModifier) { |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 38 | PrintingPolicy Policy = Context->getPrintingPolicy(); |
Dmitri Gribenko | a93a7e8 | 2012-08-21 17:36:32 +0000 | [diff] [blame] | 39 | Policy.TerseOutput = true; |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 40 | if (PolicyModifier) |
| 41 | PolicyModifier(Policy); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 42 | D->print(Out, Policy, /*Indentation*/ 0, /*PrintInstantiation*/ false); |
| 43 | } |
| 44 | |
| 45 | class PrintMatch : public MatchFinder::MatchCallback { |
| 46 | SmallString<1024> Printed; |
| 47 | unsigned NumFoundDecls; |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 48 | PrintingPolicyModifier PolicyModifier; |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 49 | |
| 50 | public: |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 51 | PrintMatch(PrintingPolicyModifier PolicyModifier) |
| 52 | : NumFoundDecls(0), PolicyModifier(PolicyModifier) {} |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 53 | |
Alexander Kornienko | 34eb207 | 2015-04-11 02:00:23 +0000 | [diff] [blame] | 54 | void run(const MatchFinder::MatchResult &Result) override { |
Alexander Kornienko | 7cdc705 | 2016-12-13 16:19:34 +0000 | [diff] [blame] | 55 | const Decl *D = Result.Nodes.getNodeAs<Decl>("id"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 56 | if (!D || D->isImplicit()) |
| 57 | return; |
| 58 | NumFoundDecls++; |
| 59 | if (NumFoundDecls > 1) |
| 60 | return; |
| 61 | |
| 62 | llvm::raw_svector_ostream Out(Printed); |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 63 | PrintDecl(Out, Result.Context, D, PolicyModifier); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | StringRef getPrinted() const { |
| 67 | return Printed; |
| 68 | } |
| 69 | |
| 70 | unsigned getNumFoundDecls() const { |
| 71 | return NumFoundDecls; |
| 72 | } |
| 73 | }; |
| 74 | |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 75 | ::testing::AssertionResult |
| 76 | PrintedDeclMatches(StringRef Code, const std::vector<std::string> &Args, |
| 77 | const DeclarationMatcher &NodeMatch, |
| 78 | StringRef ExpectedPrinted, StringRef FileName, |
| 79 | PrintingPolicyModifier PolicyModifier = nullptr) { |
| 80 | PrintMatch Printer(PolicyModifier); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 81 | MatchFinder Finder; |
| 82 | Finder.addMatcher(NodeMatch, &Printer); |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 83 | std::unique_ptr<FrontendActionFactory> Factory( |
| 84 | newFrontendActionFactory(&Finder)); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 85 | |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 86 | if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, FileName)) |
Saleem Abdulrasool | 8a8454b | 2014-01-25 20:04:44 +0000 | [diff] [blame] | 87 | return testing::AssertionFailure() |
| 88 | << "Parsing error in \"" << Code.str() << "\""; |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 89 | |
| 90 | if (Printer.getNumFoundDecls() == 0) |
| 91 | return testing::AssertionFailure() |
| 92 | << "Matcher didn't find any declarations"; |
| 93 | |
| 94 | if (Printer.getNumFoundDecls() > 1) |
| 95 | return testing::AssertionFailure() |
| 96 | << "Matcher should match only one declaration " |
| 97 | "(found " << Printer.getNumFoundDecls() << ")"; |
| 98 | |
| 99 | if (Printer.getPrinted() != ExpectedPrinted) |
| 100 | return ::testing::AssertionFailure() |
Saleem Abdulrasool | 8a8454b | 2014-01-25 20:04:44 +0000 | [diff] [blame] | 101 | << "Expected \"" << ExpectedPrinted.str() << "\", " |
| 102 | "got \"" << Printer.getPrinted().str() << "\""; |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 103 | |
| 104 | return ::testing::AssertionSuccess(); |
| 105 | } |
| 106 | |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 107 | ::testing::AssertionResult PrintedDeclCXX98Matches(StringRef Code, |
| 108 | StringRef DeclName, |
| 109 | StringRef ExpectedPrinted) { |
Dmitri Gribenko | 454a43c | 2012-08-31 03:23:26 +0000 | [diff] [blame] | 110 | std::vector<std::string> Args(1, "-std=c++98"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 111 | return PrintedDeclMatches(Code, |
Dmitri Gribenko | 454a43c | 2012-08-31 03:23:26 +0000 | [diff] [blame] | 112 | Args, |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 113 | namedDecl(hasName(DeclName)).bind("id"), |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 114 | ExpectedPrinted, |
| 115 | "input.cc"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 118 | ::testing::AssertionResult |
| 119 | PrintedDeclCXX98Matches(StringRef Code, const DeclarationMatcher &NodeMatch, |
| 120 | StringRef ExpectedPrinted, |
| 121 | PrintingPolicyModifier PolicyModifier = nullptr) { |
Dmitri Gribenko | 454a43c | 2012-08-31 03:23:26 +0000 | [diff] [blame] | 122 | std::vector<std::string> Args(1, "-std=c++98"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 123 | return PrintedDeclMatches(Code, |
Dmitri Gribenko | 454a43c | 2012-08-31 03:23:26 +0000 | [diff] [blame] | 124 | Args, |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 125 | NodeMatch, |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 126 | ExpectedPrinted, |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 127 | "input.cc", |
| 128 | PolicyModifier); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | ::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code, |
| 132 | StringRef DeclName, |
| 133 | StringRef ExpectedPrinted) { |
Dmitri Gribenko | 454a43c | 2012-08-31 03:23:26 +0000 | [diff] [blame] | 134 | std::vector<std::string> Args(1, "-std=c++11"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 135 | return PrintedDeclMatches(Code, |
Dmitri Gribenko | 454a43c | 2012-08-31 03:23:26 +0000 | [diff] [blame] | 136 | Args, |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 137 | namedDecl(hasName(DeclName)).bind("id"), |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 138 | ExpectedPrinted, |
| 139 | "input.cc"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | ::testing::AssertionResult PrintedDeclCXX11Matches( |
| 143 | StringRef Code, |
| 144 | const DeclarationMatcher &NodeMatch, |
| 145 | StringRef ExpectedPrinted) { |
Dmitri Gribenko | 454a43c | 2012-08-31 03:23:26 +0000 | [diff] [blame] | 146 | std::vector<std::string> Args(1, "-std=c++11"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 147 | return PrintedDeclMatches(Code, |
Dmitri Gribenko | 454a43c | 2012-08-31 03:23:26 +0000 | [diff] [blame] | 148 | Args, |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 149 | NodeMatch, |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 150 | ExpectedPrinted, |
| 151 | "input.cc"); |
| 152 | } |
| 153 | |
NAKAMURA Takumi | 7d2da0b | 2014-02-16 10:16:09 +0000 | [diff] [blame] | 154 | ::testing::AssertionResult PrintedDeclCXX11nonMSCMatches( |
| 155 | StringRef Code, |
| 156 | const DeclarationMatcher &NodeMatch, |
| 157 | StringRef ExpectedPrinted) { |
| 158 | std::vector<std::string> Args(1, "-std=c++11"); |
| 159 | Args.push_back("-fno-delayed-template-parsing"); |
| 160 | return PrintedDeclMatches(Code, |
| 161 | Args, |
| 162 | NodeMatch, |
| 163 | ExpectedPrinted, |
| 164 | "input.cc"); |
| 165 | } |
| 166 | |
David Majnemer | 8423df9 | 2015-06-05 22:40:53 +0000 | [diff] [blame] | 167 | ::testing::AssertionResult |
| 168 | PrintedDeclCXX1ZMatches(StringRef Code, const DeclarationMatcher &NodeMatch, |
| 169 | StringRef ExpectedPrinted) { |
| 170 | std::vector<std::string> Args(1, "-std=c++1z"); |
| 171 | return PrintedDeclMatches(Code, |
| 172 | Args, |
| 173 | NodeMatch, |
| 174 | ExpectedPrinted, |
| 175 | "input.cc"); |
| 176 | } |
| 177 | |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 178 | ::testing::AssertionResult PrintedDeclObjCMatches( |
| 179 | StringRef Code, |
| 180 | const DeclarationMatcher &NodeMatch, |
| 181 | StringRef ExpectedPrinted) { |
| 182 | std::vector<std::string> Args(1, ""); |
| 183 | return PrintedDeclMatches(Code, |
| 184 | Args, |
| 185 | NodeMatch, |
| 186 | ExpectedPrinted, |
| 187 | "input.m"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | } // unnamed namespace |
| 191 | |
Dmitri Gribenko | 5ea34fc | 2014-03-03 13:21:00 +0000 | [diff] [blame] | 192 | TEST(DeclPrinter, TestTypedef1) { |
| 193 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
| 194 | "typedef int A;", |
| 195 | "A", |
| 196 | "typedef int A")); |
| 197 | // Should be: with semicolon |
| 198 | } |
| 199 | |
| 200 | TEST(DeclPrinter, TestTypedef2) { |
| 201 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
| 202 | "typedef const char *A;", |
| 203 | "A", |
| 204 | "typedef const char *A")); |
| 205 | // Should be: with semicolon |
| 206 | } |
| 207 | |
| 208 | TEST(DeclPrinter, TestTypedef3) { |
| 209 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
| 210 | "template <typename Y> class X {};" |
| 211 | "typedef X<int> A;", |
| 212 | "A", |
| 213 | "typedef X<int> A")); |
| 214 | // Should be: with semicolon |
| 215 | } |
| 216 | |
| 217 | TEST(DeclPrinter, TestTypedef4) { |
| 218 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
| 219 | "namespace X { class Y {}; }" |
| 220 | "typedef X::Y A;", |
| 221 | "A", |
| 222 | "typedef X::Y A")); |
| 223 | // Should be: with semicolon |
| 224 | } |
| 225 | |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 226 | TEST(DeclPrinter, TestNamespace1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 227 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 228 | "namespace A { int B; }", |
| 229 | "A", |
| 230 | "namespace A {\n}")); |
| 231 | // Should be: with { ... } |
| 232 | } |
| 233 | |
| 234 | TEST(DeclPrinter, TestNamespace2) { |
| 235 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 236 | "inline namespace A { int B; }", |
| 237 | "A", |
| 238 | "inline namespace A {\n}")); |
| 239 | // Should be: with { ... } |
| 240 | } |
| 241 | |
| 242 | TEST(DeclPrinter, TestNamespaceAlias1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 243 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 244 | "namespace Z { }" |
| 245 | "namespace A = Z;", |
| 246 | "A", |
| 247 | "namespace A = Z")); |
| 248 | // Should be: with semicolon |
| 249 | } |
| 250 | |
| 251 | TEST(DeclPrinter, TestNamespaceAlias2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 252 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 253 | "namespace X { namespace Y {} }" |
| 254 | "namespace A = X::Y;", |
| 255 | "A", |
| 256 | "namespace A = X::Y")); |
| 257 | // Should be: with semicolon |
| 258 | } |
| 259 | |
| 260 | TEST(DeclPrinter, TestCXXRecordDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 261 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 262 | "class A { int a; };", |
| 263 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 264 | "class A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | TEST(DeclPrinter, TestCXXRecordDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 268 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 269 | "struct A { int a; };", |
| 270 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 271 | "struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | TEST(DeclPrinter, TestCXXRecordDecl3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 275 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 276 | "union A { int a; };", |
| 277 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 278 | "union A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | TEST(DeclPrinter, TestCXXRecordDecl4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 282 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 283 | "class Z { int a; };" |
| 284 | "class A : Z { int b; };", |
| 285 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 286 | "class A : Z {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | TEST(DeclPrinter, TestCXXRecordDecl5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 290 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 291 | "struct Z { int a; };" |
| 292 | "struct A : Z { int b; };", |
| 293 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 294 | "struct A : Z {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | TEST(DeclPrinter, TestCXXRecordDecl6) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 298 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 299 | "class Z { int a; };" |
| 300 | "class A : public Z { int b; };", |
| 301 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 302 | "class A : public Z {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | TEST(DeclPrinter, TestCXXRecordDecl7) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 306 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 307 | "class Z { int a; };" |
| 308 | "class A : protected Z { int b; };", |
| 309 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 310 | "class A : protected Z {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | TEST(DeclPrinter, TestCXXRecordDecl8) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 314 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 315 | "class Z { int a; };" |
| 316 | "class A : private Z { int b; };", |
| 317 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 318 | "class A : private Z {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | TEST(DeclPrinter, TestCXXRecordDecl9) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 322 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 323 | "class Z { int a; };" |
| 324 | "class A : virtual Z { int b; };", |
| 325 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 326 | "class A : virtual Z {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | TEST(DeclPrinter, TestCXXRecordDecl10) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 330 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 331 | "class Z { int a; };" |
| 332 | "class A : virtual public Z { int b; };", |
| 333 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 334 | "class A : virtual public Z {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | TEST(DeclPrinter, TestCXXRecordDecl11) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 338 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 339 | "class Z { int a; };" |
| 340 | "class Y : virtual public Z { int b; };" |
| 341 | "class A : virtual public Z, private Y { int c; };", |
| 342 | "A", |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 343 | "class A : virtual public Z, private Y {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | TEST(DeclPrinter, TestFunctionDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 347 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 348 | "void A();", |
| 349 | "A", |
| 350 | "void A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | TEST(DeclPrinter, TestFunctionDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 354 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 355 | "void A() {}", |
| 356 | "A", |
| 357 | "void A()")); |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | TEST(DeclPrinter, TestFunctionDecl3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 361 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 362 | "void Z();" |
| 363 | "void A() { Z(); }", |
| 364 | "A", |
| 365 | "void A()")); |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | TEST(DeclPrinter, TestFunctionDecl4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 369 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 370 | "extern void A();", |
| 371 | "A", |
| 372 | "extern void A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 375 | TEST(DeclPrinter, TestFunctionDecl5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 376 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 377 | "static void A();", |
| 378 | "A", |
| 379 | "static void A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 382 | TEST(DeclPrinter, TestFunctionDecl6) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 383 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 384 | "inline void A();", |
| 385 | "A", |
| 386 | "inline void A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 389 | TEST(DeclPrinter, TestFunctionDecl7) { |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 390 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 391 | "constexpr int A(int a);", |
| 392 | "A", |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 393 | "constexpr int A(int a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 396 | TEST(DeclPrinter, TestFunctionDecl8) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 397 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 398 | "void A(int a);", |
| 399 | "A", |
| 400 | "void A(int a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 403 | TEST(DeclPrinter, TestFunctionDecl9) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 404 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 405 | "void A(...);", |
| 406 | "A", |
| 407 | "void A(...)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 410 | TEST(DeclPrinter, TestFunctionDecl10) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 411 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 412 | "void A(int a, ...);", |
| 413 | "A", |
| 414 | "void A(int a, ...)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 417 | TEST(DeclPrinter, TestFunctionDecl11) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 418 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
David Majnemer | d4328de | 2014-01-14 08:18:49 +0000 | [diff] [blame] | 419 | "typedef long ssize_t;" |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 420 | "typedef int *pInt;" |
David Majnemer | d4328de | 2014-01-14 08:18:49 +0000 | [diff] [blame] | 421 | "void A(int a, pInt b, ssize_t c);", |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 422 | "A", |
David Majnemer | d4328de | 2014-01-14 08:18:49 +0000 | [diff] [blame] | 423 | "void A(int a, pInt b, ssize_t c)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 426 | TEST(DeclPrinter, TestFunctionDecl12) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 427 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 428 | "void A(int a, int b = 0);", |
| 429 | "A", |
| 430 | "void A(int a, int b = 0)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 433 | TEST(DeclPrinter, TestFunctionDecl13) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 434 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 435 | "void (*A(int a))(int b);", |
| 436 | "A", |
| 437 | "void (*A(int a))(int)")); |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 438 | // Should be: with parameter name (?) |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 441 | TEST(DeclPrinter, TestFunctionDecl14) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 442 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 443 | "template<typename T>" |
| 444 | "void A(T t) { }" |
| 445 | "template<>" |
| 446 | "void A(int N) { }", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 447 | functionDecl(hasName("A"), isExplicitTemplateSpecialization()).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 448 | "template<> void A<int>(int N)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | |
| 452 | TEST(DeclPrinter, TestCXXConstructorDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 453 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 454 | "struct A {" |
| 455 | " A();" |
| 456 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 457 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Fariborz Jahanian | 14ef479 | 2012-12-05 19:54:11 +0000 | [diff] [blame] | 458 | "A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | TEST(DeclPrinter, TestCXXConstructorDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 462 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 463 | "struct A {" |
| 464 | " A(int a);" |
| 465 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 466 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Fariborz Jahanian | 14ef479 | 2012-12-05 19:54:11 +0000 | [diff] [blame] | 467 | "A(int a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | TEST(DeclPrinter, TestCXXConstructorDecl3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 471 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 472 | "struct A {" |
| 473 | " A(const A &a);" |
| 474 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 475 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Fariborz Jahanian | 14ef479 | 2012-12-05 19:54:11 +0000 | [diff] [blame] | 476 | "A(const A &a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | TEST(DeclPrinter, TestCXXConstructorDecl4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 480 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 481 | "struct A {" |
| 482 | " A(const A &a, int = 0);" |
| 483 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 484 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Fariborz Jahanian | 14ef479 | 2012-12-05 19:54:11 +0000 | [diff] [blame] | 485 | "A(const A &a, int = 0)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 488 | TEST(DeclPrinter, TestCXXConstructorDeclWithMemberInitializer) { |
| 489 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
| 490 | "struct A {" |
| 491 | " int m;" |
| 492 | " A() : m(2) {}" |
| 493 | "};", |
| 494 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
| 495 | "A()")); |
| 496 | } |
| 497 | |
| 498 | TEST(DeclPrinter, TestCXXConstructorDeclWithMemberInitializer_NoTerseOutput) { |
| 499 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
| 500 | "struct A {" |
| 501 | " int m;" |
| 502 | " A() : m(2) {}" |
| 503 | "};", |
| 504 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
| 505 | "A() : m(2) {\n}\n", |
| 506 | [](PrintingPolicy &Policy){ Policy.TerseOutput = false; })); |
| 507 | } |
| 508 | |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 509 | TEST(DeclPrinter, TestCXXConstructorDecl5) { |
| 510 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 511 | "struct A {" |
| 512 | " A(const A &&a);" |
| 513 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 514 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Fariborz Jahanian | 14ef479 | 2012-12-05 19:54:11 +0000 | [diff] [blame] | 515 | "A(const A &&a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | TEST(DeclPrinter, TestCXXConstructorDecl6) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 519 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 520 | "struct A {" |
| 521 | " explicit A(int a);" |
| 522 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 523 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Fariborz Jahanian | 69c403c | 2012-12-05 22:19:06 +0000 | [diff] [blame] | 524 | "explicit A(int a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | TEST(DeclPrinter, TestCXXConstructorDecl7) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 528 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 529 | "struct A {" |
| 530 | " constexpr A();" |
| 531 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 532 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 533 | "constexpr A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | TEST(DeclPrinter, TestCXXConstructorDecl8) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 537 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 538 | "struct A {" |
| 539 | " A() = default;" |
| 540 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 541 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Richard Smith | bd30512 | 2012-12-11 01:14:52 +0000 | [diff] [blame] | 542 | "A() = default")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | TEST(DeclPrinter, TestCXXConstructorDecl9) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 546 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 547 | "struct A {" |
| 548 | " A() = delete;" |
| 549 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 550 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Fariborz Jahanian | 14ef479 | 2012-12-05 19:54:11 +0000 | [diff] [blame] | 551 | "A() = delete")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Dmitri Gribenko | 340c0f6 | 2012-08-24 00:26:25 +0000 | [diff] [blame] | 554 | TEST(DeclPrinter, TestCXXConstructorDecl10) { |
| 555 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 556 | "template<typename... T>" |
| 557 | "struct A {" |
| 558 | " A(const A &a);" |
| 559 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 560 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Fariborz Jahanian | 14ef479 | 2012-12-05 19:54:11 +0000 | [diff] [blame] | 561 | "A<T...>(const A<T...> &a)")); |
Dmitri Gribenko | 340c0f6 | 2012-08-24 00:26:25 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | TEST(DeclPrinter, TestCXXConstructorDecl11) { |
NAKAMURA Takumi | 7d2da0b | 2014-02-16 10:16:09 +0000 | [diff] [blame] | 565 | ASSERT_TRUE(PrintedDeclCXX11nonMSCMatches( |
Dmitri Gribenko | 340c0f6 | 2012-08-24 00:26:25 +0000 | [diff] [blame] | 566 | "template<typename... T>" |
| 567 | "struct A : public T... {" |
| 568 | " A(T&&... ts) : T(ts)... {}" |
| 569 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 570 | cxxConstructorDecl(ofClass(hasName("A"))).bind("id"), |
Alex Lorenz | 35019db | 2017-11-16 01:28:25 +0000 | [diff] [blame^] | 571 | "A<T...>(T &&...ts)")); |
Dmitri Gribenko | 340c0f6 | 2012-08-24 00:26:25 +0000 | [diff] [blame] | 572 | } |
Dmitri Gribenko | 340c0f6 | 2012-08-24 00:26:25 +0000 | [diff] [blame] | 573 | |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 574 | TEST(DeclPrinter, TestCXXDestructorDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 575 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 576 | "struct A {" |
| 577 | " ~A();" |
| 578 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 579 | cxxDestructorDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 580 | "~A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | TEST(DeclPrinter, TestCXXDestructorDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 584 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 585 | "struct A {" |
| 586 | " virtual ~A();" |
| 587 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 588 | cxxDestructorDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 589 | "virtual ~A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | TEST(DeclPrinter, TestCXXConversionDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 593 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 594 | "struct A {" |
| 595 | " operator int();" |
| 596 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 597 | cxxMethodDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 598 | "operator int()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | TEST(DeclPrinter, TestCXXConversionDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 602 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 603 | "struct A {" |
| 604 | " operator bool();" |
| 605 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 606 | cxxMethodDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 607 | "operator bool()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | TEST(DeclPrinter, TestCXXConversionDecl3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 611 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 612 | "struct Z {};" |
| 613 | "struct A {" |
| 614 | " operator Z();" |
| 615 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 616 | cxxMethodDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 617 | "operator Z()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 621 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 622 | "namespace std { typedef decltype(sizeof(int)) size_t; }" |
| 623 | "struct Z {" |
| 624 | " void *operator new(std::size_t);" |
| 625 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 626 | cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 627 | "void *operator new(std::size_t)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 631 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 632 | "namespace std { typedef decltype(sizeof(int)) size_t; }" |
| 633 | "struct Z {" |
| 634 | " void *operator new[](std::size_t);" |
| 635 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 636 | cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 637 | "void *operator new[](std::size_t)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 641 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 642 | "struct Z {" |
| 643 | " void operator delete(void *);" |
| 644 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 645 | cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 646 | "void operator delete(void *) noexcept")); |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 647 | // Should be: without noexcept? |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 651 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 652 | "struct Z {" |
| 653 | " void operator delete(void *);" |
| 654 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 655 | cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 656 | "void operator delete(void *)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 660 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 661 | "struct Z {" |
| 662 | " void operator delete[](void *);" |
| 663 | "};", |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 664 | cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 665 | "void operator delete[](void *) noexcept")); |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 666 | // Should be: without noexcept? |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | TEST(DeclPrinter, TestCXXMethodDecl_Operator1) { |
| 670 | const char *OperatorNames[] = { |
| 671 | "+", "-", "*", "/", "%", "^", "&", "|", |
| 672 | "=", "<", ">", "+=", "-=", "*=", "/=", "%=", |
| 673 | "^=", "&=", "|=", "<<", ">>", ">>=", "<<=", "==", "!=", |
| 674 | "<=", ">=", "&&", "||", ",", "->*", |
| 675 | "()", "[]" |
| 676 | }; |
| 677 | |
| 678 | for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) { |
| 679 | SmallString<128> Code; |
| 680 | Code.append("struct Z { void operator"); |
| 681 | Code.append(OperatorNames[i]); |
| 682 | Code.append("(Z z); };"); |
| 683 | |
| 684 | SmallString<128> Expected; |
| 685 | Expected.append("void operator"); |
| 686 | Expected.append(OperatorNames[i]); |
| 687 | Expected.append("(Z z)"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 688 | |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 689 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 690 | Code, |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 691 | cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 692 | Expected)); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | TEST(DeclPrinter, TestCXXMethodDecl_Operator2) { |
| 697 | const char *OperatorNames[] = { |
| 698 | "~", "!", "++", "--", "->" |
| 699 | }; |
| 700 | |
| 701 | for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) { |
| 702 | SmallString<128> Code; |
| 703 | Code.append("struct Z { void operator"); |
| 704 | Code.append(OperatorNames[i]); |
| 705 | Code.append("(); };"); |
| 706 | |
| 707 | SmallString<128> Expected; |
| 708 | Expected.append("void operator"); |
| 709 | Expected.append(OperatorNames[i]); |
| 710 | Expected.append("()"); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 711 | |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 712 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 713 | Code, |
Aaron Ballman | 512fb64 | 2015-09-17 13:30:52 +0000 | [diff] [blame] | 714 | cxxMethodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 715 | Expected)); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | TEST(DeclPrinter, TestCXXMethodDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 720 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 721 | "struct Z {" |
| 722 | " void A(int a);" |
| 723 | "};", |
| 724 | "A", |
| 725 | "void A(int a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | TEST(DeclPrinter, TestCXXMethodDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 729 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 730 | "struct Z {" |
| 731 | " virtual void A(int a);" |
| 732 | "};", |
| 733 | "A", |
| 734 | "virtual void A(int a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | TEST(DeclPrinter, TestCXXMethodDecl3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 738 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 739 | "struct Z {" |
| 740 | " virtual void A(int a);" |
| 741 | "};" |
| 742 | "struct ZZ : Z {" |
| 743 | " void A(int a);" |
| 744 | "};", |
| 745 | "ZZ::A", |
| 746 | "void A(int a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 747 | // TODO: should we print "virtual"? |
| 748 | } |
| 749 | |
| 750 | TEST(DeclPrinter, TestCXXMethodDecl4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 751 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 752 | "struct Z {" |
| 753 | " inline void A(int a);" |
| 754 | "};", |
| 755 | "A", |
| 756 | "inline void A(int a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | TEST(DeclPrinter, TestCXXMethodDecl5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 760 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 761 | "struct Z {" |
| 762 | " virtual void A(int a) = 0;" |
| 763 | "};", |
| 764 | "A", |
| 765 | "virtual void A(int a) = 0")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 769 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 770 | "struct Z {" |
| 771 | " void A(int a) const;" |
| 772 | "};", |
| 773 | "A", |
| 774 | "void A(int a) const")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 778 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 779 | "struct Z {" |
| 780 | " void A(int a) volatile;" |
| 781 | "};", |
| 782 | "A", |
| 783 | "void A(int a) volatile")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 787 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 788 | "struct Z {" |
| 789 | " void A(int a) const volatile;" |
| 790 | "};", |
| 791 | "A", |
| 792 | "void A(int a) const volatile")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) { |
| 796 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 797 | "struct Z {" |
| 798 | " void A(int a) &;" |
| 799 | "};", |
| 800 | "A", |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 801 | "void A(int a) &")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) { |
| 805 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 806 | "struct Z {" |
| 807 | " void A(int a) &&;" |
| 808 | "};", |
| 809 | "A", |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 810 | "void A(int a) &&")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 814 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 815 | "struct Z {" |
| 816 | " void A(int a) throw();" |
| 817 | "};", |
| 818 | "A", |
| 819 | "void A(int a) throw()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 823 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 824 | "struct Z {" |
| 825 | " void A(int a) throw(int);" |
| 826 | "};", |
| 827 | "A", |
| 828 | "void A(int a) throw(int)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 832 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 833 | "class ZZ {};" |
| 834 | "struct Z {" |
| 835 | " void A(int a) throw(ZZ, int);" |
| 836 | "};", |
| 837 | "A", |
| 838 | "void A(int a) throw(ZZ, int)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification4) { |
| 842 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 843 | "struct Z {" |
| 844 | " void A(int a) noexcept;" |
| 845 | "};", |
| 846 | "A", |
| 847 | "void A(int a) noexcept")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification5) { |
| 851 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 852 | "struct Z {" |
| 853 | " void A(int a) noexcept(true);" |
| 854 | "};", |
| 855 | "A", |
| 856 | "void A(int a) noexcept(trueA(int a) noexcept(true)")); |
| 857 | // WRONG; Should be: "void A(int a) noexcept(true);" |
| 858 | } |
| 859 | |
| 860 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) { |
| 861 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 862 | "struct Z {" |
| 863 | " void A(int a) noexcept(1 < 2);" |
| 864 | "};", |
| 865 | "A", |
| 866 | "void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)")); |
| 867 | // WRONG; Should be: "void A(int a) noexcept(1 < 2);" |
| 868 | } |
| 869 | |
| 870 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) { |
| 871 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 872 | "template<int N>" |
| 873 | "struct Z {" |
| 874 | " void A(int a) noexcept(N < 2);" |
| 875 | "};", |
| 876 | "A", |
| 877 | "void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)")); |
| 878 | // WRONG; Should be: "void A(int a) noexcept(N < 2);" |
| 879 | } |
| 880 | |
| 881 | TEST(DeclPrinter, TestVarDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 882 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 883 | "char *const (*(*A)[5])(int);", |
| 884 | "A", |
| 885 | "char *const (*(*A)[5])(int)")); |
| 886 | // Should be: with semicolon |
| 887 | } |
| 888 | |
| 889 | TEST(DeclPrinter, TestVarDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 890 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 891 | "void (*A)() throw(int);", |
| 892 | "A", |
| 893 | "void (*A)() throw(int)")); |
| 894 | // Should be: with semicolon |
| 895 | } |
| 896 | |
| 897 | TEST(DeclPrinter, TestVarDecl3) { |
| 898 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 899 | "void (*A)() noexcept;", |
| 900 | "A", |
| 901 | "void (*A)() noexcept")); |
| 902 | // Should be: with semicolon |
| 903 | } |
| 904 | |
| 905 | TEST(DeclPrinter, TestFieldDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 906 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 907 | "template<typename T>" |
| 908 | "struct Z { T A; };", |
| 909 | "A", |
| 910 | "T A")); |
| 911 | // Should be: with semicolon |
| 912 | } |
| 913 | |
| 914 | TEST(DeclPrinter, TestFieldDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 915 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 916 | "template<int N>" |
| 917 | "struct Z { int A[N]; };", |
| 918 | "A", |
| 919 | "int A[N]")); |
| 920 | // Should be: with semicolon |
| 921 | } |
| 922 | |
| 923 | TEST(DeclPrinter, TestClassTemplateDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 924 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 925 | "template<typename T>" |
| 926 | "struct A { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 927 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 928 | "template <typename T> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | TEST(DeclPrinter, TestClassTemplateDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 932 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 933 | "template<typename T = int>" |
| 934 | "struct A { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 935 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 936 | "template <typename T = int> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | TEST(DeclPrinter, TestClassTemplateDecl3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 940 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 941 | "template<class T>" |
| 942 | "struct A { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 943 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 944 | "template <class T> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | TEST(DeclPrinter, TestClassTemplateDecl4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 948 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 949 | "template<typename T, typename U>" |
| 950 | "struct A { T a; U b; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 951 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 952 | "template <typename T, typename U> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | TEST(DeclPrinter, TestClassTemplateDecl5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 956 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 957 | "template<int N>" |
| 958 | "struct A { int a[N]; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 959 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 960 | "template <int N> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | TEST(DeclPrinter, TestClassTemplateDecl6) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 964 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 965 | "template<int N = 42>" |
| 966 | "struct A { int a[N]; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 967 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 968 | "template <int N = 42> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | TEST(DeclPrinter, TestClassTemplateDecl7) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 972 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 973 | "typedef int MyInt;" |
| 974 | "template<MyInt N>" |
| 975 | "struct A { int a[N]; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 976 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 977 | "template <MyInt N> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | TEST(DeclPrinter, TestClassTemplateDecl8) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 981 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 982 | "template<template<typename U> class T> struct A { };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 983 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 984 | "template <template <typename U> class T> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | TEST(DeclPrinter, TestClassTemplateDecl9) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 988 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 989 | "template<typename T> struct Z { };" |
| 990 | "template<template<typename U> class T = Z> struct A { };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 991 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 992 | "template <template <typename U> class T> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | TEST(DeclPrinter, TestClassTemplateDecl10) { |
| 996 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 997 | "template<typename... T>" |
| 998 | "struct A { int a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 999 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 1000 | "template <typename ...T> struct A {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | TEST(DeclPrinter, TestClassTemplateDecl11) { |
| 1004 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1005 | "template<typename... T>" |
| 1006 | "struct A : public T... { int a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1007 | classTemplateDecl(hasName("A")).bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 1008 | "template <typename ...T> struct A : public T... {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1012 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1013 | "template<typename T, typename U>" |
| 1014 | "struct A { T a; U b; };" |
| 1015 | "template<typename T>" |
| 1016 | "struct A<T, int> { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1017 | classTemplateSpecializationDecl().bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 1018 | "template <typename T> struct A<T, int> {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1022 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1023 | "template<typename T>" |
| 1024 | "struct A { T a; };" |
| 1025 | "template<typename T>" |
| 1026 | "struct A<T *> { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1027 | classTemplateSpecializationDecl().bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 1028 | "template <typename T> struct A<type-parameter-0-0 *> {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1029 | // WRONG; Should be: "template<typename T> struct A<T *> { ... }" |
| 1030 | } |
| 1031 | |
| 1032 | TEST(DeclPrinter, TestClassTemplateSpecializationDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1033 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1034 | "template<typename T>" |
| 1035 | "struct A { T a; };" |
| 1036 | "template<>" |
| 1037 | "struct A<int> { int a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1038 | classTemplateSpecializationDecl().bind("id"), |
Serge Pavlov | a67a4d2 | 2016-11-10 08:49:37 +0000 | [diff] [blame] | 1039 | "template<> struct A<int> {}")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | TEST(DeclPrinter, TestFunctionTemplateDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1043 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1044 | "template<typename T>" |
| 1045 | "void A(T &t);", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1046 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1047 | "template <typename T> void A(T &t)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | TEST(DeclPrinter, TestFunctionTemplateDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1051 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1052 | "template<typename T>" |
| 1053 | "void A(T &t) { }", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1054 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 1055 | "template <typename T> void A(T &t)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | TEST(DeclPrinter, TestFunctionTemplateDecl3) { |
| 1059 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1060 | "template<typename... T>" |
| 1061 | "void A(T... a);", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1062 | functionTemplateDecl(hasName("A")).bind("id"), |
Richard Smith | a4bb292 | 2014-07-23 03:17:06 +0000 | [diff] [blame] | 1063 | "template <typename ...T> void A(T ...a)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | TEST(DeclPrinter, TestFunctionTemplateDecl4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1067 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1068 | "struct Z { template<typename T> void A(T t); };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1069 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1070 | "template <typename T> void A(T t)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | TEST(DeclPrinter, TestFunctionTemplateDecl5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1074 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1075 | "struct Z { template<typename T> void A(T t) {} };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1076 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 1077 | "template <typename T> void A(T t)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | TEST(DeclPrinter, TestFunctionTemplateDecl6) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1081 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1082 | "template<typename T >struct Z {" |
| 1083 | " template<typename U> void A(U t) {}" |
| 1084 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1085 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 1086 | "template <typename U> void A(U t)")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | TEST(DeclPrinter, TestTemplateArgumentList1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1090 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1091 | "template<typename T> struct Z {};" |
| 1092 | "struct X {};" |
| 1093 | "Z<X> A;", |
| 1094 | "A", |
| 1095 | "Z<X> A")); |
| 1096 | // Should be: with semicolon |
| 1097 | } |
| 1098 | |
| 1099 | TEST(DeclPrinter, TestTemplateArgumentList2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1100 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1101 | "template<typename T, typename U> struct Z {};" |
| 1102 | "struct X {};" |
| 1103 | "typedef int Y;" |
| 1104 | "Z<X, Y> A;", |
| 1105 | "A", |
| 1106 | "Z<X, Y> A")); |
| 1107 | // Should be: with semicolon |
| 1108 | } |
| 1109 | |
| 1110 | TEST(DeclPrinter, TestTemplateArgumentList3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1111 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1112 | "template<typename T> struct Z {};" |
| 1113 | "template<typename T> struct X {};" |
| 1114 | "Z<X<int> > A;", |
| 1115 | "A", |
| 1116 | "Z<X<int> > A")); |
| 1117 | // Should be: with semicolon |
| 1118 | } |
| 1119 | |
| 1120 | TEST(DeclPrinter, TestTemplateArgumentList4) { |
| 1121 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1122 | "template<typename T> struct Z {};" |
| 1123 | "template<typename T> struct X {};" |
| 1124 | "Z<X<int>> A;", |
| 1125 | "A", |
| 1126 | "Z<X<int> > A")); |
| 1127 | // Should be: with semicolon, without extra space in "> >" |
| 1128 | } |
| 1129 | |
| 1130 | TEST(DeclPrinter, TestTemplateArgumentList5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1131 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1132 | "template<typename T> struct Z {};" |
| 1133 | "template<typename T> struct X { Z<T> A; };", |
| 1134 | "A", |
| 1135 | "Z<T> A")); |
| 1136 | // Should be: with semicolon |
| 1137 | } |
| 1138 | |
| 1139 | TEST(DeclPrinter, TestTemplateArgumentList6) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1140 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1141 | "template<template<typename T> class U> struct Z {};" |
| 1142 | "template<typename T> struct X {};" |
| 1143 | "Z<X> A;", |
| 1144 | "A", |
| 1145 | "Z<X> A")); |
| 1146 | // Should be: with semicolon |
| 1147 | } |
| 1148 | |
| 1149 | TEST(DeclPrinter, TestTemplateArgumentList7) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1150 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1151 | "template<template<typename T> class U> struct Z {};" |
| 1152 | "template<template<typename T> class U> struct Y {" |
| 1153 | " Z<U> A;" |
| 1154 | "};", |
| 1155 | "A", |
| 1156 | "Z<U> A")); |
| 1157 | // Should be: with semicolon |
| 1158 | } |
| 1159 | |
| 1160 | TEST(DeclPrinter, TestTemplateArgumentList8) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1161 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1162 | "template<typename T> struct Z {};" |
| 1163 | "template<template<typename T> class U> struct Y {" |
| 1164 | " Z<U<int> > A;" |
| 1165 | "};", |
| 1166 | "A", |
| 1167 | "Z<U<int> > A")); |
| 1168 | // Should be: with semicolon |
| 1169 | } |
| 1170 | |
| 1171 | TEST(DeclPrinter, TestTemplateArgumentList9) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1172 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1173 | "template<unsigned I> struct Z {};" |
| 1174 | "Z<0> A;", |
| 1175 | "A", |
| 1176 | "Z<0> A")); |
| 1177 | // Should be: with semicolon |
| 1178 | } |
| 1179 | |
| 1180 | TEST(DeclPrinter, TestTemplateArgumentList10) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1181 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1182 | "template<unsigned I> struct Z {};" |
| 1183 | "template<unsigned I> struct X { Z<I> A; };", |
| 1184 | "A", |
| 1185 | "Z<I> A")); |
| 1186 | // Should be: with semicolon |
| 1187 | } |
| 1188 | |
| 1189 | TEST(DeclPrinter, TestTemplateArgumentList11) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1190 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1191 | "template<int I> struct Z {};" |
| 1192 | "Z<42 * 10 - 420 / 1> A;", |
| 1193 | "A", |
| 1194 | "Z<42 * 10 - 420 / 1> A")); |
| 1195 | // Should be: with semicolon |
| 1196 | } |
| 1197 | |
| 1198 | TEST(DeclPrinter, TestTemplateArgumentList12) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1199 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1200 | "template<const char *p> struct Z {};" |
| 1201 | "extern const char X[] = \"aaa\";" |
| 1202 | "Z<X> A;", |
| 1203 | "A", |
| 1204 | "Z<X> A")); |
| 1205 | // Should be: with semicolon |
| 1206 | } |
| 1207 | |
| 1208 | TEST(DeclPrinter, TestTemplateArgumentList13) { |
| 1209 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1210 | "template<typename... T> struct Z {};" |
| 1211 | "template<typename... T> struct X {" |
| 1212 | " Z<T...> A;" |
| 1213 | "};", |
| 1214 | "A", |
| 1215 | "Z<T...> A")); |
Richard Smith | a4bb292 | 2014-07-23 03:17:06 +0000 | [diff] [blame] | 1216 | // Should be: with semicolon |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | TEST(DeclPrinter, TestTemplateArgumentList14) { |
| 1220 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1221 | "template<typename... T> struct Z {};" |
| 1222 | "template<typename T> struct Y {};" |
| 1223 | "template<typename... T> struct X {" |
| 1224 | " Z<Y<T>...> A;" |
| 1225 | "};", |
| 1226 | "A", |
| 1227 | "Z<Y<T>...> A")); |
Richard Smith | a4bb292 | 2014-07-23 03:17:06 +0000 | [diff] [blame] | 1228 | // Should be: with semicolon |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | TEST(DeclPrinter, TestTemplateArgumentList15) { |
| 1232 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1233 | "template<unsigned I> struct Z {};" |
| 1234 | "template<typename... T> struct X {" |
| 1235 | " Z<sizeof...(T)> A;" |
| 1236 | "};", |
| 1237 | "A", |
| 1238 | "Z<sizeof...(T)> A")); |
Richard Smith | a4bb292 | 2014-07-23 03:17:06 +0000 | [diff] [blame] | 1239 | // Should be: with semicolon |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1240 | } |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1241 | |
David Majnemer | 8423df9 | 2015-06-05 22:40:53 +0000 | [diff] [blame] | 1242 | TEST(DeclPrinter, TestStaticAssert1) { |
| 1243 | ASSERT_TRUE(PrintedDeclCXX1ZMatches( |
| 1244 | "static_assert(true);", |
| 1245 | staticAssertDecl().bind("id"), |
| 1246 | "static_assert(true)")); |
| 1247 | } |
| 1248 | |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 1249 | TEST(DeclPrinter, TestObjCMethod1) { |
| 1250 | ASSERT_TRUE(PrintedDeclObjCMatches( |
| 1251 | "__attribute__((objc_root_class)) @interface X\n" |
| 1252 | "- (int)A:(id)anObject inRange:(long)range;\n" |
| 1253 | "@end\n" |
| 1254 | "@implementation X\n" |
| 1255 | "- (int)A:(id)anObject inRange:(long)range { int printThis; return 0; }\n" |
| 1256 | "@end\n", |
| 1257 | namedDecl(hasName("A:inRange:"), |
| 1258 | hasDescendant(namedDecl(hasName("printThis")))).bind("id"), |
Alex Lorenz | bbf4f70 | 2017-06-02 15:02:59 +0000 | [diff] [blame] | 1259 | "- (int)A:(id)anObject inRange:(long)range")); |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Fariborz Jahanian | 4419449 | 2012-12-20 02:20:09 +0000 | [diff] [blame] | 1262 | TEST(DeclPrinter, TestObjCProtocol1) { |
| 1263 | ASSERT_TRUE(PrintedDeclObjCMatches( |
| 1264 | "@protocol P1, P2;", |
| 1265 | namedDecl(hasName("P1")).bind("id"), |
| 1266 | "@protocol P1;\n")); |
| 1267 | ASSERT_TRUE(PrintedDeclObjCMatches( |
| 1268 | "@protocol P1, P2;", |
| 1269 | namedDecl(hasName("P2")).bind("id"), |
| 1270 | "@protocol P2;\n")); |
| 1271 | } |
| 1272 | |
| 1273 | TEST(DeclPrinter, TestObjCProtocol2) { |
| 1274 | ASSERT_TRUE(PrintedDeclObjCMatches( |
| 1275 | "@protocol P2 @end" |
| 1276 | "@protocol P1<P2> @end", |
| 1277 | namedDecl(hasName("P1")).bind("id"), |
| 1278 | "@protocol P1<P2>\n@end")); |
| 1279 | } |