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)...")); |
Benjamin Kramer | 594802f | 2014-02-26 10:23:43 +0000 | [diff] [blame^] | 522 | // WRONG; Should be: "A(T&&... ts) : T(ts)..." |
Dmitri Gribenko | 340c0f6 | 2012-08-24 00:26:25 +0000 | [diff] [blame] | 523 | } |
Dmitri Gribenko | 340c0f6 | 2012-08-24 00:26:25 +0000 | [diff] [blame] | 524 | |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 525 | TEST(DeclPrinter, TestCXXDestructorDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 526 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 527 | "struct A {" |
| 528 | " ~A();" |
| 529 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 530 | destructorDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 531 | "~A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | TEST(DeclPrinter, TestCXXDestructorDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 535 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 536 | "struct A {" |
| 537 | " virtual ~A();" |
| 538 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 539 | destructorDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 540 | "virtual ~A()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | TEST(DeclPrinter, TestCXXConversionDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 544 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 545 | "struct A {" |
| 546 | " operator int();" |
| 547 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 548 | methodDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 549 | "operator int()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | TEST(DeclPrinter, TestCXXConversionDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 553 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 554 | "struct A {" |
| 555 | " operator bool();" |
| 556 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 557 | methodDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 558 | "operator bool()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | TEST(DeclPrinter, TestCXXConversionDecl3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 562 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 563 | "struct Z {};" |
| 564 | "struct A {" |
| 565 | " operator Z();" |
| 566 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 567 | methodDecl(ofClass(hasName("A"))).bind("id"), |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 568 | "operator Z()")); |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 572 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 573 | "namespace std { typedef decltype(sizeof(int)) size_t; }" |
| 574 | "struct Z {" |
| 575 | " void *operator new(std::size_t);" |
| 576 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 577 | methodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 578 | "void *operator new(std::size_t)")); |
| 579 | // Should be: with semicolon |
| 580 | } |
| 581 | |
| 582 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 583 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 584 | "namespace std { typedef decltype(sizeof(int)) size_t; }" |
| 585 | "struct Z {" |
| 586 | " void *operator new[](std::size_t);" |
| 587 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 588 | methodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 589 | "void *operator new[](std::size_t)")); |
| 590 | // Should be: with semicolon |
| 591 | } |
| 592 | |
| 593 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 594 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 595 | "struct Z {" |
| 596 | " void operator delete(void *);" |
| 597 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 598 | methodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 599 | "void operator delete(void *) noexcept")); |
| 600 | // Should be: with semicolon, without noexcept? |
| 601 | } |
| 602 | |
| 603 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 604 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 605 | "struct Z {" |
| 606 | " void operator delete(void *);" |
| 607 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 608 | methodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 609 | "void operator delete(void *)")); |
| 610 | // Should be: with semicolon |
| 611 | } |
| 612 | |
| 613 | TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 614 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 615 | "struct Z {" |
| 616 | " void operator delete[](void *);" |
| 617 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 618 | methodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 619 | "void operator delete[](void *) noexcept")); |
| 620 | // Should be: with semicolon, without noexcept? |
| 621 | } |
| 622 | |
| 623 | TEST(DeclPrinter, TestCXXMethodDecl_Operator1) { |
| 624 | const char *OperatorNames[] = { |
| 625 | "+", "-", "*", "/", "%", "^", "&", "|", |
| 626 | "=", "<", ">", "+=", "-=", "*=", "/=", "%=", |
| 627 | "^=", "&=", "|=", "<<", ">>", ">>=", "<<=", "==", "!=", |
| 628 | "<=", ">=", "&&", "||", ",", "->*", |
| 629 | "()", "[]" |
| 630 | }; |
| 631 | |
| 632 | for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) { |
| 633 | SmallString<128> Code; |
| 634 | Code.append("struct Z { void operator"); |
| 635 | Code.append(OperatorNames[i]); |
| 636 | Code.append("(Z z); };"); |
| 637 | |
| 638 | SmallString<128> Expected; |
| 639 | Expected.append("void operator"); |
| 640 | Expected.append(OperatorNames[i]); |
| 641 | Expected.append("(Z z)"); |
| 642 | // Should be: with semicolon |
| 643 | |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 644 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 645 | Code, |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 646 | methodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 647 | Expected)); |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | TEST(DeclPrinter, TestCXXMethodDecl_Operator2) { |
| 652 | const char *OperatorNames[] = { |
| 653 | "~", "!", "++", "--", "->" |
| 654 | }; |
| 655 | |
| 656 | for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) { |
| 657 | SmallString<128> Code; |
| 658 | Code.append("struct Z { void operator"); |
| 659 | Code.append(OperatorNames[i]); |
| 660 | Code.append("(); };"); |
| 661 | |
| 662 | SmallString<128> Expected; |
| 663 | Expected.append("void operator"); |
| 664 | Expected.append(OperatorNames[i]); |
| 665 | Expected.append("()"); |
| 666 | // Should be: with semicolon |
| 667 | |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 668 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 669 | Code, |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 670 | methodDecl(ofClass(hasName("Z"))).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 671 | Expected)); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | TEST(DeclPrinter, TestCXXMethodDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 676 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 677 | "struct Z {" |
| 678 | " void A(int a);" |
| 679 | "};", |
| 680 | "A", |
| 681 | "void A(int a)")); |
| 682 | // Should be: with semicolon |
| 683 | } |
| 684 | |
| 685 | TEST(DeclPrinter, TestCXXMethodDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 686 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 687 | "struct Z {" |
| 688 | " virtual void A(int a);" |
| 689 | "};", |
| 690 | "A", |
| 691 | "virtual void A(int a)")); |
| 692 | // Should be: with semicolon |
| 693 | } |
| 694 | |
| 695 | TEST(DeclPrinter, TestCXXMethodDecl3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 696 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 697 | "struct Z {" |
| 698 | " virtual void A(int a);" |
| 699 | "};" |
| 700 | "struct ZZ : Z {" |
| 701 | " void A(int a);" |
| 702 | "};", |
| 703 | "ZZ::A", |
| 704 | "void A(int a)")); |
| 705 | // Should be: with semicolon |
| 706 | // TODO: should we print "virtual"? |
| 707 | } |
| 708 | |
| 709 | TEST(DeclPrinter, TestCXXMethodDecl4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 710 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 711 | "struct Z {" |
| 712 | " inline void A(int a);" |
| 713 | "};", |
| 714 | "A", |
| 715 | "inline void A(int a)")); |
| 716 | // Should be: with semicolon |
| 717 | } |
| 718 | |
| 719 | TEST(DeclPrinter, TestCXXMethodDecl5) { |
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 | " virtual void A(int a) = 0;" |
| 723 | "};", |
| 724 | "A", |
| 725 | "virtual void A(int a) = 0")); |
| 726 | // Should be: with semicolon |
| 727 | } |
| 728 | |
| 729 | TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 730 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 731 | "struct Z {" |
| 732 | " void A(int a) const;" |
| 733 | "};", |
| 734 | "A", |
| 735 | "void A(int a) const")); |
| 736 | // Should be: with semicolon |
| 737 | } |
| 738 | |
| 739 | TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 740 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 741 | "struct Z {" |
| 742 | " void A(int a) volatile;" |
| 743 | "};", |
| 744 | "A", |
| 745 | "void A(int a) volatile")); |
| 746 | // Should be: with semicolon |
| 747 | } |
| 748 | |
| 749 | TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 750 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 751 | "struct Z {" |
| 752 | " void A(int a) const volatile;" |
| 753 | "};", |
| 754 | "A", |
| 755 | "void A(int a) const volatile")); |
| 756 | // Should be: with semicolon |
| 757 | } |
| 758 | |
| 759 | TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) { |
| 760 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 761 | "struct Z {" |
| 762 | " void A(int a) &;" |
| 763 | "};", |
| 764 | "A", |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 765 | "void A(int a) &")); |
| 766 | // Should be: with semicolon |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) { |
| 770 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 771 | "struct Z {" |
| 772 | " void A(int a) &&;" |
| 773 | "};", |
| 774 | "A", |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 775 | "void A(int a) &&")); |
| 776 | // Should be: with semicolon |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 780 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 781 | "struct Z {" |
| 782 | " void A(int a) throw();" |
| 783 | "};", |
| 784 | "A", |
| 785 | "void A(int a) throw()")); |
| 786 | // Should be: with semicolon |
| 787 | } |
| 788 | |
| 789 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 790 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 791 | "struct Z {" |
| 792 | " void A(int a) throw(int);" |
| 793 | "};", |
| 794 | "A", |
| 795 | "void A(int a) throw(int)")); |
| 796 | // Should be: with semicolon |
| 797 | } |
| 798 | |
| 799 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 800 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 801 | "class ZZ {};" |
| 802 | "struct Z {" |
| 803 | " void A(int a) throw(ZZ, int);" |
| 804 | "};", |
| 805 | "A", |
| 806 | "void A(int a) throw(ZZ, int)")); |
| 807 | // Should be: with semicolon |
| 808 | } |
| 809 | |
| 810 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification4) { |
| 811 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 812 | "struct Z {" |
| 813 | " void A(int a) noexcept;" |
| 814 | "};", |
| 815 | "A", |
| 816 | "void A(int a) noexcept")); |
| 817 | // Should be: with semicolon |
| 818 | } |
| 819 | |
| 820 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification5) { |
| 821 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 822 | "struct Z {" |
| 823 | " void A(int a) noexcept(true);" |
| 824 | "};", |
| 825 | "A", |
| 826 | "void A(int a) noexcept(trueA(int a) noexcept(true)")); |
| 827 | // WRONG; Should be: "void A(int a) noexcept(true);" |
| 828 | } |
| 829 | |
| 830 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) { |
| 831 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 832 | "struct Z {" |
| 833 | " void A(int a) noexcept(1 < 2);" |
| 834 | "};", |
| 835 | "A", |
| 836 | "void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)")); |
| 837 | // WRONG; Should be: "void A(int a) noexcept(1 < 2);" |
| 838 | } |
| 839 | |
| 840 | TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) { |
| 841 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 842 | "template<int N>" |
| 843 | "struct Z {" |
| 844 | " void A(int a) noexcept(N < 2);" |
| 845 | "};", |
| 846 | "A", |
| 847 | "void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)")); |
| 848 | // WRONG; Should be: "void A(int a) noexcept(N < 2);" |
| 849 | } |
| 850 | |
| 851 | TEST(DeclPrinter, TestVarDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 852 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 853 | "char *const (*(*A)[5])(int);", |
| 854 | "A", |
| 855 | "char *const (*(*A)[5])(int)")); |
| 856 | // Should be: with semicolon |
| 857 | } |
| 858 | |
| 859 | TEST(DeclPrinter, TestVarDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 860 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 861 | "void (*A)() throw(int);", |
| 862 | "A", |
| 863 | "void (*A)() throw(int)")); |
| 864 | // Should be: with semicolon |
| 865 | } |
| 866 | |
| 867 | TEST(DeclPrinter, TestVarDecl3) { |
| 868 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 869 | "void (*A)() noexcept;", |
| 870 | "A", |
| 871 | "void (*A)() noexcept")); |
| 872 | // Should be: with semicolon |
| 873 | } |
| 874 | |
| 875 | TEST(DeclPrinter, TestFieldDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 876 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 877 | "template<typename T>" |
| 878 | "struct Z { T A; };", |
| 879 | "A", |
| 880 | "T A")); |
| 881 | // Should be: with semicolon |
| 882 | } |
| 883 | |
| 884 | TEST(DeclPrinter, TestFieldDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 885 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 886 | "template<int N>" |
| 887 | "struct Z { int A[N]; };", |
| 888 | "A", |
| 889 | "int A[N]")); |
| 890 | // Should be: with semicolon |
| 891 | } |
| 892 | |
| 893 | TEST(DeclPrinter, TestClassTemplateDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 894 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 895 | "template<typename T>" |
| 896 | "struct A { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 897 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 898 | "template <typename T> struct A {\n}")); |
| 899 | // Should be: with semicolon, with { ... } |
| 900 | } |
| 901 | |
| 902 | TEST(DeclPrinter, TestClassTemplateDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 903 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 904 | "template<typename T = int>" |
| 905 | "struct A { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 906 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 907 | "template <typename T = int> struct A {\n}")); |
| 908 | // Should be: with semicolon, with { ... } |
| 909 | } |
| 910 | |
| 911 | TEST(DeclPrinter, TestClassTemplateDecl3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 912 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 913 | "template<class T>" |
| 914 | "struct A { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 915 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 916 | "template <class T> struct A {\n}")); |
| 917 | // Should be: with semicolon, with { ... } |
| 918 | } |
| 919 | |
| 920 | TEST(DeclPrinter, TestClassTemplateDecl4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 921 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 922 | "template<typename T, typename U>" |
| 923 | "struct A { T a; U b; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 924 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 925 | "template <typename T, typename U> struct A {\n}")); |
| 926 | // Should be: with semicolon, with { ... } |
| 927 | } |
| 928 | |
| 929 | TEST(DeclPrinter, TestClassTemplateDecl5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 930 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 931 | "template<int N>" |
| 932 | "struct A { int a[N]; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 933 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 934 | "template <int N> struct A {\n}")); |
| 935 | // Should be: with semicolon, with { ... } |
| 936 | } |
| 937 | |
| 938 | TEST(DeclPrinter, TestClassTemplateDecl6) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 939 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 940 | "template<int N = 42>" |
| 941 | "struct A { int a[N]; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 942 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 943 | "template <int N = 42> struct A {\n}")); |
| 944 | // Should be: with semicolon, with { ... } |
| 945 | } |
| 946 | |
| 947 | TEST(DeclPrinter, TestClassTemplateDecl7) { |
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 | "typedef int MyInt;" |
| 950 | "template<MyInt N>" |
| 951 | "struct A { int a[N]; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 952 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 953 | "template <MyInt N> struct A {\n}")); |
| 954 | // Should be: with semicolon, with { ... } |
| 955 | } |
| 956 | |
| 957 | TEST(DeclPrinter, TestClassTemplateDecl8) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 958 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 959 | "template<template<typename U> class T> struct A { };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 960 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 961 | "template <template <typename U> class T> struct A {\n}")); |
| 962 | // Should be: with semicolon, with { ... } |
| 963 | } |
| 964 | |
| 965 | TEST(DeclPrinter, TestClassTemplateDecl9) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 966 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 967 | "template<typename T> struct Z { };" |
| 968 | "template<template<typename U> class T = Z> struct A { };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 969 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 970 | "template <template <typename U> class T> struct A {\n}")); |
| 971 | // Should be: with semicolon, with { ... } |
| 972 | } |
| 973 | |
| 974 | TEST(DeclPrinter, TestClassTemplateDecl10) { |
| 975 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 976 | "template<typename... T>" |
| 977 | "struct A { int a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 978 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 979 | "template <typename ... T> struct A {\n}")); |
| 980 | // Should be: with semicolon, with { ... }, without spaces before '...' |
| 981 | } |
| 982 | |
| 983 | TEST(DeclPrinter, TestClassTemplateDecl11) { |
| 984 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 985 | "template<typename... T>" |
| 986 | "struct A : public T... { int a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 987 | classTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 988 | "template <typename ... T> struct A : public T... {\n}")); |
| 989 | // Should be: with semicolon, with { ... }, without spaces before '...' |
| 990 | } |
| 991 | |
| 992 | TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 993 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 994 | "template<typename T, typename U>" |
| 995 | "struct A { T a; U b; };" |
| 996 | "template<typename T>" |
| 997 | "struct A<T, int> { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 998 | classTemplateSpecializationDecl().bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 999 | "struct A {\n}")); |
| 1000 | // WRONG; Should be: "template<typename T> struct A<T, int> { ... }" |
| 1001 | } |
| 1002 | |
| 1003 | TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1004 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1005 | "template<typename T>" |
| 1006 | "struct A { T a; };" |
| 1007 | "template<typename T>" |
| 1008 | "struct A<T *> { T a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1009 | classTemplateSpecializationDecl().bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1010 | "struct A {\n}")); |
| 1011 | // WRONG; Should be: "template<typename T> struct A<T *> { ... }" |
| 1012 | } |
| 1013 | |
| 1014 | TEST(DeclPrinter, TestClassTemplateSpecializationDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1015 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1016 | "template<typename T>" |
| 1017 | "struct A { T a; };" |
| 1018 | "template<>" |
| 1019 | "struct A<int> { int a; };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1020 | classTemplateSpecializationDecl().bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1021 | "struct A {\n}")); |
| 1022 | // WRONG; Should be: "template<> struct A<int> { ... }" |
| 1023 | } |
| 1024 | |
| 1025 | TEST(DeclPrinter, TestFunctionTemplateDecl1) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1026 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1027 | "template<typename T>" |
| 1028 | "void A(T &t);", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1029 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1030 | "template <typename T> void A(T &t)")); |
| 1031 | // Should be: with semicolon |
| 1032 | } |
| 1033 | |
| 1034 | TEST(DeclPrinter, TestFunctionTemplateDecl2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1035 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1036 | "template<typename T>" |
| 1037 | "void A(T &t) { }", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1038 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 1039 | "template <typename T> void A(T &t)")); |
| 1040 | // Should be: with semicolon |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | TEST(DeclPrinter, TestFunctionTemplateDecl3) { |
| 1044 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1045 | "template<typename... T>" |
| 1046 | "void A(T... a);", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1047 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1048 | "template <typename ... T> void A(T a...)")); |
| 1049 | // WRONG; Should be: "template <typename ... T> void A(T... a)" |
| 1050 | // (not "T a...") |
| 1051 | // Should be: with semicolon. |
| 1052 | } |
| 1053 | |
| 1054 | TEST(DeclPrinter, TestFunctionTemplateDecl4) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1055 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1056 | "struct Z { template<typename T> void A(T t); };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1057 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1058 | "template <typename T> void A(T t)")); |
| 1059 | // Should be: with semicolon |
| 1060 | } |
| 1061 | |
| 1062 | TEST(DeclPrinter, TestFunctionTemplateDecl5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1063 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1064 | "struct Z { template<typename T> void A(T t) {} };", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1065 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 1066 | "template <typename T> void A(T t)")); |
| 1067 | // Should be: with semicolon |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | TEST(DeclPrinter, TestFunctionTemplateDecl6) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1071 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1072 | "template<typename T >struct Z {" |
| 1073 | " template<typename U> void A(U t) {}" |
| 1074 | "};", |
Daniel Jasper | bd3d76d | 2012-08-24 05:12:34 +0000 | [diff] [blame] | 1075 | functionTemplateDecl(hasName("A")).bind("id"), |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 1076 | "template <typename U> void A(U t)")); |
| 1077 | // Should be: with semicolon |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | TEST(DeclPrinter, TestTemplateArgumentList1) { |
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 | "struct X {};" |
| 1084 | "Z<X> A;", |
| 1085 | "A", |
| 1086 | "Z<X> A")); |
| 1087 | // Should be: with semicolon |
| 1088 | } |
| 1089 | |
| 1090 | TEST(DeclPrinter, TestTemplateArgumentList2) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1091 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1092 | "template<typename T, typename U> struct Z {};" |
| 1093 | "struct X {};" |
| 1094 | "typedef int Y;" |
| 1095 | "Z<X, Y> A;", |
| 1096 | "A", |
| 1097 | "Z<X, Y> A")); |
| 1098 | // Should be: with semicolon |
| 1099 | } |
| 1100 | |
| 1101 | TEST(DeclPrinter, TestTemplateArgumentList3) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1102 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1103 | "template<typename T> struct Z {};" |
| 1104 | "template<typename T> struct X {};" |
| 1105 | "Z<X<int> > A;", |
| 1106 | "A", |
| 1107 | "Z<X<int> > A")); |
| 1108 | // Should be: with semicolon |
| 1109 | } |
| 1110 | |
| 1111 | TEST(DeclPrinter, TestTemplateArgumentList4) { |
| 1112 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1113 | "template<typename T> struct Z {};" |
| 1114 | "template<typename T> struct X {};" |
| 1115 | "Z<X<int>> A;", |
| 1116 | "A", |
| 1117 | "Z<X<int> > A")); |
| 1118 | // Should be: with semicolon, without extra space in "> >" |
| 1119 | } |
| 1120 | |
| 1121 | TEST(DeclPrinter, TestTemplateArgumentList5) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1122 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1123 | "template<typename T> struct Z {};" |
| 1124 | "template<typename T> struct X { Z<T> A; };", |
| 1125 | "A", |
| 1126 | "Z<T> A")); |
| 1127 | // Should be: with semicolon |
| 1128 | } |
| 1129 | |
| 1130 | TEST(DeclPrinter, TestTemplateArgumentList6) { |
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<template<typename T> class U> struct Z {};" |
| 1133 | "template<typename T> struct X {};" |
| 1134 | "Z<X> A;", |
| 1135 | "A", |
| 1136 | "Z<X> A")); |
| 1137 | // Should be: with semicolon |
| 1138 | } |
| 1139 | |
| 1140 | TEST(DeclPrinter, TestTemplateArgumentList7) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1141 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1142 | "template<template<typename T> class U> struct Z {};" |
| 1143 | "template<template<typename T> class U> struct Y {" |
| 1144 | " Z<U> A;" |
| 1145 | "};", |
| 1146 | "A", |
| 1147 | "Z<U> A")); |
| 1148 | // Should be: with semicolon |
| 1149 | } |
| 1150 | |
| 1151 | TEST(DeclPrinter, TestTemplateArgumentList8) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1152 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1153 | "template<typename T> struct Z {};" |
| 1154 | "template<template<typename T> class U> struct Y {" |
| 1155 | " Z<U<int> > A;" |
| 1156 | "};", |
| 1157 | "A", |
| 1158 | "Z<U<int> > A")); |
| 1159 | // Should be: with semicolon |
| 1160 | } |
| 1161 | |
| 1162 | TEST(DeclPrinter, TestTemplateArgumentList9) { |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1163 | ASSERT_TRUE(PrintedDeclCXX98Matches( |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 1164 | "template<unsigned I> struct Z {};" |
| 1165 | "Z<0> A;", |
| 1166 | "A", |
| 1167 | "Z<0> A")); |
| 1168 | // Should be: with semicolon |
| 1169 | } |
| 1170 | |
| 1171 | TEST(DeclPrinter, TestTemplateArgumentList10) { |
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 | "template<unsigned I> struct X { Z<I> A; };", |
| 1175 | "A", |
| 1176 | "Z<I> A")); |
| 1177 | // Should be: with semicolon |
| 1178 | } |
| 1179 | |
| 1180 | TEST(DeclPrinter, TestTemplateArgumentList11) { |
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<int I> struct Z {};" |
| 1183 | "Z<42 * 10 - 420 / 1> A;", |
| 1184 | "A", |
| 1185 | "Z<42 * 10 - 420 / 1> A")); |
| 1186 | // Should be: with semicolon |
| 1187 | } |
| 1188 | |
| 1189 | TEST(DeclPrinter, TestTemplateArgumentList12) { |
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<const char *p> struct Z {};" |
| 1192 | "extern const char X[] = \"aaa\";" |
| 1193 | "Z<X> A;", |
| 1194 | "A", |
| 1195 | "Z<X> A")); |
| 1196 | // Should be: with semicolon |
| 1197 | } |
| 1198 | |
| 1199 | TEST(DeclPrinter, TestTemplateArgumentList13) { |
| 1200 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1201 | "template<typename... T> struct Z {};" |
| 1202 | "template<typename... T> struct X {" |
| 1203 | " Z<T...> A;" |
| 1204 | "};", |
| 1205 | "A", |
| 1206 | "Z<T...> A")); |
| 1207 | // Should be: with semicolon, without extra space in "> >" |
| 1208 | } |
| 1209 | |
| 1210 | TEST(DeclPrinter, TestTemplateArgumentList14) { |
| 1211 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1212 | "template<typename... T> struct Z {};" |
| 1213 | "template<typename T> struct Y {};" |
| 1214 | "template<typename... T> struct X {" |
| 1215 | " Z<Y<T>...> A;" |
| 1216 | "};", |
| 1217 | "A", |
| 1218 | "Z<Y<T>...> A")); |
| 1219 | // Should be: with semicolon, without extra space in "> >" |
| 1220 | } |
| 1221 | |
| 1222 | TEST(DeclPrinter, TestTemplateArgumentList15) { |
| 1223 | ASSERT_TRUE(PrintedDeclCXX11Matches( |
| 1224 | "template<unsigned I> struct Z {};" |
| 1225 | "template<typename... T> struct X {" |
| 1226 | " Z<sizeof...(T)> A;" |
| 1227 | "};", |
| 1228 | "A", |
| 1229 | "Z<sizeof...(T)> A")); |
| 1230 | // Should be: with semicolon, without extra space in "> >" |
| 1231 | } |
Dmitri Gribenko | bda79e5 | 2012-08-31 03:05:44 +0000 | [diff] [blame] | 1232 | |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 1233 | TEST(DeclPrinter, TestObjCMethod1) { |
| 1234 | ASSERT_TRUE(PrintedDeclObjCMatches( |
| 1235 | "__attribute__((objc_root_class)) @interface X\n" |
| 1236 | "- (int)A:(id)anObject inRange:(long)range;\n" |
| 1237 | "@end\n" |
| 1238 | "@implementation X\n" |
| 1239 | "- (int)A:(id)anObject inRange:(long)range { int printThis; return 0; }\n" |
| 1240 | "@end\n", |
| 1241 | namedDecl(hasName("A:inRange:"), |
| 1242 | hasDescendant(namedDecl(hasName("printThis")))).bind("id"), |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1243 | "- (int) A:(id)anObject inRange:(long)range")); |
Fariborz Jahanian | e0586a5 | 2012-10-18 19:12:17 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Fariborz Jahanian | 4419449 | 2012-12-20 02:20:09 +0000 | [diff] [blame] | 1246 | TEST(DeclPrinter, TestObjCProtocol1) { |
| 1247 | ASSERT_TRUE(PrintedDeclObjCMatches( |
| 1248 | "@protocol P1, P2;", |
| 1249 | namedDecl(hasName("P1")).bind("id"), |
| 1250 | "@protocol P1;\n")); |
| 1251 | ASSERT_TRUE(PrintedDeclObjCMatches( |
| 1252 | "@protocol P1, P2;", |
| 1253 | namedDecl(hasName("P2")).bind("id"), |
| 1254 | "@protocol P2;\n")); |
| 1255 | } |
| 1256 | |
| 1257 | TEST(DeclPrinter, TestObjCProtocol2) { |
| 1258 | ASSERT_TRUE(PrintedDeclObjCMatches( |
| 1259 | "@protocol P2 @end" |
| 1260 | "@protocol P1<P2> @end", |
| 1261 | namedDecl(hasName("P1")).bind("id"), |
| 1262 | "@protocol P1<P2>\n@end")); |
| 1263 | } |