blob: c99550af226716b0652948ac39a7f3966b35be9f [file] [log] [blame]
Dmitri Gribenko49795ae2012-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 Jasper7fd90b02012-08-24 05:50:27 +000025#include "llvm/ADT/SmallString.h"
Dmitri Gribenko49795ae2012-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 Gribenkod1fc82e2012-08-21 17:36:32 +000036 Policy.TerseOutput = true;
Dmitri Gribenko49795ae2012-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
47 virtual void run(const MatchFinder::MatchResult &Result) {
48 const Decl *D = Result.Nodes.getDeclAs<Decl>("id");
49 if (!D || D->isImplicit())
50 return;
51 NumFoundDecls++;
52 if (NumFoundDecls > 1)
53 return;
54
55 llvm::raw_svector_ostream Out(Printed);
56 PrintDecl(Out, Result.Context, D);
57 }
58
59 StringRef getPrinted() const {
60 return Printed;
61 }
62
63 unsigned getNumFoundDecls() const {
64 return NumFoundDecls;
65 }
66};
67
68bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code,
69 ArrayRef<const char *> ClangArgs) {
70 SmallString<16> FileNameStorage;
71 StringRef FileNameRef = "input.cc";
72
73 std::vector<std::string> ArgVector;
74 ArgVector.push_back("clang-tool");
75 ArgVector.push_back("-fsyntax-only");
76 ArgVector.push_back(FileNameRef.data());
77 for (unsigned i = 0, e = ClangArgs.size(); i != e; ++i)
78 ArgVector.push_back(ClangArgs[i]);
79
80 FileManager Files((FileSystemOptions()));
81 ToolInvocation Invocation(ArgVector, ToolAction, &Files);
82
83 SmallString<1024> CodeStorage;
84 Invocation.mapVirtualFile(FileNameRef,
85 Code.toNullTerminatedStringRef(CodeStorage));
86 return Invocation.run();
87}
88
89::testing::AssertionResult PrintedDeclMatches(
90 StringRef Code,
91 ArrayRef<const char *> ClangArgs,
92 const DeclarationMatcher &NodeMatch,
93 StringRef ExpectedPrinted) {
94 PrintMatch Printer;
95 MatchFinder Finder;
96 Finder.addMatcher(NodeMatch, &Printer);
97 OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder));
98
99 if (!runToolOnCode(Factory->create(), Code, ClangArgs))
100 return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
101
102 if (Printer.getNumFoundDecls() == 0)
103 return testing::AssertionFailure()
104 << "Matcher didn't find any declarations";
105
106 if (Printer.getNumFoundDecls() > 1)
107 return testing::AssertionFailure()
108 << "Matcher should match only one declaration "
109 "(found " << Printer.getNumFoundDecls() << ")";
110
111 if (Printer.getPrinted() != ExpectedPrinted)
112 return ::testing::AssertionFailure()
113 << "Expected \"" << ExpectedPrinted << "\", "
114 "got \"" << Printer.getPrinted() << "\"";
115
116 return ::testing::AssertionSuccess();
117}
118
119::testing::AssertionResult PrintedDeclMatches(StringRef Code,
120 StringRef DeclName,
121 StringRef ExpectedPrinted) {
122 return PrintedDeclMatches(Code,
123 ArrayRef<const char *>(),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000124 namedDecl(hasName(DeclName)).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000125 ExpectedPrinted);
126}
127
128::testing::AssertionResult PrintedDeclMatches(
129 StringRef Code,
130 const DeclarationMatcher &NodeMatch,
131 StringRef ExpectedPrinted) {
132 return PrintedDeclMatches(Code,
133 ArrayRef<const char *>(),
134 NodeMatch,
135 ExpectedPrinted);
136}
137
138::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code,
139 StringRef DeclName,
140 StringRef ExpectedPrinted) {
141 return PrintedDeclMatches(Code,
142 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000143 namedDecl(hasName(DeclName)).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000144 ExpectedPrinted);
145}
146
147::testing::AssertionResult PrintedDeclCXX11Matches(
148 StringRef Code,
149 const DeclarationMatcher &NodeMatch,
150 StringRef ExpectedPrinted) {
151 return PrintedDeclMatches(Code,
152 ArrayRef<const char *>("-std=c++11"),
153 NodeMatch,
154 ExpectedPrinted);
155}
156
157} // unnamed namespace
158
159TEST(DeclPrinter, TestNamespace1) {
160 ASSERT_TRUE(PrintedDeclMatches(
161 "namespace A { int B; }",
162 "A",
163 "namespace A {\n}"));
164 // Should be: with { ... }
165}
166
167TEST(DeclPrinter, TestNamespace2) {
168 ASSERT_TRUE(PrintedDeclCXX11Matches(
169 "inline namespace A { int B; }",
170 "A",
171 "inline namespace A {\n}"));
172 // Should be: with { ... }
173}
174
175TEST(DeclPrinter, TestNamespaceAlias1) {
176 ASSERT_TRUE(PrintedDeclMatches(
177 "namespace Z { }"
178 "namespace A = Z;",
179 "A",
180 "namespace A = Z"));
181 // Should be: with semicolon
182}
183
184TEST(DeclPrinter, TestNamespaceAlias2) {
185 ASSERT_TRUE(PrintedDeclMatches(
186 "namespace X { namespace Y {} }"
187 "namespace A = X::Y;",
188 "A",
189 "namespace A = X::Y"));
190 // Should be: with semicolon
191}
192
193TEST(DeclPrinter, TestCXXRecordDecl1) {
194 ASSERT_TRUE(PrintedDeclMatches(
195 "class A { int a; };",
196 "A",
197 "class A {\n}"));
198 // Should be: with semicolon, with { ... }
199}
200
201TEST(DeclPrinter, TestCXXRecordDecl2) {
202 ASSERT_TRUE(PrintedDeclMatches(
203 "struct A { int a; };",
204 "A",
205 "struct A {\n}"));
206 // Should be: with semicolon, with { ... }
207}
208
209TEST(DeclPrinter, TestCXXRecordDecl3) {
210 ASSERT_TRUE(PrintedDeclMatches(
211 "union A { int a; };",
212 "A",
213 "union A {\n}"));
214 // Should be: with semicolon, with { ... }
215}
216
217TEST(DeclPrinter, TestCXXRecordDecl4) {
218 ASSERT_TRUE(PrintedDeclMatches(
219 "class Z { int a; };"
220 "class A : Z { int b; };",
221 "A",
222 "class A : Z {\n}"));
223 // Should be: with semicolon, with { ... }, without two spaces
224}
225
226TEST(DeclPrinter, TestCXXRecordDecl5) {
227 ASSERT_TRUE(PrintedDeclMatches(
228 "struct Z { int a; };"
229 "struct A : Z { int b; };",
230 "A",
231 "struct A : Z {\n}"));
232 // Should be: with semicolon, with { ... }, without two spaces
233}
234
235TEST(DeclPrinter, TestCXXRecordDecl6) {
236 ASSERT_TRUE(PrintedDeclMatches(
237 "class Z { int a; };"
238 "class A : public Z { int b; };",
239 "A",
240 "class A : public Z {\n}"));
241 // Should be: with semicolon, with { ... }
242}
243
244TEST(DeclPrinter, TestCXXRecordDecl7) {
245 ASSERT_TRUE(PrintedDeclMatches(
246 "class Z { int a; };"
247 "class A : protected Z { int b; };",
248 "A",
249 "class A : protected Z {\n}"));
250 // Should be: with semicolon, with { ... }
251}
252
253TEST(DeclPrinter, TestCXXRecordDecl8) {
254 ASSERT_TRUE(PrintedDeclMatches(
255 "class Z { int a; };"
256 "class A : private Z { int b; };",
257 "A",
258 "class A : private Z {\n}"));
259 // Should be: with semicolon, with { ... }
260}
261
262TEST(DeclPrinter, TestCXXRecordDecl9) {
263 ASSERT_TRUE(PrintedDeclMatches(
264 "class Z { int a; };"
265 "class A : virtual Z { int b; };",
266 "A",
267 "class A : virtual Z {\n}"));
268 // Should be: with semicolon, with { ... }, without two spaces
269}
270
271TEST(DeclPrinter, TestCXXRecordDecl10) {
272 ASSERT_TRUE(PrintedDeclMatches(
273 "class Z { int a; };"
274 "class A : virtual public Z { int b; };",
275 "A",
276 "class A : virtual public Z {\n}"));
277 // Should be: with semicolon, with { ... }
278}
279
280TEST(DeclPrinter, TestCXXRecordDecl11) {
281 ASSERT_TRUE(PrintedDeclMatches(
282 "class Z { int a; };"
283 "class Y : virtual public Z { int b; };"
284 "class A : virtual public Z, private Y { int c; };",
285 "A",
286 "class A : virtual public Z, private Y {\n}"));
287 // Should be: with semicolon, with { ... }
288}
289
290TEST(DeclPrinter, TestFunctionDecl1) {
291 ASSERT_TRUE(PrintedDeclMatches(
292 "void A();",
293 "A",
294 "void A()"));
295 // Should be: with semicolon
296}
297
298TEST(DeclPrinter, TestFunctionDecl2) {
299 ASSERT_TRUE(PrintedDeclMatches(
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000300 "void A() {}",
301 "A",
302 "void A()"));
303 // Should be: with semicolon
304}
305
306TEST(DeclPrinter, TestFunctionDecl3) {
307 ASSERT_TRUE(PrintedDeclMatches(
308 "void Z();"
309 "void A() { Z(); }",
310 "A",
311 "void A()"));
312 // Should be: with semicolon
313}
314
315TEST(DeclPrinter, TestFunctionDecl4) {
316 ASSERT_TRUE(PrintedDeclMatches(
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000317 "extern void A();",
318 "A",
319 "extern void A()"));
320 // Should be: with semicolon
321}
322
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000323TEST(DeclPrinter, TestFunctionDecl5) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000324 ASSERT_TRUE(PrintedDeclMatches(
325 "static void A();",
326 "A",
327 "static void A()"));
328 // Should be: with semicolon
329}
330
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000331TEST(DeclPrinter, TestFunctionDecl6) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000332 ASSERT_TRUE(PrintedDeclMatches(
333 "inline void A();",
334 "A",
335 "inline void A()"));
336 // Should be: with semicolon
337}
338
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000339TEST(DeclPrinter, TestFunctionDecl7) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000340 ASSERT_TRUE(PrintedDeclCXX11Matches(
341 "constexpr int A(int a);",
342 "A",
343 "int A(int a)"));
344 // WRONG; Should be: "constexpr int A(int a);"
345}
346
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000347TEST(DeclPrinter, TestFunctionDecl8) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000348 ASSERT_TRUE(PrintedDeclMatches(
349 "void A(int a);",
350 "A",
351 "void A(int a)"));
352 // Should be: with semicolon
353}
354
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000355TEST(DeclPrinter, TestFunctionDecl9) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000356 ASSERT_TRUE(PrintedDeclMatches(
357 "void A(...);",
358 "A",
359 "void A(...)"));
360 // Should be: with semicolon
361}
362
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000363TEST(DeclPrinter, TestFunctionDecl10) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000364 ASSERT_TRUE(PrintedDeclMatches(
365 "void A(int a, ...);",
366 "A",
367 "void A(int a, ...)"));
368 // Should be: with semicolon
369}
370
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000371TEST(DeclPrinter, TestFunctionDecl11) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000372 ASSERT_TRUE(PrintedDeclMatches(
373 "typedef long size_t;"
374 "typedef int *pInt;"
375 "void A(int a, pInt b, size_t c);",
376 "A",
377 "void A(int a, pInt b, size_t c)"));
378 // Should be: with semicolon
379}
380
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000381TEST(DeclPrinter, TestFunctionDecl12) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000382 ASSERT_TRUE(PrintedDeclMatches(
383 "void A(int a, int b = 0);",
384 "A",
385 "void A(int a, int b = 0)"));
386 // Should be: with semicolon
387}
388
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000389TEST(DeclPrinter, TestFunctionDecl13) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000390 ASSERT_TRUE(PrintedDeclMatches(
391 "void (*A(int a))(int b);",
392 "A",
393 "void (*A(int a))(int)"));
394 // Should be: with semicolon, with parameter name (?)
395}
396
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000397TEST(DeclPrinter, TestFunctionDecl14) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000398 ASSERT_TRUE(PrintedDeclMatches(
399 "template<typename T>"
400 "void A(T t) { }"
401 "template<>"
402 "void A(int N) { }",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000403 functionDecl(hasName("A"), isExplicitTemplateSpecialization()).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000404 "void A(int N)"));
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000405 // WRONG; Should be: "template <> void A(int N);"));
406}
407
408
409TEST(DeclPrinter, TestCXXConstructorDecl1) {
410 ASSERT_TRUE(PrintedDeclMatches(
411 "struct A {"
412 " A();"
413 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000414 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000415 ""));
416 // WRONG; Should be: "A();"
417}
418
419TEST(DeclPrinter, TestCXXConstructorDecl2) {
420 ASSERT_TRUE(PrintedDeclMatches(
421 "struct A {"
422 " A(int a);"
423 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000424 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000425 ""));
426 // WRONG; Should be: "A(int a);"
427}
428
429TEST(DeclPrinter, TestCXXConstructorDecl3) {
430 ASSERT_TRUE(PrintedDeclMatches(
431 "struct A {"
432 " A(const A &a);"
433 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000434 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000435 ""));
436 // WRONG; Should be: "A(const A &a);"
437}
438
439TEST(DeclPrinter, TestCXXConstructorDecl4) {
440 ASSERT_TRUE(PrintedDeclMatches(
441 "struct A {"
442 " A(const A &a, int = 0);"
443 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000444 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000445 ""));
446 // WRONG; Should be: "A(const A &a, int = 0);"
447}
448
449TEST(DeclPrinter, TestCXXConstructorDecl5) {
450 ASSERT_TRUE(PrintedDeclCXX11Matches(
451 "struct A {"
452 " A(const A &&a);"
453 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000454 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000455 ""));
456 // WRONG; Should be: "A(const A &&a);"
457}
458
459TEST(DeclPrinter, TestCXXConstructorDecl6) {
460 ASSERT_TRUE(PrintedDeclMatches(
461 "struct A {"
462 " explicit A(int a);"
463 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000464 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000465 ""));
466 // WRONG; Should be: "explicit A(int a);"
467}
468
469TEST(DeclPrinter, TestCXXConstructorDecl7) {
470 ASSERT_TRUE(PrintedDeclMatches(
471 "struct A {"
472 " constexpr A();"
473 "};",
474 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000475 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000476 ""));
477 // WRONG; Should be: "constexpr A();"
478}
479
480TEST(DeclPrinter, TestCXXConstructorDecl8) {
481 ASSERT_TRUE(PrintedDeclMatches(
482 "struct A {"
483 " A() = default;"
484 "};",
485 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000486 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000487 ""));
488 // WRONG; Should be: "A() = default;"
489}
490
491TEST(DeclPrinter, TestCXXConstructorDecl9) {
492 ASSERT_TRUE(PrintedDeclMatches(
493 "struct A {"
494 " A() = delete;"
495 "};",
496 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000497 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000498 " = delete"));
499 // WRONG; Should be: "A() = delete;"
500}
501
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000502TEST(DeclPrinter, TestCXXConstructorDecl10) {
503 ASSERT_TRUE(PrintedDeclCXX11Matches(
504 "template<typename... T>"
505 "struct A {"
506 " A(const A &a);"
507 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000508 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000509 ""));
510 // WRONG; Should be: "A(const A &a);"
511}
512
NAKAMURA Takumi29b1f682012-08-25 00:05:56 +0000513#if !defined(_MSC_VER)
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000514TEST(DeclPrinter, TestCXXConstructorDecl11) {
515 ASSERT_TRUE(PrintedDeclCXX11Matches(
516 "template<typename... T>"
517 "struct A : public T... {"
518 " A(T&&... ts) : T(ts)... {}"
519 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000520 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000521 "A<T...>(T &&ts...) : T(ts)"));
Dmitri Gribenkof6ec15a2012-08-24 00:27:50 +0000522 // WRONG; Should be: "A(T&&... ts) : T(ts)..."
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000523}
NAKAMURA Takumi29b1f682012-08-25 00:05:56 +0000524#endif
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000525
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000526TEST(DeclPrinter, TestCXXDestructorDecl1) {
527 ASSERT_TRUE(PrintedDeclMatches(
528 "struct A {"
529 " ~A();"
530 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000531 destructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000532 "void ~A()"));
533 // WRONG; Should be: "~A();"
534}
535
536TEST(DeclPrinter, TestCXXDestructorDecl2) {
537 ASSERT_TRUE(PrintedDeclMatches(
538 "struct A {"
539 " virtual ~A();"
540 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000541 destructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000542 "virtual void ~A()"));
543 // WRONG; Should be: "virtual ~A();"
544}
545
546TEST(DeclPrinter, TestCXXConversionDecl1) {
547 ASSERT_TRUE(PrintedDeclMatches(
548 "struct A {"
549 " operator int();"
550 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000551 methodDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000552 "int operator int()"));
553 // WRONG; Should be: "operator int();"
554}
555
556TEST(DeclPrinter, TestCXXConversionDecl2) {
557 ASSERT_TRUE(PrintedDeclMatches(
558 "struct A {"
559 " operator bool();"
560 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000561 methodDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000562 "bool operator _Bool()"));
563 // WRONG; Should be: "operator bool();"
564}
565
566TEST(DeclPrinter, TestCXXConversionDecl3) {
567 ASSERT_TRUE(PrintedDeclMatches(
568 "struct Z {};"
569 "struct A {"
570 " operator Z();"
571 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000572 methodDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000573 "Z operator struct Z()"));
574 // WRONG; Should be: "operator Z();"
575}
576
577TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) {
578 ASSERT_TRUE(PrintedDeclMatches(
579 "namespace std { typedef decltype(sizeof(int)) size_t; }"
580 "struct Z {"
581 " void *operator new(std::size_t);"
582 "};",
583 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000584 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000585 "void *operator new(std::size_t)"));
586 // Should be: with semicolon
587}
588
589TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) {
590 ASSERT_TRUE(PrintedDeclMatches(
591 "namespace std { typedef decltype(sizeof(int)) size_t; }"
592 "struct Z {"
593 " void *operator new[](std::size_t);"
594 "};",
595 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000596 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000597 "void *operator new[](std::size_t)"));
598 // Should be: with semicolon
599}
600
601TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) {
602 ASSERT_TRUE(PrintedDeclMatches(
603 "struct Z {"
604 " void operator delete(void *);"
605 "};",
606 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000607 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000608 "void operator delete(void *) noexcept"));
609 // Should be: with semicolon, without noexcept?
610}
611
612TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) {
613 ASSERT_TRUE(PrintedDeclMatches(
614 "struct Z {"
615 " void operator delete(void *);"
616 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000617 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000618 "void operator delete(void *)"));
619 // Should be: with semicolon
620}
621
622TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) {
623 ASSERT_TRUE(PrintedDeclMatches(
624 "struct Z {"
625 " void operator delete[](void *);"
626 "};",
627 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000628 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000629 "void operator delete[](void *) noexcept"));
630 // Should be: with semicolon, without noexcept?
631}
632
633TEST(DeclPrinter, TestCXXMethodDecl_Operator1) {
634 const char *OperatorNames[] = {
635 "+", "-", "*", "/", "%", "^", "&", "|",
636 "=", "<", ">", "+=", "-=", "*=", "/=", "%=",
637 "^=", "&=", "|=", "<<", ">>", ">>=", "<<=", "==", "!=",
638 "<=", ">=", "&&", "||", ",", "->*",
639 "()", "[]"
640 };
641
642 for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) {
643 SmallString<128> Code;
644 Code.append("struct Z { void operator");
645 Code.append(OperatorNames[i]);
646 Code.append("(Z z); };");
647
648 SmallString<128> Expected;
649 Expected.append("void operator");
650 Expected.append(OperatorNames[i]);
651 Expected.append("(Z z)");
652 // Should be: with semicolon
653
654 ASSERT_TRUE(PrintedDeclMatches(
655 Code,
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000656 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000657 Expected));
658 }
659}
660
661TEST(DeclPrinter, TestCXXMethodDecl_Operator2) {
662 const char *OperatorNames[] = {
663 "~", "!", "++", "--", "->"
664 };
665
666 for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) {
667 SmallString<128> Code;
668 Code.append("struct Z { void operator");
669 Code.append(OperatorNames[i]);
670 Code.append("(); };");
671
672 SmallString<128> Expected;
673 Expected.append("void operator");
674 Expected.append(OperatorNames[i]);
675 Expected.append("()");
676 // Should be: with semicolon
677
678 ASSERT_TRUE(PrintedDeclMatches(
679 Code,
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000680 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000681 Expected));
682 }
683}
684
685TEST(DeclPrinter, TestCXXMethodDecl1) {
686 ASSERT_TRUE(PrintedDeclMatches(
687 "struct Z {"
688 " void A(int a);"
689 "};",
690 "A",
691 "void A(int a)"));
692 // Should be: with semicolon
693}
694
695TEST(DeclPrinter, TestCXXMethodDecl2) {
696 ASSERT_TRUE(PrintedDeclMatches(
697 "struct Z {"
698 " virtual void A(int a);"
699 "};",
700 "A",
701 "virtual void A(int a)"));
702 // Should be: with semicolon
703}
704
705TEST(DeclPrinter, TestCXXMethodDecl3) {
706 ASSERT_TRUE(PrintedDeclMatches(
707 "struct Z {"
708 " virtual void A(int a);"
709 "};"
710 "struct ZZ : Z {"
711 " void A(int a);"
712 "};",
713 "ZZ::A",
714 "void A(int a)"));
715 // Should be: with semicolon
716 // TODO: should we print "virtual"?
717}
718
719TEST(DeclPrinter, TestCXXMethodDecl4) {
720 ASSERT_TRUE(PrintedDeclMatches(
721 "struct Z {"
722 " inline void A(int a);"
723 "};",
724 "A",
725 "inline void A(int a)"));
726 // Should be: with semicolon
727}
728
729TEST(DeclPrinter, TestCXXMethodDecl5) {
730 ASSERT_TRUE(PrintedDeclMatches(
731 "struct Z {"
732 " virtual void A(int a) = 0;"
733 "};",
734 "A",
735 "virtual void A(int a) = 0"));
736 // Should be: with semicolon
737}
738
739TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier1) {
740 ASSERT_TRUE(PrintedDeclMatches(
741 "struct Z {"
742 " void A(int a) const;"
743 "};",
744 "A",
745 "void A(int a) const"));
746 // Should be: with semicolon
747}
748
749TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier2) {
750 ASSERT_TRUE(PrintedDeclMatches(
751 "struct Z {"
752 " void A(int a) volatile;"
753 "};",
754 "A",
755 "void A(int a) volatile"));
756 // Should be: with semicolon
757}
758
759TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier3) {
760 ASSERT_TRUE(PrintedDeclMatches(
761 "struct Z {"
762 " void A(int a) const volatile;"
763 "};",
764 "A",
765 "void A(int a) const volatile"));
766 // Should be: with semicolon
767}
768
769TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) {
770 ASSERT_TRUE(PrintedDeclCXX11Matches(
771 "struct Z {"
772 " void A(int a) &;"
773 "};",
774 "A",
775 "void A(int a)"));
776 // WRONG; Should be: "void A(int a) &;"
777}
778
779TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) {
780 ASSERT_TRUE(PrintedDeclCXX11Matches(
781 "struct Z {"
782 " void A(int a) &&;"
783 "};",
784 "A",
785 "void A(int a)"));
786 // WRONG; Should be: "void A(int a) &&;"
787}
788
789TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) {
790 ASSERT_TRUE(PrintedDeclMatches(
791 "struct Z {"
792 " void A(int a) throw();"
793 "};",
794 "A",
795 "void A(int a) throw()"));
796 // Should be: with semicolon
797}
798
799TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification2) {
800 ASSERT_TRUE(PrintedDeclMatches(
801 "struct Z {"
802 " void A(int a) throw(int);"
803 "};",
804 "A",
805 "void A(int a) throw(int)"));
806 // Should be: with semicolon
807}
808
809TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification3) {
810 ASSERT_TRUE(PrintedDeclMatches(
811 "class ZZ {};"
812 "struct Z {"
813 " void A(int a) throw(ZZ, int);"
814 "};",
815 "A",
816 "void A(int a) throw(ZZ, int)"));
817 // Should be: with semicolon
818}
819
820TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification4) {
821 ASSERT_TRUE(PrintedDeclCXX11Matches(
822 "struct Z {"
823 " void A(int a) noexcept;"
824 "};",
825 "A",
826 "void A(int a) noexcept"));
827 // Should be: with semicolon
828}
829
830TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification5) {
831 ASSERT_TRUE(PrintedDeclCXX11Matches(
832 "struct Z {"
833 " void A(int a) noexcept(true);"
834 "};",
835 "A",
836 "void A(int a) noexcept(trueA(int a) noexcept(true)"));
837 // WRONG; Should be: "void A(int a) noexcept(true);"
838}
839
840TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) {
841 ASSERT_TRUE(PrintedDeclCXX11Matches(
842 "struct Z {"
843 " void A(int a) noexcept(1 < 2);"
844 "};",
845 "A",
846 "void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)"));
847 // WRONG; Should be: "void A(int a) noexcept(1 < 2);"
848}
849
850TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) {
851 ASSERT_TRUE(PrintedDeclCXX11Matches(
852 "template<int N>"
853 "struct Z {"
854 " void A(int a) noexcept(N < 2);"
855 "};",
856 "A",
857 "void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)"));
858 // WRONG; Should be: "void A(int a) noexcept(N < 2);"
859}
860
861TEST(DeclPrinter, TestVarDecl1) {
862 ASSERT_TRUE(PrintedDeclMatches(
863 "char *const (*(*A)[5])(int);",
864 "A",
865 "char *const (*(*A)[5])(int)"));
866 // Should be: with semicolon
867}
868
869TEST(DeclPrinter, TestVarDecl2) {
870 ASSERT_TRUE(PrintedDeclMatches(
871 "void (*A)() throw(int);",
872 "A",
873 "void (*A)() throw(int)"));
874 // Should be: with semicolon
875}
876
877TEST(DeclPrinter, TestVarDecl3) {
878 ASSERT_TRUE(PrintedDeclCXX11Matches(
879 "void (*A)() noexcept;",
880 "A",
881 "void (*A)() noexcept"));
882 // Should be: with semicolon
883}
884
885TEST(DeclPrinter, TestFieldDecl1) {
886 ASSERT_TRUE(PrintedDeclMatches(
887 "template<typename T>"
888 "struct Z { T A; };",
889 "A",
890 "T A"));
891 // Should be: with semicolon
892}
893
894TEST(DeclPrinter, TestFieldDecl2) {
895 ASSERT_TRUE(PrintedDeclMatches(
896 "template<int N>"
897 "struct Z { int A[N]; };",
898 "A",
899 "int A[N]"));
900 // Should be: with semicolon
901}
902
903TEST(DeclPrinter, TestClassTemplateDecl1) {
904 ASSERT_TRUE(PrintedDeclMatches(
905 "template<typename T>"
906 "struct A { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000907 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000908 "template <typename T> struct A {\n}"));
909 // Should be: with semicolon, with { ... }
910}
911
912TEST(DeclPrinter, TestClassTemplateDecl2) {
913 ASSERT_TRUE(PrintedDeclMatches(
914 "template<typename T = int>"
915 "struct A { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000916 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000917 "template <typename T = int> struct A {\n}"));
918 // Should be: with semicolon, with { ... }
919}
920
921TEST(DeclPrinter, TestClassTemplateDecl3) {
922 ASSERT_TRUE(PrintedDeclMatches(
923 "template<class T>"
924 "struct A { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000925 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000926 "template <class T> struct A {\n}"));
927 // Should be: with semicolon, with { ... }
928}
929
930TEST(DeclPrinter, TestClassTemplateDecl4) {
931 ASSERT_TRUE(PrintedDeclMatches(
932 "template<typename T, typename U>"
933 "struct A { T a; U b; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000934 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000935 "template <typename T, typename U> struct A {\n}"));
936 // Should be: with semicolon, with { ... }
937}
938
939TEST(DeclPrinter, TestClassTemplateDecl5) {
940 ASSERT_TRUE(PrintedDeclMatches(
941 "template<int N>"
942 "struct A { int a[N]; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000943 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000944 "template <int N> struct A {\n}"));
945 // Should be: with semicolon, with { ... }
946}
947
948TEST(DeclPrinter, TestClassTemplateDecl6) {
949 ASSERT_TRUE(PrintedDeclMatches(
950 "template<int N = 42>"
951 "struct A { int a[N]; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000952 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000953 "template <int N = 42> struct A {\n}"));
954 // Should be: with semicolon, with { ... }
955}
956
957TEST(DeclPrinter, TestClassTemplateDecl7) {
958 ASSERT_TRUE(PrintedDeclMatches(
959 "typedef int MyInt;"
960 "template<MyInt N>"
961 "struct A { int a[N]; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000962 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000963 "template <MyInt N> struct A {\n}"));
964 // Should be: with semicolon, with { ... }
965}
966
967TEST(DeclPrinter, TestClassTemplateDecl8) {
968 ASSERT_TRUE(PrintedDeclMatches(
969 "template<template<typename U> class T> struct A { };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000970 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000971 "template <template <typename U> class T> struct A {\n}"));
972 // Should be: with semicolon, with { ... }
973}
974
975TEST(DeclPrinter, TestClassTemplateDecl9) {
976 ASSERT_TRUE(PrintedDeclMatches(
977 "template<typename T> struct Z { };"
978 "template<template<typename U> class T = Z> struct A { };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000979 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000980 "template <template <typename U> class T> struct A {\n}"));
981 // Should be: with semicolon, with { ... }
982}
983
984TEST(DeclPrinter, TestClassTemplateDecl10) {
985 ASSERT_TRUE(PrintedDeclCXX11Matches(
986 "template<typename... T>"
987 "struct A { int a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000988 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000989 "template <typename ... T> struct A {\n}"));
990 // Should be: with semicolon, with { ... }, without spaces before '...'
991}
992
993TEST(DeclPrinter, TestClassTemplateDecl11) {
994 ASSERT_TRUE(PrintedDeclCXX11Matches(
995 "template<typename... T>"
996 "struct A : public T... { int a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000997 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000998 "template <typename ... T> struct A : public T... {\n}"));
999 // Should be: with semicolon, with { ... }, without spaces before '...'
1000}
1001
1002TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) {
1003 ASSERT_TRUE(PrintedDeclMatches(
1004 "template<typename T, typename U>"
1005 "struct A { T a; U b; };"
1006 "template<typename T>"
1007 "struct A<T, int> { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001008 classTemplateSpecializationDecl().bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001009 "struct A {\n}"));
1010 // WRONG; Should be: "template<typename T> struct A<T, int> { ... }"
1011}
1012
1013TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) {
1014 ASSERT_TRUE(PrintedDeclMatches(
1015 "template<typename T>"
1016 "struct A { T a; };"
1017 "template<typename T>"
1018 "struct A<T *> { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001019 classTemplateSpecializationDecl().bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001020 "struct A {\n}"));
1021 // WRONG; Should be: "template<typename T> struct A<T *> { ... }"
1022}
1023
1024TEST(DeclPrinter, TestClassTemplateSpecializationDecl1) {
1025 ASSERT_TRUE(PrintedDeclMatches(
1026 "template<typename T>"
1027 "struct A { T a; };"
1028 "template<>"
1029 "struct A<int> { int a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001030 classTemplateSpecializationDecl().bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001031 "struct A {\n}"));
1032 // WRONG; Should be: "template<> struct A<int> { ... }"
1033}
1034
1035TEST(DeclPrinter, TestFunctionTemplateDecl1) {
1036 ASSERT_TRUE(PrintedDeclMatches(
1037 "template<typename T>"
1038 "void A(T &t);",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001039 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001040 "template <typename T> void A(T &t)"));
1041 // Should be: with semicolon
1042}
1043
1044TEST(DeclPrinter, TestFunctionTemplateDecl2) {
1045 ASSERT_TRUE(PrintedDeclMatches(
1046 "template<typename T>"
1047 "void A(T &t) { }",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001048 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +00001049 "template <typename T> void A(T &t)"));
1050 // Should be: with semicolon
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001051}
1052
1053TEST(DeclPrinter, TestFunctionTemplateDecl3) {
1054 ASSERT_TRUE(PrintedDeclCXX11Matches(
1055 "template<typename... T>"
1056 "void A(T... a);",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001057 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001058 "template <typename ... T> void A(T a...)"));
1059 // WRONG; Should be: "template <typename ... T> void A(T... a)"
1060 // (not "T a...")
1061 // Should be: with semicolon.
1062}
1063
1064TEST(DeclPrinter, TestFunctionTemplateDecl4) {
1065 ASSERT_TRUE(PrintedDeclMatches(
1066 "struct Z { template<typename T> void A(T t); };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001067 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001068 "template <typename T> void A(T t)"));
1069 // Should be: with semicolon
1070}
1071
1072TEST(DeclPrinter, TestFunctionTemplateDecl5) {
1073 ASSERT_TRUE(PrintedDeclMatches(
1074 "struct Z { template<typename T> void A(T t) {} };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001075 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +00001076 "template <typename T> void A(T t)"));
1077 // Should be: with semicolon
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001078}
1079
1080TEST(DeclPrinter, TestFunctionTemplateDecl6) {
1081 ASSERT_TRUE(PrintedDeclMatches(
1082 "template<typename T >struct Z {"
1083 " template<typename U> void A(U t) {}"
1084 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001085 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +00001086 "template <typename U> void A(U t)"));
1087 // Should be: with semicolon
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001088}
1089
1090TEST(DeclPrinter, TestTemplateArgumentList1) {
1091 ASSERT_TRUE(PrintedDeclMatches(
1092 "template<typename T> struct Z {};"
1093 "struct X {};"
1094 "Z<X> A;",
1095 "A",
1096 "Z<X> A"));
1097 // Should be: with semicolon
1098}
1099
1100TEST(DeclPrinter, TestTemplateArgumentList2) {
1101 ASSERT_TRUE(PrintedDeclMatches(
1102 "template<typename T, typename U> struct Z {};"
1103 "struct X {};"
1104 "typedef int Y;"
1105 "Z<X, Y> A;",
1106 "A",
1107 "Z<X, Y> A"));
1108 // Should be: with semicolon
1109}
1110
1111TEST(DeclPrinter, TestTemplateArgumentList3) {
1112 ASSERT_TRUE(PrintedDeclMatches(
1113 "template<typename T> struct Z {};"
1114 "template<typename T> struct X {};"
1115 "Z<X<int> > A;",
1116 "A",
1117 "Z<X<int> > A"));
1118 // Should be: with semicolon
1119}
1120
1121TEST(DeclPrinter, TestTemplateArgumentList4) {
1122 ASSERT_TRUE(PrintedDeclCXX11Matches(
1123 "template<typename T> struct Z {};"
1124 "template<typename T> struct X {};"
1125 "Z<X<int>> A;",
1126 "A",
1127 "Z<X<int> > A"));
1128 // Should be: with semicolon, without extra space in "> >"
1129}
1130
1131TEST(DeclPrinter, TestTemplateArgumentList5) {
1132 ASSERT_TRUE(PrintedDeclCXX11Matches(
1133 "template<typename T> struct Z {};"
1134 "template<typename T> struct X { Z<T> A; };",
1135 "A",
1136 "Z<T> A"));
1137 // Should be: with semicolon
1138}
1139
1140TEST(DeclPrinter, TestTemplateArgumentList6) {
1141 ASSERT_TRUE(PrintedDeclMatches(
1142 "template<template<typename T> class U> struct Z {};"
1143 "template<typename T> struct X {};"
1144 "Z<X> A;",
1145 "A",
1146 "Z<X> A"));
1147 // Should be: with semicolon
1148}
1149
1150TEST(DeclPrinter, TestTemplateArgumentList7) {
1151 ASSERT_TRUE(PrintedDeclCXX11Matches(
1152 "template<template<typename T> class U> struct Z {};"
1153 "template<template<typename T> class U> struct Y {"
1154 " Z<U> A;"
1155 "};",
1156 "A",
1157 "Z<U> A"));
1158 // Should be: with semicolon
1159}
1160
1161TEST(DeclPrinter, TestTemplateArgumentList8) {
1162 ASSERT_TRUE(PrintedDeclCXX11Matches(
1163 "template<typename T> struct Z {};"
1164 "template<template<typename T> class U> struct Y {"
1165 " Z<U<int> > A;"
1166 "};",
1167 "A",
1168 "Z<U<int> > A"));
1169 // Should be: with semicolon
1170}
1171
1172TEST(DeclPrinter, TestTemplateArgumentList9) {
1173 ASSERT_TRUE(PrintedDeclMatches(
1174 "template<unsigned I> struct Z {};"
1175 "Z<0> A;",
1176 "A",
1177 "Z<0> A"));
1178 // Should be: with semicolon
1179}
1180
1181TEST(DeclPrinter, TestTemplateArgumentList10) {
1182 ASSERT_TRUE(PrintedDeclMatches(
1183 "template<unsigned I> struct Z {};"
1184 "template<unsigned I> struct X { Z<I> A; };",
1185 "A",
1186 "Z<I> A"));
1187 // Should be: with semicolon
1188}
1189
1190TEST(DeclPrinter, TestTemplateArgumentList11) {
1191 ASSERT_TRUE(PrintedDeclMatches(
1192 "template<int I> struct Z {};"
1193 "Z<42 * 10 - 420 / 1> A;",
1194 "A",
1195 "Z<42 * 10 - 420 / 1> A"));
1196 // Should be: with semicolon
1197}
1198
1199TEST(DeclPrinter, TestTemplateArgumentList12) {
1200 ASSERT_TRUE(PrintedDeclMatches(
1201 "template<const char *p> struct Z {};"
1202 "extern const char X[] = \"aaa\";"
1203 "Z<X> A;",
1204 "A",
1205 "Z<X> A"));
1206 // Should be: with semicolon
1207}
1208
1209TEST(DeclPrinter, TestTemplateArgumentList13) {
1210 ASSERT_TRUE(PrintedDeclCXX11Matches(
1211 "template<typename... T> struct Z {};"
1212 "template<typename... T> struct X {"
1213 " Z<T...> A;"
1214 "};",
1215 "A",
1216 "Z<T...> A"));
1217 // Should be: with semicolon, without extra space in "> >"
1218}
1219
1220TEST(DeclPrinter, TestTemplateArgumentList14) {
1221 ASSERT_TRUE(PrintedDeclCXX11Matches(
1222 "template<typename... T> struct Z {};"
1223 "template<typename T> struct Y {};"
1224 "template<typename... T> struct X {"
1225 " Z<Y<T>...> A;"
1226 "};",
1227 "A",
1228 "Z<Y<T>...> A"));
1229 // Should be: with semicolon, without extra space in "> >"
1230}
1231
1232TEST(DeclPrinter, TestTemplateArgumentList15) {
1233 ASSERT_TRUE(PrintedDeclCXX11Matches(
1234 "template<unsigned I> struct Z {};"
1235 "template<typename... T> struct X {"
1236 " Z<sizeof...(T)> A;"
1237 "};",
1238 "A",
1239 "Z<sizeof...(T)> A"));
1240 // Should be: with semicolon, without extra space in "> >"
1241}