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