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