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