1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015-2016 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "CmdLineParser.h"
23 TEST(CCmdLineParser
, Null
)
25 CCmdLineParser
parser(nullptr);
26 EXPECT_FALSE(parser
.HasKey(L
"action"));
27 EXPECT_FALSE(parser
.HasVal(L
"action"));
28 EXPECT_EQ(nullptr, parser
.GetVal(L
"action"));
29 EXPECT_EQ(0, parser
.GetLongVal(L
"action"));
30 EXPECT_EQ(0, parser
.GetLongLongVal(L
"action"));
33 TEST(CCmdLineParser
, Empty
)
35 CCmdLineParser
parser(L
"");
36 EXPECT_FALSE(parser
.HasKey(L
"action"));
37 EXPECT_FALSE(parser
.HasVal(L
"action"));
38 EXPECT_EQ(nullptr, parser
.GetVal(L
"action"));
39 EXPECT_EQ(0, parser
.GetLongVal(L
"action"));
40 EXPECT_EQ(0, parser
.GetLongLongVal(L
"action"));
43 TEST(CCmdLineParser
, Text
)
45 CCmdLineParser
parser(L
"action");
46 EXPECT_FALSE(parser
.HasKey(L
"action"));
47 EXPECT_FALSE(parser
.HasVal(L
"action"));
48 EXPECT_EQ(nullptr, parser
.GetVal(L
"action"));
49 EXPECT_EQ(0, parser
.GetLongVal(L
"action"));
50 EXPECT_EQ(0, parser
.GetLongLongVal(L
"action"));
53 TEST(CCmdLineParser
, SingleSimpleArgValue
)
55 CString args
[] = { L
"/action", L
"-action" };
56 for (const CString
& arg
: args
)
58 CCmdLineParser
parser(arg
);
59 EXPECT_TRUE(parser
.HasKey(L
"action"));
60 EXPECT_FALSE(parser
.HasVal(L
"action"));
61 EXPECT_STREQ(L
"", parser
.GetVal(L
"action"));
62 EXPECT_EQ(0, parser
.GetLongVal(L
"action"));
63 EXPECT_EQ(0, parser
.GetLongLongVal(L
"action"));
67 TEST(CCmdLineParser
, PrefixSingleSimpleArgValue
)
69 CString args
[] = { L
"Something /action", L
"Something -action" };
70 for (const CString
& arg
: args
)
72 CCmdLineParser
parser(arg
);
73 EXPECT_TRUE(parser
.HasKey(L
"action"));
74 EXPECT_FALSE(parser
.HasVal(L
"action"));
75 EXPECT_STREQ(L
"", parser
.GetVal(L
"action"));
76 EXPECT_EQ(0, parser
.GetLongVal(L
"action"));
77 EXPECT_EQ(0, parser
.GetLongLongVal(L
"action"));
81 TEST(CCmdLineParser
, QuotedArgs
)
83 CString args
[] = { L
"\"/action\"", L
"\"-action\"", L
"/\"action\"", L
"/\"action\"" };
84 for (const CString
& arg
: args
)
86 CCmdLineParser
parser(arg
);
87 EXPECT_FALSE(parser
.HasKey(L
""));
88 EXPECT_FALSE(parser
.HasVal(L
""));
89 EXPECT_EQ(nullptr, parser
.GetVal(L
""));
90 EXPECT_FALSE(parser
.HasKey(L
"action"));
91 EXPECT_FALSE(parser
.HasVal(L
"action"));
92 EXPECT_EQ(nullptr, parser
.GetVal(L
"action"));
96 TEST(CCmdLineParser
, SingleSimpleArgStringValue
)
98 CString args
[] = { L
"/action:log", L
"/action log", L
"-action:log", L
"-action log" };
99 for (const CString
& arg
: args
)
101 CCmdLineParser
parser(arg
);
102 EXPECT_FALSE(parser
.HasKey(L
"log"));
103 EXPECT_FALSE(parser
.HasVal(L
"log"));
104 EXPECT_TRUE(parser
.HasKey(L
"action"));
105 EXPECT_TRUE(parser
.HasVal(L
"action"));
106 EXPECT_STREQ(L
"log", parser
.GetVal(L
"action"));
110 TEST(CCmdLineParser
, SingleArgStringSpaceValue
)
112 CString args
[] = { L
"/action:log 2", L
"/action log 2", L
"-action:log 2", L
"-action log 2" };
113 for (const CString
& arg
: args
)
115 CCmdLineParser
parser(arg
);
116 EXPECT_TRUE(parser
.HasKey(L
"action"));
117 EXPECT_TRUE(parser
.HasVal(L
"action"));
118 EXPECT_STREQ(L
"log", parser
.GetVal(L
"action"));
119 EXPECT_FALSE(parser
.HasKey(L
"log"));
120 EXPECT_FALSE(parser
.HasVal(L
"log"));
121 EXPECT_FALSE(parser
.HasKey(L
"2"));
122 EXPECT_FALSE(parser
.HasVal(L
"2"));
126 TEST(CCmdLineParser
, SingleArgStringSpaceValueQuoted
)
128 CString args
[] = { L
"/action:\"log 2\"", L
"/action \"log 2\"", L
"-action:\"log 2\"", L
"-action \"log 2\"" };
129 for (const CString
& arg
: args
)
131 CCmdLineParser
parser(arg
);
132 EXPECT_TRUE(parser
.HasKey(L
"action"));
133 EXPECT_TRUE(parser
.HasVal(L
"action"));
134 EXPECT_STREQ(L
"log 2", parser
.GetVal(L
"action"));
138 TEST(CCmdLineParser
, SingleArgStringValueQuoted
)
140 CString args
[] = { L
"/action:\"log\"", L
"/action \"log\"", L
"-action:\"log\"", L
"-action \"log\"" };
141 for (const CString
& arg
: args
)
143 CCmdLineParser
parser(arg
);
144 EXPECT_TRUE(parser
.HasKey(L
"action"));
145 EXPECT_TRUE(parser
.HasVal(L
"action"));
146 EXPECT_STREQ(L
"log", parser
.GetVal(L
"action"));
150 TEST(CCmdLineParser
, SingleArgStringValueQuotedWithQuotes
)
152 CString args
[] = { L
"/action:\"lo\"\"g\"", L
"/action \"lo\"\"g\"", L
"-action:\"lo\"\"g\"", L
"-action \"lo\"\"g\"" };
153 for (const CString
& arg
: args
)
155 CCmdLineParser
parser(arg
);
156 EXPECT_TRUE(parser
.HasKey(L
"action"));
157 EXPECT_TRUE(parser
.HasVal(L
"action"));
158 EXPECT_STREQ(L
"lo\"g", parser
.GetVal(L
"action"));
162 TEST(CCmdLineParser
, SingleArgStringValueQuotedWithQuotesAtEnd
)
164 CString args
[] = { L
"/action:\"lo\"\"\"", L
"/action \"lo\"\"\"", L
"-action:\"lo\"\"\"", L
"-action \"lo\"\"\"" };
165 for (const CString
& arg
: args
)
167 CCmdLineParser
parser(arg
);
168 EXPECT_TRUE(parser
.HasKey(L
"action"));
169 EXPECT_TRUE(parser
.HasVal(L
"action"));
170 EXPECT_STREQ(L
"lo\"", parser
.GetVal(L
"action"));
174 TEST(CCmdLineParser
, SingleArgStartingDoubleQuote
)
176 CString args
[] = { L
"/action:\"\"log", L
"/action \"\"log", L
"-action:\"\"log", L
"-action \"\"log" };
177 for (const CString
& arg
: args
)
179 CCmdLineParser
parser(arg
);
180 EXPECT_TRUE(parser
.HasKey(L
"action"));
181 EXPECT_FALSE(parser
.HasVal(L
"action"));
185 TEST(CCmdLineParser
, SingleArgStringValueQuote
)
187 CString args
[] = { L
"/action:l\"og", L
"/action l\"og", L
"-action:l\"og", L
"-action l\"og" };
188 for (const CString
& arg
: args
)
190 CCmdLineParser
parser(arg
);
191 EXPECT_TRUE(parser
.HasKey(L
"action"));
192 EXPECT_TRUE(parser
.HasVal(L
"action"));
193 EXPECT_STREQ(L
"l\"og", parser
.GetVal(L
"action"));
197 TEST(CCmdLineParser
, SingleArgStringValueQuotes1
)
199 CString args
[] = { L
"/action:l\"\"og", L
"/action l\"\"og", L
"-action:l\"\"og", L
"-action l\"\"og" };
200 for (const CString
& arg
: args
)
202 CCmdLineParser
parser(arg
);
203 EXPECT_TRUE(parser
.HasKey(L
"action"));
204 EXPECT_TRUE(parser
.HasVal(L
"action"));
205 EXPECT_STREQ(L
"l\"\"og", parser
.GetVal(L
"action"));
209 TEST(CCmdLineParser
, SingleArgStringValueQuotes2
)
211 CString args
[] = { L
"/action:l\"og\"", L
"/action l\"og\"", L
"-action:l\"og\"", L
"-action l\"og\"" };
212 for (const CString
& arg
: args
)
214 CCmdLineParser
parser(arg
);
215 EXPECT_TRUE(parser
.HasKey(L
"action"));
216 EXPECT_TRUE(parser
.HasVal(L
"action"));
217 EXPECT_STREQ(L
"l\"og\"", parser
.GetVal(L
"action"));
221 TEST(CCmdLineParser
, SingleArgStringValueQuoteAtEnd
)
223 CString args
[] = { L
"/action:log\"", L
"/action log\"", L
"-action:log\"", L
"-action log\"" };
224 for (const CString
& arg
: args
)
226 CCmdLineParser
parser(arg
);
227 EXPECT_TRUE(parser
.HasKey(L
"action"));
228 EXPECT_TRUE(parser
.HasVal(L
"action"));
229 EXPECT_STREQ(L
"log\"", parser
.GetVal(L
"action"));
233 TEST(CCmdLineParser
, SingleArgStringValueMultiQuote
)
235 CString args
[] = { L
"/action:l\"o\"g", L
"/action l\"o\"g", L
"-action:l\"o\"g", L
"-action l\"o\"g" };
236 for (const CString
& arg
: args
)
238 CCmdLineParser
parser(arg
);
239 EXPECT_TRUE(parser
.HasKey(L
"action"));
240 EXPECT_TRUE(parser
.HasVal(L
"action"));
241 EXPECT_STREQ(L
"l\"o\"g", parser
.GetVal(L
"action"));
245 TEST(CCmdLineParser
, SingleArgStringValueQuotedWithQuote
)
247 CString args
[] = { L
"/action:\"l\"o\"g\"", L
"/action \"l\"o\"g\"", L
"-action:\"l\"o\"g\"", L
"-action \"l\"o\"g\"" };
248 for (const CString
& arg
: args
)
250 CCmdLineParser
parser(arg
);
251 EXPECT_TRUE(parser
.HasKey(L
"action"));
252 EXPECT_TRUE(parser
.HasVal(L
"action"));
253 EXPECT_STREQ(L
"l", parser
.GetVal(L
"action"));
257 TEST(CCmdLineParser
, SingleArgStringValueQuotedWithTwoQuotes
)
259 CString args
[] = { L
"/action:\"l\"\"o\"\"g\"", L
"/action \"l\"\"o\"\"g\"", L
"-action:\"l\"\"o\"\"g\"", L
"-action \"l\"\"o\"\"g\"" };
260 for (const CString
& arg
: args
)
262 CCmdLineParser
parser(arg
);
263 EXPECT_TRUE(parser
.HasKey(L
"action"));
264 EXPECT_TRUE(parser
.HasVal(L
"action"));
265 EXPECT_STREQ(L
"l\"o\"g", parser
.GetVal(L
"action"));
269 TEST(CCmdLineParser
, SingleArgStringEmptyValue
)
271 CString args
[] = { L
"/action:\"\"", L
"/action \"\"", L
"-action:\"\"", L
"-action \"\"" };
272 for (const CString
& arg
: args
)
274 CCmdLineParser
parser(arg
);
275 EXPECT_TRUE(parser
.HasKey(L
"action"));
276 EXPECT_FALSE(parser
.HasVal(L
"action"));
280 TEST(CCmdLineParser
, SingleArgStringSingleQuote
)
282 CString args
[] = { L
"/action:\"\"\"\"", L
"/action \"\"\"\"", L
"-action:\"\"\"\"", L
"-action \"\"\"\"" };
283 for (const CString
& arg
: args
)
285 CCmdLineParser
parser(arg
);
286 EXPECT_TRUE(parser
.HasKey(L
"action"));
287 EXPECT_TRUE(parser
.HasVal(L
"action"));
288 EXPECT_STREQ(L
"\"", parser
.GetVal(L
"action"));
292 TEST(CCmdLineParser
, SingleArgStringDoubleQuote
)
294 CString args
[] = { L
"/action:\"\"\"\"\"\"", L
"/action \"\"\"\"\"\"", L
"-action:\"\"\"\"\"\"", L
"-action \"\"\"\"\"\"" };
295 for (const CString
& arg
: args
)
297 CCmdLineParser
parser(arg
);
298 EXPECT_TRUE(parser
.HasKey(L
"action"));
299 EXPECT_TRUE(parser
.HasVal(L
"action"));
300 EXPECT_STREQ(L
"\"\"", parser
.GetVal(L
"action"));
304 TEST(CCmdLineParser
, SingleArgNumberValue
)
306 CString args
[] = { L
"/action:10", L
"/action 10", L
"-action:10", L
"-action 10" };
307 for (const CString
& arg
: args
)
309 CCmdLineParser
parser(arg
);
310 EXPECT_TRUE(parser
.HasKey(L
"action"));
311 EXPECT_TRUE(parser
.HasVal(L
"action"));
312 EXPECT_STREQ(L
"10", parser
.GetVal(L
"action"));
313 EXPECT_EQ(10, parser
.GetLongVal(L
"action"));
314 EXPECT_EQ(10, parser
.GetLongLongVal(L
"action"));
318 TEST(CCmdLineParser
, SingleArgNumberValueQuoted
)
320 CString args
[] = { L
"/action:\"10\"", L
"/action \"10\"", L
"-action:\"10\"", L
"-action \"10\"" };
321 for (const CString
& arg
: args
)
323 CCmdLineParser
parser(arg
);
324 EXPECT_TRUE(parser
.HasKey(L
"action"));
325 EXPECT_TRUE(parser
.HasVal(L
"action"));
326 EXPECT_STREQ(L
"10", parser
.GetVal(L
"action"));
327 EXPECT_EQ(10, parser
.GetLongVal(L
"action"));
328 EXPECT_EQ(10, parser
.GetLongLongVal(L
"action"));
332 TEST(CCmdLineParser
, SingleArgNumberValuePrefix
)
334 CString args
[] = { L
"/action:010", L
"/action 010", L
"-action:010", L
"-action 010" };
335 for (const CString
& arg
: args
)
337 CCmdLineParser
parser(arg
);
338 EXPECT_TRUE(parser
.HasKey(L
"action"));
339 EXPECT_TRUE(parser
.HasVal(L
"action"));
340 EXPECT_STREQ(L
"010", parser
.GetVal(L
"action"));
341 EXPECT_EQ(10, parser
.GetLongVal(L
"action"));
342 EXPECT_EQ(10, parser
.GetLongLongVal(L
"action"));
346 TEST(CCmdLineParser
, SingleArgQuotedArg1
)
348 CString args
[] = { L
"/action:\"/test\"", L
"/action \"/test\"", L
"-action:\"/test\"", L
"-action \"/test\"" };
349 for (const CString
& arg
: args
)
351 CCmdLineParser
parser(arg
);
352 EXPECT_TRUE(parser
.HasKey(L
"action"));
353 EXPECT_TRUE(parser
.HasVal(L
"action"));
354 EXPECT_STREQ(L
"/test", parser
.GetVal(L
"action"));
358 TEST(CCmdLineParser
, SingleArgQuotedArg2
)
360 CString args
[] = { L
"/action:\"-test\"", L
"/action \"-test\"", L
"-action:\"-test\"", L
"-action \"-test\"" };
361 for (const CString
& arg
: args
)
363 CCmdLineParser
parser(arg
);
364 EXPECT_TRUE(parser
.HasKey(L
"action"));
365 EXPECT_TRUE(parser
.HasVal(L
"action"));
366 EXPECT_STREQ(L
"-test", parser
.GetVal(L
"action"));
370 TEST(CCmdLineParser
, SingleArgBrokenQuote
)
372 CString args
[] = { L
"/action:\"-test", L
"/action \"-test", L
"-action \"-test", L
"-action:\"-test" };
373 for (const CString
& arg
: args
)
375 CCmdLineParser
parser(arg
);
376 EXPECT_TRUE(parser
.HasKey(L
"action"));
377 EXPECT_TRUE(parser
.HasVal(L
"action"));
378 EXPECT_STREQ(L
"-test", parser
.GetVal(L
"action"));
379 EXPECT_FALSE(parser
.HasKey(L
"test"));
383 TEST(CCmdLineParser
, SingleArgBrokenQuoteAtEnd
)
385 CString args
[] = { L
"/action:\"", L
"/action \"", L
"-action \"", L
"-action:\"" };
386 for (const CString
& arg
: args
)
388 CCmdLineParser
parser(arg
);
389 EXPECT_TRUE(parser
.HasKey(L
"action"));
390 EXPECT_FALSE(parser
.HasVal(L
"action"));
394 TEST(CCmdLineParser
, SingleArgBrokenQuoteEndDoubleQuote
)
396 CString args
[] = { L
"/action:\"-test\"\"", L
"/action \"-test\"\"", L
"-action \"-test\"\"", L
"-action:\"-test\"\"" };
397 for (const CString
& arg
: args
)
399 CCmdLineParser
parser(arg
);
400 EXPECT_TRUE(parser
.HasKey(L
"action"));
401 EXPECT_TRUE(parser
.HasVal(L
"action"));
402 EXPECT_STREQ(L
"-test\"", parser
.GetVal(L
"action"));
403 EXPECT_FALSE(parser
.HasKey(L
"test"));
407 TEST(CCmdLineParser
, SingleArgBrokenQuote2
)
409 CString args
[] = { L
"/action \"-test \"bla\"", L
"/action:\"-test \"bla\"", L
"-action \"-test \"bla\"", L
"-action:\"-test \"bla\"" };
410 for (const CString
& arg
: args
)
412 CCmdLineParser
parser(arg
);
413 EXPECT_TRUE(parser
.HasKey(L
"action"));
414 EXPECT_TRUE(parser
.HasVal(L
"action"));
415 EXPECT_STREQ(L
"-test ", parser
.GetVal(L
"action"));
416 EXPECT_FALSE(parser
.HasKey(L
"test"));
417 EXPECT_FALSE(parser
.HasKey(L
"bla"));
421 TEST(CCmdLineParser
, SingleArgBrokenQuote3
)
423 CString args
[] = { L
"/action \"-test:\"bla\"", L
"/action:\"-test:\"bla\"", L
"-action \"-test:\"bla\"", L
"-action:\"-test:\"bla\"" };
424 for (const CString
& arg
: args
)
426 CCmdLineParser
parser(arg
);
427 EXPECT_TRUE(parser
.HasKey(L
"action"));
428 EXPECT_TRUE(parser
.HasVal(L
"action"));
429 EXPECT_STREQ(L
"-test:", parser
.GetVal(L
"action"));
430 EXPECT_FALSE(parser
.HasKey(L
"test"));
431 EXPECT_FALSE(parser
.HasKey(L
"bla"));
435 TEST(CCmdLineParser
, MultiArgSimpleArgs
)
437 CString args
[] = { L
"/action /rev", L
"/action -rev", L
"-action -rev", L
"-action /rev" };
438 for (const CString
& arg
: args
)
440 CCmdLineParser
parser(arg
);
441 EXPECT_TRUE(parser
.HasKey(L
"action"));
442 EXPECT_FALSE(parser
.HasVal(L
"action"));
443 EXPECT_EQ(0, parser
.GetLongVal(L
"action"));
444 EXPECT_EQ(0, parser
.GetLongLongVal(L
"action"));
445 EXPECT_TRUE(parser
.HasKey(L
"rev"));
446 EXPECT_FALSE(parser
.HasVal(L
"rev"));
447 EXPECT_EQ(0, parser
.GetLongVal(L
"rev"));
448 EXPECT_EQ(0, parser
.GetLongLongVal(L
"rev"));
452 TEST(CCmdLineParser
, MultiArgSimpleArgsDoubleSpace
)
454 CString args
[] = { L
"/action /rev", L
"/action -rev", L
"-action -rev", L
"-action /rev" };
455 for (const CString
& arg
: args
)
457 CCmdLineParser
parser(arg
);
458 EXPECT_TRUE(parser
.HasKey(L
"action"));
459 EXPECT_FALSE(parser
.HasVal(L
"action"));
460 EXPECT_EQ(0, parser
.GetLongVal(L
"action"));
461 EXPECT_EQ(0, parser
.GetLongLongVal(L
"action"));
462 EXPECT_TRUE(parser
.HasKey(L
"rev"));
463 EXPECT_FALSE(parser
.HasVal(L
"rev"));
464 EXPECT_EQ(0, parser
.GetLongVal(L
"rev"));
465 EXPECT_EQ(0, parser
.GetLongLongVal(L
"rev"));
469 TEST(CCmdLineParser
, MultiArgMixedArgs1
)
471 CString args
[] = { L
"/action log /rev", L
"/action log -rev", L
"-action log -rev", L
"-action log /rev" };
472 for (const CString
& arg
: args
)
474 CCmdLineParser
parser(arg
);
475 EXPECT_TRUE(parser
.HasKey(L
"action"));
476 EXPECT_TRUE(parser
.HasVal(L
"action"));
477 EXPECT_STREQ(L
"log", parser
.GetVal(L
"action"));
478 EXPECT_TRUE(parser
.HasKey(L
"rev"));
479 EXPECT_FALSE(parser
.HasVal(L
"rev"));
480 EXPECT_EQ(0, parser
.GetLongVal(L
"rev"));
481 EXPECT_EQ(0, parser
.GetLongLongVal(L
"rev"));
485 TEST(CCmdLineParser
, MultiArgMixedArgs2
)
487 CString args
[] = { L
"/action /rev def", L
"/action -rev def", L
"-action -rev def", L
"-action /rev def" };
488 for (const CString
& arg
: args
)
490 CCmdLineParser
parser(arg
);
491 EXPECT_TRUE(parser
.HasKey(L
"action"));
492 EXPECT_FALSE(parser
.HasVal(L
"action"));
493 EXPECT_TRUE(parser
.HasKey(L
"rev"));
494 EXPECT_TRUE(parser
.HasVal(L
"rev"));
495 EXPECT_STREQ(L
"def", parser
.GetVal(L
"rev"));
499 TEST(CCmdLineParser
, MultiArgStringSpaceValue
)
501 CString args
[] = { L
"/action:log 2 /rev def", L
"/action log 2 -rev def", L
"-action:log 2 -rev def", L
"-action log 2 /rev def" };
502 for (const CString
& arg
: args
)
504 CCmdLineParser
parser(arg
);
505 EXPECT_TRUE(parser
.HasKey(L
"action"));
506 EXPECT_TRUE(parser
.HasVal(L
"action"));
507 EXPECT_STREQ(L
"log", parser
.GetVal(L
"action"));
508 EXPECT_FALSE(parser
.HasKey(L
"log"));
509 EXPECT_FALSE(parser
.HasVal(L
"log"));
510 EXPECT_FALSE(parser
.HasKey(L
"2"));
511 EXPECT_FALSE(parser
.HasVal(L
"2"));
512 EXPECT_TRUE(parser
.HasKey(L
"rev"));
513 EXPECT_TRUE(parser
.HasVal(L
"rev"));
514 EXPECT_STREQ(L
"def", parser
.GetVal(L
"rev"));
518 TEST(CCmdLineParser
, MultiArgStringSpaceLeftOverQuote
)
520 CString args
[] = { L
"/action:log \"2 /rev def", L
"/action log \"2 -rev def", L
"-action:log \"2 -rev def", L
"-action log \"2 /rev def" };
521 for (const CString
& arg
: args
)
523 CCmdLineParser
parser(arg
);
524 EXPECT_TRUE(parser
.HasKey(L
"action"));
525 EXPECT_TRUE(parser
.HasVal(L
"action"));
526 EXPECT_STREQ(L
"log", parser
.GetVal(L
"action"));
527 EXPECT_TRUE(parser
.HasKey(L
"rev"));
528 EXPECT_TRUE(parser
.HasVal(L
"rev"));
529 EXPECT_STREQ(L
"def", parser
.GetVal(L
"rev"));
533 TEST(CCmdLineParser
, MultiArgStringSpaceValueQuoted
)
535 CString args
[] = { L
"/action:\"log 2\" /rev def", L
"/action \"log 2\" -rev def", L
"-action:\"log 2\" -rev def", L
"-action \"log 2\" /rev def" };
536 for (const CString
& arg
: args
)
538 CCmdLineParser
parser(arg
);
539 EXPECT_TRUE(parser
.HasKey(L
"action"));
540 EXPECT_TRUE(parser
.HasVal(L
"action"));
541 EXPECT_STREQ(L
"log 2", parser
.GetVal(L
"action"));
542 EXPECT_TRUE(parser
.HasKey(L
"rev"));
543 EXPECT_TRUE(parser
.HasVal(L
"rev"));
544 EXPECT_STREQ(L
"def", parser
.GetVal(L
"rev"));
548 TEST(CCmdLineParser
, MultiArgStringSpaceValueQuotedWithQuote
)
550 CString args
[] = { L
"/action:\"log \"\"2\" /rev def", L
"/action \"log \"\"2\" -rev def", L
"-action:\"log \"\"2\" -rev def", L
"-action \"log \"\"2\" /rev def" };
551 for (const CString
& arg
: args
)
553 CCmdLineParser
parser(arg
);
554 EXPECT_TRUE(parser
.HasKey(L
"action"));
555 EXPECT_TRUE(parser
.HasVal(L
"action"));
556 EXPECT_STREQ(L
"log \"2", parser
.GetVal(L
"action"));
557 EXPECT_TRUE(parser
.HasKey(L
"rev"));
558 EXPECT_TRUE(parser
.HasVal(L
"rev"));
559 EXPECT_STREQ(L
"def", parser
.GetVal(L
"rev"));
563 TEST(CCmdLineParser
, MultiArgStringSpaceValueQuoted2
)
565 CString args
[] = { L
"/action:\" log 2 \" /rev def", L
"/action \" log 2 \" -rev def", L
"-action:\" log 2 \" -rev def", L
"-action \" log 2 \" /rev def" };
566 for (const CString
& arg
: args
)
568 CCmdLineParser
parser(arg
);
569 EXPECT_TRUE(parser
.HasKey(L
"action"));
570 EXPECT_TRUE(parser
.HasVal(L
"action"));
571 EXPECT_STREQ(L
" log 2 ", parser
.GetVal(L
"action"));
572 EXPECT_TRUE(parser
.HasKey(L
"rev"));
573 EXPECT_TRUE(parser
.HasVal(L
"rev"));
574 EXPECT_STREQ(L
"def", parser
.GetVal(L
"rev"));
578 TEST(CCmdLineParser
, MultiArgStringSpaceValueQuotedWithQuote2
)
580 CString args
[] = { L
"/action:\" log 2 \"\"\" /rev def", L
"/action \" log 2 \"\"\" -rev def", L
"-action:\" log 2 \"\"\" -rev def", L
"-action \" log 2 \"\"\" /rev def" };
581 for (const CString
& arg
: args
)
583 CCmdLineParser
parser(arg
);
584 EXPECT_TRUE(parser
.HasKey(L
"action"));
585 EXPECT_TRUE(parser
.HasVal(L
"action"));
586 EXPECT_STREQ(L
" log 2 \"", parser
.GetVal(L
"action"));
587 EXPECT_TRUE(parser
.HasKey(L
"rev"));
588 EXPECT_TRUE(parser
.HasVal(L
"rev"));
589 EXPECT_STREQ(L
"def", parser
.GetVal(L
"rev"));
593 TEST(CCmdLineParser
, MultiArgValueTwice
)
595 CString args
[] = { L
"/action:\"log\" /action:\"log2\"", L
"/action \"log\" /action \"log2\"", L
"-action:\"log\" -action:\"log2\"", L
"-action \"log\" -action \"log2\"", L
"/action:\"log\" -action:\"log2\"", L
"/action \"log\" -action \"log2\"", L
"-action:\"log\" /action:\"log2\"", L
"-action \"log\" /action \"log2\"" };
596 for (const CString
& arg
: args
)
598 CCmdLineParser
parser(arg
);
599 EXPECT_TRUE(parser
.HasKey(L
"action"));
600 EXPECT_TRUE(parser
.HasVal(L
"action"));
601 EXPECT_STREQ(L
"log", parser
.GetVal(L
"action"));
605 TEST(CCmdLineParser
, SingleArgPath
)
607 CString args
[] = { L
"/path:C:\\test", L
"/path C:\\test", L
"-path C:\\test", L
"-path C:\\test" };
608 for (const CString
& arg
: args
)
610 CCmdLineParser
parser(arg
);
611 EXPECT_TRUE(parser
.HasKey(L
"path"));
612 EXPECT_TRUE(parser
.HasVal(L
"path"));
613 EXPECT_STREQ(L
"C:\\test", parser
.GetVal(L
"path"));
617 TEST(CCmdLineParser
, SingleArgPathQuoted
)
619 CString args
[] = { L
"/path:\"C:\\test\"", L
"/path \"C:\\test\"", L
"-path \"C:\\test\"", L
"-path \"C:\\test\"" };
620 for (const CString
& arg
: args
)
622 CCmdLineParser
parser(arg
);
623 EXPECT_TRUE(parser
.HasKey(L
"path"));
624 EXPECT_TRUE(parser
.HasVal(L
"path"));
625 EXPECT_STREQ(L
"C:\\test", parser
.GetVal(L
"path"));
629 TEST(CCmdLineParser
, SingleArgUnixPath
)
631 CString args
[] = { L
"/path:C:/test", L
"/path C:/test", L
"-path C:/test", L
"-path C:/test" };
632 for (const CString
& arg
: args
)
634 CCmdLineParser
parser(arg
);
635 EXPECT_TRUE(parser
.HasKey(L
"path"));
636 EXPECT_TRUE(parser
.HasVal(L
"path"));
637 EXPECT_STREQ(L
"C:/test", parser
.GetVal(L
"path"));
638 EXPECT_FALSE(parser
.HasKey(L
"C"));
639 EXPECT_FALSE(parser
.HasKey(L
"C:"));
644 TEST(CCmdLineParser
, SingleArgUnixPathQuoted
)
646 CString args
[] = { L
"/path:\"C:/test\"", L
"/path \"C:/test\"", L
"-path \"C:/test\"", L
"-path \"C:/test\"" };
647 for (const CString
& arg
: args
)
649 CCmdLineParser
parser(arg
);
650 EXPECT_TRUE(parser
.HasKey(L
"path"));
651 EXPECT_TRUE(parser
.HasVal(L
"path"));
652 EXPECT_STREQ(L
"C:/test", parser
.GetVal(L
"path"));
653 EXPECT_FALSE(parser
.HasKey(L
"C"));
654 EXPECT_FALSE(parser
.HasKey(L
"C:"));