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