blob: 923aff18472b6075499cae929f2a175c7e6c27e6 [file] [log] [blame]
Chandler Carruth320d9662012-12-04 09:45:34 +00001//===- unittests/Lex/LexerTest.cpp ------ Lexer tests ---------------------===//
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +00002//
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
Chandler Carruth320d9662012-12-04 09:45:34 +000010#include "clang/Lex/Lexer.h"
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +000011#include "clang/Basic/Diagnostic.h"
Douglas Gregoredf8e382012-10-23 22:38:58 +000012#include "clang/Basic/DiagnosticOptions.h"
Chandler Carruth320d9662012-12-04 09:45:34 +000013#include "clang/Basic/FileManager.h"
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +000014#include "clang/Basic/LangOptions.h"
Duncan P. N. Exon Smith030d7d62017-03-20 17:58:26 +000015#include "clang/Basic/MemoryBufferCache.h"
Chandler Carruthfa0b3bb2012-12-04 09:53:37 +000016#include "clang/Basic/SourceManager.h"
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +000017#include "clang/Basic/TargetInfo.h"
Chandler Carruth320d9662012-12-04 09:45:34 +000018#include "clang/Basic/TargetOptions.h"
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +000019#include "clang/Lex/HeaderSearch.h"
Douglas Gregor40ba1a02012-10-24 16:24:38 +000020#include "clang/Lex/HeaderSearchOptions.h"
Erich Keane8691d6e2017-06-14 23:09:01 +000021#include "clang/Lex/MacroArgs.h"
22#include "clang/Lex/MacroInfo.h"
Chandler Carruth320d9662012-12-04 09:45:34 +000023#include "clang/Lex/ModuleLoader.h"
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +000024#include "clang/Lex/Preprocessor.h"
Douglas Gregor1452ff12012-10-24 17:46:57 +000025#include "clang/Lex/PreprocessorOptions.h"
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +000026#include "gtest/gtest.h"
27
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +000028using namespace clang;
29
30namespace {
31
Argyrios Kyrtzidis065d7202013-05-16 21:37:39 +000032// The test fixture.
33class LexerTest : public ::testing::Test {
34protected:
35 LexerTest()
36 : FileMgr(FileMgrOpts),
37 DiagID(new DiagnosticIDs()),
38 Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
39 SourceMgr(Diags, FileMgr),
40 TargetOpts(new TargetOptions)
41 {
42 TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
Alp Toker80758082014-07-06 05:26:44 +000043 Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +000044 }
45
Erich Keane8691d6e2017-06-14 23:09:01 +000046 std::unique_ptr<Preprocessor> CreatePP(StringRef Source,
47 TrivialModuleLoader &ModLoader) {
James Y Knightb214cbc2016-03-04 19:00:41 +000048 std::unique_ptr<llvm::MemoryBuffer> Buf =
49 llvm::MemoryBuffer::getMemBuffer(Source);
David Blaikie50a5f972014-08-29 07:59:55 +000050 SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
Argyrios Kyrtzidis065d7202013-05-16 21:37:39 +000051
Duncan P. N. Exon Smith030d7d62017-03-20 17:58:26 +000052 MemoryBufferCache PCMCache;
David Blaikie9c28cb32017-01-06 01:04:46 +000053 HeaderSearch HeaderInfo(std::make_shared<HeaderSearchOptions>(), SourceMgr,
54 Diags, LangOpts, Target.get());
Erich Keane8691d6e2017-06-14 23:09:01 +000055 std::unique_ptr<Preprocessor> PP = llvm::make_unique<Preprocessor>(
56 std::make_shared<PreprocessorOptions>(), Diags, LangOpts, SourceMgr,
57 PCMCache, HeaderInfo, ModLoader,
58 /*IILookup =*/nullptr,
59 /*OwnsHeaderSearch =*/false);
60 PP->Initialize(*Target);
61 PP->EnterMainSourceFile();
62 return PP;
63 }
64
65 std::vector<Token> Lex(StringRef Source) {
66 TrivialModuleLoader ModLoader;
67 auto PP = CreatePP(Source, ModLoader);
Argyrios Kyrtzidis065d7202013-05-16 21:37:39 +000068
69 std::vector<Token> toks;
70 while (1) {
71 Token tok;
Erich Keane8691d6e2017-06-14 23:09:01 +000072 PP->Lex(tok);
Argyrios Kyrtzidis065d7202013-05-16 21:37:39 +000073 if (tok.is(tok::eof))
74 break;
75 toks.push_back(tok);
76 }
77
Vedant Kumar95a2a7f2016-05-19 23:44:02 +000078 return toks;
79 }
80
81 std::vector<Token> CheckLex(StringRef Source,
82 ArrayRef<tok::TokenKind> ExpectedTokens) {
83 auto toks = Lex(Source);
Argyrios Kyrtzidis065d7202013-05-16 21:37:39 +000084 EXPECT_EQ(ExpectedTokens.size(), toks.size());
85 for (unsigned i = 0, e = ExpectedTokens.size(); i != e; ++i) {
86 EXPECT_EQ(ExpectedTokens[i], toks[i].getKind());
87 }
88
89 return toks;
90 }
91
92 std::string getSourceText(Token Begin, Token End) {
93 bool Invalid;
94 StringRef Str =
95 Lexer::getSourceText(CharSourceRange::getTokenRange(SourceRange(
96 Begin.getLocation(), End.getLocation())),
97 SourceMgr, LangOpts, &Invalid);
98 if (Invalid)
99 return "<INVALID>";
100 return Str;
101 }
102
103 FileSystemOptions FileMgrOpts;
104 FileManager FileMgr;
105 IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
106 DiagnosticsEngine Diags;
107 SourceManager SourceMgr;
108 LangOptions LangOpts;
Alp Toker80758082014-07-06 05:26:44 +0000109 std::shared_ptr<TargetOptions> TargetOpts;
Argyrios Kyrtzidis065d7202013-05-16 21:37:39 +0000110 IntrusiveRefCntPtr<TargetInfo> Target;
111};
112
113TEST_F(LexerTest, GetSourceTextExpandsToMaximumInMacroArgument) {
114 std::vector<tok::TokenKind> ExpectedTokens;
115 ExpectedTokens.push_back(tok::identifier);
116 ExpectedTokens.push_back(tok::l_paren);
117 ExpectedTokens.push_back(tok::identifier);
118 ExpectedTokens.push_back(tok::r_paren);
119
120 std::vector<Token> toks = CheckLex("#define M(x) x\n"
121 "M(f(M(i)))",
122 ExpectedTokens);
123
124 EXPECT_EQ("M(i)", getSourceText(toks[2], toks[2]));
125}
126
127TEST_F(LexerTest, GetSourceTextExpandsToMaximumInMacroArgumentForEndOfMacro) {
128 std::vector<tok::TokenKind> ExpectedTokens;
129 ExpectedTokens.push_back(tok::identifier);
130 ExpectedTokens.push_back(tok::identifier);
131
132 std::vector<Token> toks = CheckLex("#define M(x) x\n"
133 "M(M(i) c)",
134 ExpectedTokens);
135
136 EXPECT_EQ("M(i)", getSourceText(toks[0], toks[0]));
137}
138
139TEST_F(LexerTest, GetSourceTextExpandsInMacroArgumentForBeginOfMacro) {
140 std::vector<tok::TokenKind> ExpectedTokens;
141 ExpectedTokens.push_back(tok::identifier);
142 ExpectedTokens.push_back(tok::identifier);
143 ExpectedTokens.push_back(tok::identifier);
144
145 std::vector<Token> toks = CheckLex("#define M(x) x\n"
146 "M(c c M(i))",
147 ExpectedTokens);
148
149 EXPECT_EQ("c M(i)", getSourceText(toks[1], toks[2]));
150}
151
152TEST_F(LexerTest, GetSourceTextExpandsInMacroArgumentForEndOfMacro) {
153 std::vector<tok::TokenKind> ExpectedTokens;
154 ExpectedTokens.push_back(tok::identifier);
155 ExpectedTokens.push_back(tok::identifier);
156 ExpectedTokens.push_back(tok::identifier);
157
158 std::vector<Token> toks = CheckLex("#define M(x) x\n"
159 "M(M(i) c c)",
160 ExpectedTokens);
161
162 EXPECT_EQ("M(i) c", getSourceText(toks[0], toks[1]));
163}
164
165TEST_F(LexerTest, GetSourceTextInSeparateFnMacros) {
166 std::vector<tok::TokenKind> ExpectedTokens;
167 ExpectedTokens.push_back(tok::identifier);
168 ExpectedTokens.push_back(tok::identifier);
169 ExpectedTokens.push_back(tok::identifier);
170 ExpectedTokens.push_back(tok::identifier);
171
172 std::vector<Token> toks = CheckLex("#define M(x) x\n"
173 "M(c M(i)) M(M(i) c)",
174 ExpectedTokens);
175
176 EXPECT_EQ("<INVALID>", getSourceText(toks[1], toks[2]));
177}
178
179TEST_F(LexerTest, GetSourceTextWorksAcrossTokenPastes) {
180 std::vector<tok::TokenKind> ExpectedTokens;
181 ExpectedTokens.push_back(tok::identifier);
182 ExpectedTokens.push_back(tok::l_paren);
183 ExpectedTokens.push_back(tok::identifier);
184 ExpectedTokens.push_back(tok::r_paren);
185
186 std::vector<Token> toks = CheckLex("#define M(x) x\n"
187 "#define C(x) M(x##c)\n"
188 "M(f(C(i)))",
189 ExpectedTokens);
190
191 EXPECT_EQ("C(i)", getSourceText(toks[2], toks[2]));
192}
193
194TEST_F(LexerTest, GetSourceTextExpandsAcrossMultipleMacroCalls) {
195 std::vector<tok::TokenKind> ExpectedTokens;
196 ExpectedTokens.push_back(tok::identifier);
197 ExpectedTokens.push_back(tok::l_paren);
198 ExpectedTokens.push_back(tok::identifier);
199 ExpectedTokens.push_back(tok::r_paren);
200
201 std::vector<Token> toks = CheckLex("#define M(x) x\n"
202 "f(M(M(i)))",
203 ExpectedTokens);
204 EXPECT_EQ("M(M(i))", getSourceText(toks[2], toks[2]));
205}
206
207TEST_F(LexerTest, GetSourceTextInMiddleOfMacroArgument) {
208 std::vector<tok::TokenKind> ExpectedTokens;
209 ExpectedTokens.push_back(tok::identifier);
210 ExpectedTokens.push_back(tok::l_paren);
211 ExpectedTokens.push_back(tok::identifier);
212 ExpectedTokens.push_back(tok::r_paren);
213
214 std::vector<Token> toks = CheckLex("#define M(x) x\n"
215 "M(f(i))",
216 ExpectedTokens);
217 EXPECT_EQ("i", getSourceText(toks[2], toks[2]));
218}
219
220TEST_F(LexerTest, GetSourceTextExpandsAroundDifferentMacroCalls) {
221 std::vector<tok::TokenKind> ExpectedTokens;
222 ExpectedTokens.push_back(tok::identifier);
223 ExpectedTokens.push_back(tok::l_paren);
224 ExpectedTokens.push_back(tok::identifier);
225 ExpectedTokens.push_back(tok::r_paren);
226
227 std::vector<Token> toks = CheckLex("#define M(x) x\n"
228 "#define C(x) x\n"
229 "f(C(M(i)))",
230 ExpectedTokens);
231 EXPECT_EQ("C(M(i))", getSourceText(toks[2], toks[2]));
232}
233
234TEST_F(LexerTest, GetSourceTextOnlyExpandsIfFirstTokenInMacro) {
235 std::vector<tok::TokenKind> ExpectedTokens;
236 ExpectedTokens.push_back(tok::identifier);
237 ExpectedTokens.push_back(tok::l_paren);
238 ExpectedTokens.push_back(tok::identifier);
239 ExpectedTokens.push_back(tok::identifier);
240 ExpectedTokens.push_back(tok::r_paren);
241
242 std::vector<Token> toks = CheckLex("#define M(x) x\n"
243 "#define C(x) c x\n"
244 "f(C(M(i)))",
245 ExpectedTokens);
246 EXPECT_EQ("M(i)", getSourceText(toks[3], toks[3]));
247}
248
249TEST_F(LexerTest, GetSourceTextExpandsRecursively) {
250 std::vector<tok::TokenKind> ExpectedTokens;
251 ExpectedTokens.push_back(tok::identifier);
252 ExpectedTokens.push_back(tok::identifier);
253 ExpectedTokens.push_back(tok::l_paren);
254 ExpectedTokens.push_back(tok::identifier);
255 ExpectedTokens.push_back(tok::r_paren);
256
257 std::vector<Token> toks = CheckLex("#define M(x) x\n"
258 "#define C(x) c M(x)\n"
259 "C(f(M(i)))",
260 ExpectedTokens);
261 EXPECT_EQ("M(i)", getSourceText(toks[3], toks[3]));
262}
263
264TEST_F(LexerTest, LexAPI) {
265 std::vector<tok::TokenKind> ExpectedTokens;
266 ExpectedTokens.push_back(tok::l_square);
267 ExpectedTokens.push_back(tok::identifier);
268 ExpectedTokens.push_back(tok::r_square);
269 ExpectedTokens.push_back(tok::l_square);
270 ExpectedTokens.push_back(tok::identifier);
271 ExpectedTokens.push_back(tok::r_square);
272 ExpectedTokens.push_back(tok::identifier);
273 ExpectedTokens.push_back(tok::identifier);
274 ExpectedTokens.push_back(tok::identifier);
275 ExpectedTokens.push_back(tok::identifier);
276
277 std::vector<Token> toks = CheckLex("#define M(x) [x]\n"
278 "#define N(x) x\n"
279 "#define INN(x) x\n"
280 "#define NOF1 INN(val)\n"
281 "#define NOF2 val\n"
282 "M(foo) N([bar])\n"
283 "N(INN(val)) N(NOF1) N(NOF2) N(val)",
284 ExpectedTokens);
285
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +0000286 SourceLocation lsqrLoc = toks[0].getLocation();
287 SourceLocation idLoc = toks[1].getLocation();
288 SourceLocation rsqrLoc = toks[2].getLocation();
Argyrios Kyrtzidisa99e02d2012-01-19 15:59:14 +0000289 std::pair<SourceLocation,SourceLocation>
290 macroPair = SourceMgr.getExpansionRange(lsqrLoc);
291 SourceRange macroRange = SourceRange(macroPair.first, macroPair.second);
292
Argyrios Kyrtzidis1b07c342012-01-19 15:59:08 +0000293 SourceLocation Loc;
294 EXPECT_TRUE(Lexer::isAtStartOfMacroExpansion(lsqrLoc, SourceMgr, LangOpts, &Loc));
Argyrios Kyrtzidisa99e02d2012-01-19 15:59:14 +0000295 EXPECT_EQ(Loc, macroRange.getBegin());
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +0000296 EXPECT_FALSE(Lexer::isAtStartOfMacroExpansion(idLoc, SourceMgr, LangOpts));
297 EXPECT_FALSE(Lexer::isAtEndOfMacroExpansion(idLoc, SourceMgr, LangOpts));
Argyrios Kyrtzidis1b07c342012-01-19 15:59:08 +0000298 EXPECT_TRUE(Lexer::isAtEndOfMacroExpansion(rsqrLoc, SourceMgr, LangOpts, &Loc));
Argyrios Kyrtzidisa99e02d2012-01-19 15:59:14 +0000299 EXPECT_EQ(Loc, macroRange.getEnd());
300
Argyrios Kyrtzidis0d9e24b2012-02-03 05:58:29 +0000301 CharSourceRange range = Lexer::makeFileCharRange(
302 CharSourceRange::getTokenRange(lsqrLoc, idLoc), SourceMgr, LangOpts);
Argyrios Kyrtzidisa99e02d2012-01-19 15:59:14 +0000303 EXPECT_TRUE(range.isInvalid());
Argyrios Kyrtzidis0d9e24b2012-02-03 05:58:29 +0000304 range = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(idLoc, rsqrLoc),
Argyrios Kyrtzidisa99e02d2012-01-19 15:59:14 +0000305 SourceMgr, LangOpts);
306 EXPECT_TRUE(range.isInvalid());
Argyrios Kyrtzidis0d9e24b2012-02-03 05:58:29 +0000307 range = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(lsqrLoc, rsqrLoc),
Argyrios Kyrtzidisa99e02d2012-01-19 15:59:14 +0000308 SourceMgr, LangOpts);
309 EXPECT_TRUE(!range.isTokenRange());
310 EXPECT_EQ(range.getAsRange(),
311 SourceRange(macroRange.getBegin(),
312 macroRange.getEnd().getLocWithOffset(1)));
Argyrios Kyrtzidis7838a2b2012-01-19 15:59:19 +0000313
314 StringRef text = Lexer::getSourceText(
Argyrios Kyrtzidis0d9e24b2012-02-03 05:58:29 +0000315 CharSourceRange::getTokenRange(lsqrLoc, rsqrLoc),
316 SourceMgr, LangOpts);
Argyrios Kyrtzidis7838a2b2012-01-19 15:59:19 +0000317 EXPECT_EQ(text, "M(foo)");
Argyrios Kyrtzidis85e76712012-01-20 16:52:43 +0000318
319 SourceLocation macroLsqrLoc = toks[3].getLocation();
320 SourceLocation macroIdLoc = toks[4].getLocation();
321 SourceLocation macroRsqrLoc = toks[5].getLocation();
322 SourceLocation fileLsqrLoc = SourceMgr.getSpellingLoc(macroLsqrLoc);
323 SourceLocation fileIdLoc = SourceMgr.getSpellingLoc(macroIdLoc);
324 SourceLocation fileRsqrLoc = SourceMgr.getSpellingLoc(macroRsqrLoc);
325
Argyrios Kyrtzidis0d9e24b2012-02-03 05:58:29 +0000326 range = Lexer::makeFileCharRange(
327 CharSourceRange::getTokenRange(macroLsqrLoc, macroIdLoc),
328 SourceMgr, LangOpts);
Argyrios Kyrtzidis85e76712012-01-20 16:52:43 +0000329 EXPECT_EQ(SourceRange(fileLsqrLoc, fileIdLoc.getLocWithOffset(3)),
330 range.getAsRange());
331
Argyrios Kyrtzidis0d9e24b2012-02-03 05:58:29 +0000332 range = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(macroIdLoc, macroRsqrLoc),
Argyrios Kyrtzidis85e76712012-01-20 16:52:43 +0000333 SourceMgr, LangOpts);
334 EXPECT_EQ(SourceRange(fileIdLoc, fileRsqrLoc.getLocWithOffset(1)),
335 range.getAsRange());
336
337 macroPair = SourceMgr.getExpansionRange(macroLsqrLoc);
Argyrios Kyrtzidis0d9e24b2012-02-03 05:58:29 +0000338 range = Lexer::makeFileCharRange(
339 CharSourceRange::getTokenRange(macroLsqrLoc, macroRsqrLoc),
340 SourceMgr, LangOpts);
Argyrios Kyrtzidis85e76712012-01-20 16:52:43 +0000341 EXPECT_EQ(SourceRange(macroPair.first, macroPair.second.getLocWithOffset(1)),
342 range.getAsRange());
343
344 text = Lexer::getSourceText(
345 CharSourceRange::getTokenRange(SourceRange(macroLsqrLoc, macroIdLoc)),
346 SourceMgr, LangOpts);
347 EXPECT_EQ(text, "[bar");
Argyrios Kyrtzidisabff5f12012-01-23 16:58:33 +0000348
349
350 SourceLocation idLoc1 = toks[6].getLocation();
351 SourceLocation idLoc2 = toks[7].getLocation();
352 SourceLocation idLoc3 = toks[8].getLocation();
353 SourceLocation idLoc4 = toks[9].getLocation();
354 EXPECT_EQ("INN", Lexer::getImmediateMacroName(idLoc1, SourceMgr, LangOpts));
355 EXPECT_EQ("INN", Lexer::getImmediateMacroName(idLoc2, SourceMgr, LangOpts));
356 EXPECT_EQ("NOF2", Lexer::getImmediateMacroName(idLoc3, SourceMgr, LangOpts));
357 EXPECT_EQ("N", Lexer::getImmediateMacroName(idLoc4, SourceMgr, LangOpts));
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +0000358}
359
Vedant Kumar95a2a7f2016-05-19 23:44:02 +0000360TEST_F(LexerTest, DontMergeMacroArgsFromDifferentMacroFiles) {
361 std::vector<Token> toks =
362 Lex("#define helper1 0\n"
363 "void helper2(const char *, ...);\n"
364 "#define M1(a, ...) helper2(a, ##__VA_ARGS__)\n"
365 "#define M2(a, ...) M1(a, helper1, ##__VA_ARGS__)\n"
366 "void f1() { M2(\"a\", \"b\"); }");
367
368 // Check the file corresponding to the "helper1" macro arg in M2.
369 //
370 // The lexer used to report its size as 31, meaning that the end of the
371 // expansion would be on the *next line* (just past `M2("a", "b")`). Make
372 // sure that we get the correct end location (the comma after "helper1").
373 SourceLocation helper1ArgLoc = toks[20].getLocation();
374 EXPECT_EQ(SourceMgr.getFileIDSize(SourceMgr.getFileID(helper1ArgLoc)), 8U);
375}
376
Erich Keane8691d6e2017-06-14 23:09:01 +0000377TEST_F(LexerTest, DontOverallocateStringifyArgs) {
378 TrivialModuleLoader ModLoader;
379 auto PP = CreatePP("\"StrArg\", 5, 'C'", ModLoader);
380
381 llvm::BumpPtrAllocator Allocator;
Faisal Valiac506d72017-07-17 17:18:43 +0000382 std::array<IdentifierInfo *, 3> ParamList;
Erich Keane8691d6e2017-06-14 23:09:01 +0000383 MacroInfo *MI = PP->AllocateMacroInfo({});
384 MI->setIsFunctionLike();
Faisal Valiac506d72017-07-17 17:18:43 +0000385 MI->setParameterList(ParamList, Allocator);
386 EXPECT_EQ(3u, MI->getNumParams());
Erich Keane8691d6e2017-06-14 23:09:01 +0000387 EXPECT_TRUE(MI->isFunctionLike());
388
389 Token Eof;
390 Eof.setKind(tok::eof);
391 std::vector<Token> ArgTokens;
392 while (1) {
393 Token tok;
394 PP->Lex(tok);
395 if (tok.is(tok::eof)) {
396 ArgTokens.push_back(Eof);
397 break;
398 }
399 if (tok.is(tok::comma))
400 ArgTokens.push_back(Eof);
401 else
402 ArgTokens.push_back(tok);
403 }
404
Erich Keanecb7af852017-06-15 18:34:47 +0000405 auto MacroArgsDeleter = [&PP](MacroArgs *M) { M->destroy(*PP); };
406 std::unique_ptr<MacroArgs, decltype(MacroArgsDeleter)> MA(
407 MacroArgs::create(MI, ArgTokens, false, *PP), MacroArgsDeleter);
Erich Keane8691d6e2017-06-14 23:09:01 +0000408 Token Result = MA->getStringifiedArgument(0, *PP, {}, {});
409 EXPECT_EQ(tok::string_literal, Result.getKind());
410 EXPECT_STREQ("\"\\\"StrArg\\\"\"", Result.getLiteralData());
411 Result = MA->getStringifiedArgument(1, *PP, {}, {});
412 EXPECT_EQ(tok::string_literal, Result.getKind());
413 EXPECT_STREQ("\"5\"", Result.getLiteralData());
414 Result = MA->getStringifiedArgument(2, *PP, {}, {});
415 EXPECT_EQ(tok::string_literal, Result.getKind());
416 EXPECT_STREQ("\"'C'\"", Result.getLiteralData());
417#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
418 EXPECT_DEATH(MA->getStringifiedArgument(3, *PP, {}, {}),
419 "Invalid argument number!");
420#endif
421}
422
Argyrios Kyrtzidisd1699112012-01-19 15:59:01 +0000423} // anonymous namespace