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