blob: dc4f91456071c1ca14508070f7ad4038d5ef07da [file] [log] [blame]
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001//===- 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 Jasper6ed1f852012-08-24 05:50:27 +000025#include "llvm/ADT/SmallString.h"
Dmitri Gribenko309856a2012-08-20 23:39:06 +000026#include "gtest/gtest.h"
27
28using namespace clang;
29using namespace ast_matchers;
30using namespace tooling;
31
32namespace {
33
34void PrintDecl(raw_ostream &Out, const ASTContext *Context, const Decl *D) {
35 PrintingPolicy Policy = Context->getPrintingPolicy();
Dmitri Gribenkoa93a7e82012-08-21 17:36:32 +000036 Policy.TerseOutput = true;
Dmitri Gribenko309856a2012-08-20 23:39:06 +000037 D->print(Out, Policy, /*Indentation*/ 0, /*PrintInstantiation*/ false);
38}
39
40class PrintMatch : public MatchFinder::MatchCallback {
41 SmallString<1024> Printed;
42 unsigned NumFoundDecls;
43
44public:
45 PrintMatch() : NumFoundDecls(0) {}
46
Alexander Kornienko34eb2072015-04-11 02:00:23 +000047 void run(const MatchFinder::MatchResult &Result) override {
Dmitri Gribenko309856a2012-08-20 23:39:06 +000048 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 Gribenko309856a2012-08-20 23:39:06 +000068::testing::AssertionResult PrintedDeclMatches(
69 StringRef Code,
Dmitri Gribenko454a43c2012-08-31 03:23:26 +000070 const std::vector<std::string> &Args,
Dmitri Gribenko309856a2012-08-20 23:39:06 +000071 const DeclarationMatcher &NodeMatch,
Fariborz Jahaniane0586a52012-10-18 19:12:17 +000072 StringRef ExpectedPrinted,
73 StringRef FileName) {
Dmitri Gribenko309856a2012-08-20 23:39:06 +000074 PrintMatch Printer;
75 MatchFinder Finder;
76 Finder.addMatcher(NodeMatch, &Printer);
Ahmed Charlesb8984322014-03-07 20:03:18 +000077 std::unique_ptr<FrontendActionFactory> Factory(
78 newFrontendActionFactory(&Finder));
Dmitri Gribenko309856a2012-08-20 23:39:06 +000079
Fariborz Jahaniane0586a52012-10-18 19:12:17 +000080 if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, FileName))
Saleem Abdulrasool8a8454b2014-01-25 20:04:44 +000081 return testing::AssertionFailure()
82 << "Parsing error in \"" << Code.str() << "\"";
Dmitri Gribenko309856a2012-08-20 23:39:06 +000083
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 Abdulrasool8a8454b2014-01-25 20:04:44 +000095 << "Expected \"" << ExpectedPrinted.str() << "\", "
96 "got \"" << Printer.getPrinted().str() << "\"";
Dmitri Gribenko309856a2012-08-20 23:39:06 +000097
98 return ::testing::AssertionSuccess();
99}
100
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000101::testing::AssertionResult PrintedDeclCXX98Matches(StringRef Code,
102 StringRef DeclName,
103 StringRef ExpectedPrinted) {
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000104 std::vector<std::string> Args(1, "-std=c++98");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000105 return PrintedDeclMatches(Code,
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000106 Args,
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000107 namedDecl(hasName(DeclName)).bind("id"),
Fariborz Jahaniane0586a52012-10-18 19:12:17 +0000108 ExpectedPrinted,
109 "input.cc");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000110}
111
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000112::testing::AssertionResult PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000113 StringRef Code,
114 const DeclarationMatcher &NodeMatch,
115 StringRef ExpectedPrinted) {
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000116 std::vector<std::string> Args(1, "-std=c++98");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000117 return PrintedDeclMatches(Code,
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000118 Args,
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000119 NodeMatch,
Fariborz Jahaniane0586a52012-10-18 19:12:17 +0000120 ExpectedPrinted,
121 "input.cc");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000122}
123
124::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code,
125 StringRef DeclName,
126 StringRef ExpectedPrinted) {
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000127 std::vector<std::string> Args(1, "-std=c++11");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000128 return PrintedDeclMatches(Code,
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000129 Args,
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000130 namedDecl(hasName(DeclName)).bind("id"),
Fariborz Jahaniane0586a52012-10-18 19:12:17 +0000131 ExpectedPrinted,
132 "input.cc");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000133}
134
135::testing::AssertionResult PrintedDeclCXX11Matches(
136 StringRef Code,
137 const DeclarationMatcher &NodeMatch,
138 StringRef ExpectedPrinted) {
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000139 std::vector<std::string> Args(1, "-std=c++11");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000140 return PrintedDeclMatches(Code,
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000141 Args,
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000142 NodeMatch,
Fariborz Jahaniane0586a52012-10-18 19:12:17 +0000143 ExpectedPrinted,
144 "input.cc");
145}
146
NAKAMURA Takumi7d2da0b2014-02-16 10:16:09 +0000147::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 Majnemer8423df92015-06-05 22:40:53 +0000160::testing::AssertionResult
161PrintedDeclCXX1ZMatches(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 Jahaniane0586a52012-10-18 19:12:17 +0000171::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 Gribenko309856a2012-08-20 23:39:06 +0000181}
182
183} // unnamed namespace
184
Dmitri Gribenko5ea34fc2014-03-03 13:21:00 +0000185TEST(DeclPrinter, TestTypedef1) {
186 ASSERT_TRUE(PrintedDeclCXX98Matches(
187 "typedef int A;",
188 "A",
189 "typedef int A"));
190 // Should be: with semicolon
191}
192
193TEST(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
201TEST(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
210TEST(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 Gribenko309856a2012-08-20 23:39:06 +0000219TEST(DeclPrinter, TestNamespace1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000220 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000221 "namespace A { int B; }",
222 "A",
223 "namespace A {\n}"));
224 // Should be: with { ... }
225}
226
227TEST(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
235TEST(DeclPrinter, TestNamespaceAlias1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000236 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000237 "namespace Z { }"
238 "namespace A = Z;",
239 "A",
240 "namespace A = Z"));
241 // Should be: with semicolon
242}
243
244TEST(DeclPrinter, TestNamespaceAlias2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000245 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000246 "namespace X { namespace Y {} }"
247 "namespace A = X::Y;",
248 "A",
249 "namespace A = X::Y"));
250 // Should be: with semicolon
251}
252
253TEST(DeclPrinter, TestCXXRecordDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000254 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000255 "class A { int a; };",
256 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000257 "class A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000258}
259
260TEST(DeclPrinter, TestCXXRecordDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000261 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000262 "struct A { int a; };",
263 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000264 "struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000265}
266
267TEST(DeclPrinter, TestCXXRecordDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000268 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000269 "union A { int a; };",
270 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000271 "union A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000272}
273
274TEST(DeclPrinter, TestCXXRecordDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000275 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000276 "class Z { int a; };"
277 "class A : Z { int b; };",
278 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000279 "class A : Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000280}
281
282TEST(DeclPrinter, TestCXXRecordDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000283 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000284 "struct Z { int a; };"
285 "struct A : Z { int b; };",
286 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000287 "struct A : Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000288}
289
290TEST(DeclPrinter, TestCXXRecordDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000291 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000292 "class Z { int a; };"
293 "class A : public Z { int b; };",
294 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000295 "class A : public Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000296}
297
298TEST(DeclPrinter, TestCXXRecordDecl7) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000299 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000300 "class Z { int a; };"
301 "class A : protected Z { int b; };",
302 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000303 "class A : protected Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000304}
305
306TEST(DeclPrinter, TestCXXRecordDecl8) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000307 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000308 "class Z { int a; };"
309 "class A : private Z { int b; };",
310 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000311 "class A : private Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000312}
313
314TEST(DeclPrinter, TestCXXRecordDecl9) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000315 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000316 "class Z { int a; };"
317 "class A : virtual Z { int b; };",
318 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000319 "class A : virtual Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000320}
321
322TEST(DeclPrinter, TestCXXRecordDecl10) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000323 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000324 "class Z { int a; };"
325 "class A : virtual public Z { int b; };",
326 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000327 "class A : virtual public Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000328}
329
330TEST(DeclPrinter, TestCXXRecordDecl11) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000331 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000332 "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 Pavlova67a4d22016-11-10 08:49:37 +0000336 "class A : virtual public Z, private Y {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000337}
338
339TEST(DeclPrinter, TestFunctionDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000340 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000341 "void A();",
342 "A",
343 "void A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000344}
345
346TEST(DeclPrinter, TestFunctionDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000347 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000348 "void A() {}",
349 "A",
350 "void A()"));
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000351}
352
353TEST(DeclPrinter, TestFunctionDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000354 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000355 "void Z();"
356 "void A() { Z(); }",
357 "A",
358 "void A()"));
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000359}
360
361TEST(DeclPrinter, TestFunctionDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000362 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000363 "extern void A();",
364 "A",
365 "extern void A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000366}
367
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000368TEST(DeclPrinter, TestFunctionDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000369 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000370 "static void A();",
371 "A",
372 "static void A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000373}
374
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000375TEST(DeclPrinter, TestFunctionDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000376 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000377 "inline void A();",
378 "A",
379 "inline void A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000380}
381
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000382TEST(DeclPrinter, TestFunctionDecl7) {
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000383 ASSERT_TRUE(PrintedDeclCXX11Matches(
384 "constexpr int A(int a);",
385 "A",
Benjamin Kramer2907b082014-02-25 18:49:49 +0000386 "constexpr int A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000387}
388
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000389TEST(DeclPrinter, TestFunctionDecl8) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000390 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000391 "void A(int a);",
392 "A",
393 "void A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000394}
395
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000396TEST(DeclPrinter, TestFunctionDecl9) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000397 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000398 "void A(...);",
399 "A",
400 "void A(...)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000401}
402
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000403TEST(DeclPrinter, TestFunctionDecl10) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000404 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000405 "void A(int a, ...);",
406 "A",
407 "void A(int a, ...)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000408}
409
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000410TEST(DeclPrinter, TestFunctionDecl11) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000411 ASSERT_TRUE(PrintedDeclCXX98Matches(
David Majnemerd4328de2014-01-14 08:18:49 +0000412 "typedef long ssize_t;"
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000413 "typedef int *pInt;"
David Majnemerd4328de2014-01-14 08:18:49 +0000414 "void A(int a, pInt b, ssize_t c);",
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000415 "A",
David Majnemerd4328de2014-01-14 08:18:49 +0000416 "void A(int a, pInt b, ssize_t c)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000417}
418
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000419TEST(DeclPrinter, TestFunctionDecl12) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000420 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000421 "void A(int a, int b = 0);",
422 "A",
423 "void A(int a, int b = 0)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000424}
425
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000426TEST(DeclPrinter, TestFunctionDecl13) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000427 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000428 "void (*A(int a))(int b);",
429 "A",
430 "void (*A(int a))(int)"));
Serge Pavlova67a4d22016-11-10 08:49:37 +0000431 // Should be: with parameter name (?)
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000432}
433
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000434TEST(DeclPrinter, TestFunctionDecl14) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000435 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000436 "template<typename T>"
437 "void A(T t) { }"
438 "template<>"
439 "void A(int N) { }",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000440 functionDecl(hasName("A"), isExplicitTemplateSpecialization()).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000441 "template<> void A<int>(int N)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000442}
443
444
445TEST(DeclPrinter, TestCXXConstructorDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000446 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000447 "struct A {"
448 " A();"
449 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000450 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000451 "A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000452}
453
454TEST(DeclPrinter, TestCXXConstructorDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000455 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000456 "struct A {"
457 " A(int a);"
458 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000459 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000460 "A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000461}
462
463TEST(DeclPrinter, TestCXXConstructorDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000464 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000465 "struct A {"
466 " A(const A &a);"
467 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000468 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000469 "A(const A &a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000470}
471
472TEST(DeclPrinter, TestCXXConstructorDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000473 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000474 "struct A {"
475 " A(const A &a, int = 0);"
476 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000477 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000478 "A(const A &a, int = 0)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000479}
480
481TEST(DeclPrinter, TestCXXConstructorDecl5) {
482 ASSERT_TRUE(PrintedDeclCXX11Matches(
483 "struct A {"
484 " A(const A &&a);"
485 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000486 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000487 "A(const A &&a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000488}
489
490TEST(DeclPrinter, TestCXXConstructorDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000491 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000492 "struct A {"
493 " explicit A(int a);"
494 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000495 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian69c403c2012-12-05 22:19:06 +0000496 "explicit A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000497}
498
499TEST(DeclPrinter, TestCXXConstructorDecl7) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000500 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000501 "struct A {"
502 " constexpr A();"
503 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000504 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer2907b082014-02-25 18:49:49 +0000505 "constexpr A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000506}
507
508TEST(DeclPrinter, TestCXXConstructorDecl8) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000509 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000510 "struct A {"
511 " A() = default;"
512 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000513 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Richard Smithbd305122012-12-11 01:14:52 +0000514 "A() = default"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000515}
516
517TEST(DeclPrinter, TestCXXConstructorDecl9) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000518 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000519 "struct A {"
520 " A() = delete;"
521 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000522 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000523 "A() = delete"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000524}
525
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000526TEST(DeclPrinter, TestCXXConstructorDecl10) {
527 ASSERT_TRUE(PrintedDeclCXX11Matches(
528 "template<typename... T>"
529 "struct A {"
530 " A(const A &a);"
531 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000532 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000533 "A<T...>(const A<T...> &a)"));
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000534}
535
536TEST(DeclPrinter, TestCXXConstructorDecl11) {
NAKAMURA Takumi7d2da0b2014-02-16 10:16:09 +0000537 ASSERT_TRUE(PrintedDeclCXX11nonMSCMatches(
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000538 "template<typename... T>"
539 "struct A : public T... {"
540 " A(T&&... ts) : T(ts)... {}"
541 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000542 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000543 "A<T...>(T &&...ts) : T(ts)... {}"));
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000544}
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000545
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000546TEST(DeclPrinter, TestCXXDestructorDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000547 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000548 "struct A {"
549 " ~A();"
550 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000551 cxxDestructorDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer2907b082014-02-25 18:49:49 +0000552 "~A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000553}
554
555TEST(DeclPrinter, TestCXXDestructorDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000556 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000557 "struct A {"
558 " virtual ~A();"
559 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000560 cxxDestructorDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer2907b082014-02-25 18:49:49 +0000561 "virtual ~A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000562}
563
564TEST(DeclPrinter, TestCXXConversionDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000565 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000566 "struct A {"
567 " operator int();"
568 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000569 cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000570 "operator int()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000571}
572
573TEST(DeclPrinter, TestCXXConversionDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000574 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000575 "struct A {"
576 " operator bool();"
577 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000578 cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000579 "operator bool()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000580}
581
582TEST(DeclPrinter, TestCXXConversionDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000583 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000584 "struct Z {};"
585 "struct A {"
586 " operator Z();"
587 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000588 cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000589 "operator Z()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000590}
591
592TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000593 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000594 "namespace std { typedef decltype(sizeof(int)) size_t; }"
595 "struct Z {"
596 " void *operator new(std::size_t);"
597 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000598 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000599 "void *operator new(std::size_t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000600}
601
602TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000603 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000604 "namespace std { typedef decltype(sizeof(int)) size_t; }"
605 "struct Z {"
606 " void *operator new[](std::size_t);"
607 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000608 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000609 "void *operator new[](std::size_t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000610}
611
612TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000613 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000614 "struct Z {"
615 " void operator delete(void *);"
616 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000617 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000618 "void operator delete(void *) noexcept"));
Serge Pavlova67a4d22016-11-10 08:49:37 +0000619 // Should be: without noexcept?
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000620}
621
622TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000623 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000624 "struct Z {"
625 " void operator delete(void *);"
626 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000627 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000628 "void operator delete(void *)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000629}
630
631TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000632 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000633 "struct Z {"
634 " void operator delete[](void *);"
635 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000636 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000637 "void operator delete[](void *) noexcept"));
Serge Pavlova67a4d22016-11-10 08:49:37 +0000638 // Should be: without noexcept?
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000639}
640
641TEST(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 Gribenko309856a2012-08-20 23:39:06 +0000660
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000661 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000662 Code,
Aaron Ballman512fb642015-09-17 13:30:52 +0000663 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000664 Expected));
665 }
666}
667
668TEST(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 Gribenko309856a2012-08-20 23:39:06 +0000683
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000684 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000685 Code,
Aaron Ballman512fb642015-09-17 13:30:52 +0000686 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000687 Expected));
688 }
689}
690
691TEST(DeclPrinter, TestCXXMethodDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000692 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000693 "struct Z {"
694 " void A(int a);"
695 "};",
696 "A",
697 "void A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000698}
699
700TEST(DeclPrinter, TestCXXMethodDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000701 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000702 "struct Z {"
703 " virtual void A(int a);"
704 "};",
705 "A",
706 "virtual void A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000707}
708
709TEST(DeclPrinter, TestCXXMethodDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000710 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000711 "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 Gribenko309856a2012-08-20 23:39:06 +0000719 // TODO: should we print "virtual"?
720}
721
722TEST(DeclPrinter, TestCXXMethodDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000723 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000724 "struct Z {"
725 " inline void A(int a);"
726 "};",
727 "A",
728 "inline void A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000729}
730
731TEST(DeclPrinter, TestCXXMethodDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000732 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000733 "struct Z {"
734 " virtual void A(int a) = 0;"
735 "};",
736 "A",
737 "virtual void A(int a) = 0"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000738}
739
740TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000741 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000742 "struct Z {"
743 " void A(int a) const;"
744 "};",
745 "A",
746 "void A(int a) const"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000747}
748
749TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000750 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000751 "struct Z {"
752 " void A(int a) volatile;"
753 "};",
754 "A",
755 "void A(int a) volatile"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000756}
757
758TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000759 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000760 "struct Z {"
761 " void A(int a) const volatile;"
762 "};",
763 "A",
764 "void A(int a) const volatile"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000765}
766
767TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) {
768 ASSERT_TRUE(PrintedDeclCXX11Matches(
769 "struct Z {"
770 " void A(int a) &;"
771 "};",
772 "A",
Benjamin Kramer2907b082014-02-25 18:49:49 +0000773 "void A(int a) &"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000774}
775
776TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) {
777 ASSERT_TRUE(PrintedDeclCXX11Matches(
778 "struct Z {"
779 " void A(int a) &&;"
780 "};",
781 "A",
Benjamin Kramer2907b082014-02-25 18:49:49 +0000782 "void A(int a) &&"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000783}
784
785TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000786 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000787 "struct Z {"
788 " void A(int a) throw();"
789 "};",
790 "A",
791 "void A(int a) throw()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000792}
793
794TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000795 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000796 "struct Z {"
797 " void A(int a) throw(int);"
798 "};",
799 "A",
800 "void A(int a) throw(int)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000801}
802
803TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000804 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000805 "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 Gribenko309856a2012-08-20 23:39:06 +0000811}
812
813TEST(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 Gribenko309856a2012-08-20 23:39:06 +0000820}
821
822TEST(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
832TEST(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
842TEST(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
853TEST(DeclPrinter, TestVarDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000854 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000855 "char *const (*(*A)[5])(int);",
856 "A",
857 "char *const (*(*A)[5])(int)"));
858 // Should be: with semicolon
859}
860
861TEST(DeclPrinter, TestVarDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000862 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000863 "void (*A)() throw(int);",
864 "A",
865 "void (*A)() throw(int)"));
866 // Should be: with semicolon
867}
868
869TEST(DeclPrinter, TestVarDecl3) {
870 ASSERT_TRUE(PrintedDeclCXX11Matches(
871 "void (*A)() noexcept;",
872 "A",
873 "void (*A)() noexcept"));
874 // Should be: with semicolon
875}
876
877TEST(DeclPrinter, TestFieldDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000878 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000879 "template<typename T>"
880 "struct Z { T A; };",
881 "A",
882 "T A"));
883 // Should be: with semicolon
884}
885
886TEST(DeclPrinter, TestFieldDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000887 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000888 "template<int N>"
889 "struct Z { int A[N]; };",
890 "A",
891 "int A[N]"));
892 // Should be: with semicolon
893}
894
895TEST(DeclPrinter, TestClassTemplateDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000896 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000897 "template<typename T>"
898 "struct A { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000899 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000900 "template <typename T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000901}
902
903TEST(DeclPrinter, TestClassTemplateDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000904 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000905 "template<typename T = int>"
906 "struct A { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000907 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000908 "template <typename T = int> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000909}
910
911TEST(DeclPrinter, TestClassTemplateDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000912 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000913 "template<class T>"
914 "struct A { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000915 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000916 "template <class T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000917}
918
919TEST(DeclPrinter, TestClassTemplateDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000920 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000921 "template<typename T, typename U>"
922 "struct A { T a; U b; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000923 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000924 "template <typename T, typename U> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000925}
926
927TEST(DeclPrinter, TestClassTemplateDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000928 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000929 "template<int N>"
930 "struct A { int a[N]; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000931 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000932 "template <int N> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000933}
934
935TEST(DeclPrinter, TestClassTemplateDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000936 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000937 "template<int N = 42>"
938 "struct A { int a[N]; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000939 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000940 "template <int N = 42> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000941}
942
943TEST(DeclPrinter, TestClassTemplateDecl7) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000944 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000945 "typedef int MyInt;"
946 "template<MyInt N>"
947 "struct A { int a[N]; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000948 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000949 "template <MyInt N> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000950}
951
952TEST(DeclPrinter, TestClassTemplateDecl8) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000953 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000954 "template<template<typename U> class T> struct A { };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000955 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000956 "template <template <typename U> class T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000957}
958
959TEST(DeclPrinter, TestClassTemplateDecl9) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000960 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000961 "template<typename T> struct Z { };"
962 "template<template<typename U> class T = Z> struct A { };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000963 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000964 "template <template <typename U> class T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000965}
966
967TEST(DeclPrinter, TestClassTemplateDecl10) {
968 ASSERT_TRUE(PrintedDeclCXX11Matches(
969 "template<typename... T>"
970 "struct A { int a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000971 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000972 "template <typename ...T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000973}
974
975TEST(DeclPrinter, TestClassTemplateDecl11) {
976 ASSERT_TRUE(PrintedDeclCXX11Matches(
977 "template<typename... T>"
978 "struct A : public T... { int a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000979 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000980 "template <typename ...T> struct A : public T... {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000981}
982
983TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000984 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000985 "template<typename T, typename U>"
986 "struct A { T a; U b; };"
987 "template<typename T>"
988 "struct A<T, int> { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000989 classTemplateSpecializationDecl().bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000990 "template <typename T> struct A<T, int> {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000991}
992
993TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000994 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000995 "template<typename T>"
996 "struct A { T a; };"
997 "template<typename T>"
998 "struct A<T *> { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000999 classTemplateSpecializationDecl().bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +00001000 "template <typename T> struct A<type-parameter-0-0 *> {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001001 // WRONG; Should be: "template<typename T> struct A<T *> { ... }"
1002}
1003
1004TEST(DeclPrinter, TestClassTemplateSpecializationDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001005 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001006 "template<typename T>"
1007 "struct A { T a; };"
1008 "template<>"
1009 "struct A<int> { int a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001010 classTemplateSpecializationDecl().bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +00001011 "template<> struct A<int> {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001012}
1013
1014TEST(DeclPrinter, TestFunctionTemplateDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001015 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001016 "template<typename T>"
1017 "void A(T &t);",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001018 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001019 "template <typename T> void A(T &t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001020}
1021
1022TEST(DeclPrinter, TestFunctionTemplateDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001023 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001024 "template<typename T>"
1025 "void A(T &t) { }",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001026 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +00001027 "template <typename T> void A(T &t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001028}
1029
1030TEST(DeclPrinter, TestFunctionTemplateDecl3) {
1031 ASSERT_TRUE(PrintedDeclCXX11Matches(
1032 "template<typename... T>"
1033 "void A(T... a);",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001034 functionTemplateDecl(hasName("A")).bind("id"),
Richard Smitha4bb2922014-07-23 03:17:06 +00001035 "template <typename ...T> void A(T ...a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001036}
1037
1038TEST(DeclPrinter, TestFunctionTemplateDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001039 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001040 "struct Z { template<typename T> void A(T t); };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001041 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001042 "template <typename T> void A(T t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001043}
1044
1045TEST(DeclPrinter, TestFunctionTemplateDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001046 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001047 "struct Z { template<typename T> void A(T t) {} };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001048 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +00001049 "template <typename T> void A(T t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001050}
1051
1052TEST(DeclPrinter, TestFunctionTemplateDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001053 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001054 "template<typename T >struct Z {"
1055 " template<typename U> void A(U t) {}"
1056 "};",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001057 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +00001058 "template <typename U> void A(U t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001059}
1060
1061TEST(DeclPrinter, TestTemplateArgumentList1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001062 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001063 "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
1071TEST(DeclPrinter, TestTemplateArgumentList2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001072 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001073 "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
1082TEST(DeclPrinter, TestTemplateArgumentList3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001083 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001084 "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
1092TEST(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
1102TEST(DeclPrinter, TestTemplateArgumentList5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001103 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001104 "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
1111TEST(DeclPrinter, TestTemplateArgumentList6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001112 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001113 "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
1121TEST(DeclPrinter, TestTemplateArgumentList7) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001122 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001123 "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
1132TEST(DeclPrinter, TestTemplateArgumentList8) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001133 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001134 "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
1143TEST(DeclPrinter, TestTemplateArgumentList9) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001144 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001145 "template<unsigned I> struct Z {};"
1146 "Z<0> A;",
1147 "A",
1148 "Z<0> A"));
1149 // Should be: with semicolon
1150}
1151
1152TEST(DeclPrinter, TestTemplateArgumentList10) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001153 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001154 "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
1161TEST(DeclPrinter, TestTemplateArgumentList11) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001162 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001163 "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
1170TEST(DeclPrinter, TestTemplateArgumentList12) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001171 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001172 "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
1180TEST(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 Smitha4bb2922014-07-23 03:17:06 +00001188 // Should be: with semicolon
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001189}
1190
1191TEST(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 Smitha4bb2922014-07-23 03:17:06 +00001200 // Should be: with semicolon
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001201}
1202
1203TEST(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 Smitha4bb2922014-07-23 03:17:06 +00001211 // Should be: with semicolon
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001212}
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001213
David Majnemer8423df92015-06-05 22:40:53 +00001214TEST(DeclPrinter, TestStaticAssert1) {
1215 ASSERT_TRUE(PrintedDeclCXX1ZMatches(
1216 "static_assert(true);",
1217 staticAssertDecl().bind("id"),
1218 "static_assert(true)"));
1219}
1220
Fariborz Jahaniane0586a52012-10-18 19:12:17 +00001221TEST(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 Jahanian0389e522012-12-19 23:36:00 +00001231 "- (int) A:(id)anObject inRange:(long)range"));
Fariborz Jahaniane0586a52012-10-18 19:12:17 +00001232}
1233
Fariborz Jahanian44194492012-12-20 02:20:09 +00001234TEST(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
1245TEST(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}