Skip to content

Commit 6e228a1

Browse files
committed
test.cpp: do not unconditionally remove comments
1 parent 6ddb8c6 commit 6e228a1

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

test.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ static std::string preprocess(const char code[], const simplecpp::DUI &dui, simp
107107
std::vector<std::string> files;
108108
simplecpp::FileDataCache cache;
109109
simplecpp::TokenList tokens = makeTokenList(code,files);
110-
tokens.removeComments();
110+
if (dui.removeComments)
111+
tokens.removeComments();
111112
simplecpp::TokenList tokens2(files);
112113
simplecpp::preprocess(tokens2, tokens, files, cache, dui, outputList);
113114
simplecpp::cleanup(cache);
@@ -437,33 +438,36 @@ static void comment()
437438

438439
static void comment_multiline()
439440
{
441+
simplecpp::DUI dui;
442+
dui.removeComments = true;
443+
440444
const char code[] = "#define ABC {// \\\n"
441445
"}\n"
442446
"void f() ABC\n";
443-
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code));
447+
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code, dui));
444448

445449
const char code1[] = "#define ABC {// \\\r\n"
446450
"}\n"
447451
"void f() ABC\n";
448-
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code1));
452+
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code1, dui));
449453

450454
const char code2[] = "#define A 1// \\\r"
451455
"\r"
452456
"2\r"
453457
"A\r";
454-
ASSERT_EQUALS("\n\n2\n1", preprocess(code2));
458+
ASSERT_EQUALS("\n\n2\n1", preprocess(code2, dui));
455459

456460
const char code3[] = "void f() {// \\ \n}\n";
457-
ASSERT_EQUALS("void f ( ) {", preprocess(code3));
461+
ASSERT_EQUALS("void f ( ) {", preprocess(code3, dui));
458462

459463
const char code4[] = "void f() {// \\\\\\\t\t\n}\n";
460-
ASSERT_EQUALS("void f ( ) {", preprocess(code4));
464+
ASSERT_EQUALS("void f ( ) {", preprocess(code4, dui));
461465

462466
const char code5[] = "void f() {// \\\\\\a\n}\n";
463-
ASSERT_EQUALS("void f ( ) {\n}", preprocess(code5));
467+
ASSERT_EQUALS("void f ( ) {\n}", preprocess(code5, dui));
464468

465469
const char code6[] = "void f() {// \\\n\n\n}\n";
466-
ASSERT_EQUALS("void f ( ) {\n\n\n}", preprocess(code6));
470+
ASSERT_EQUALS("void f ( ) {\n\n\n}", preprocess(code6, dui));
467471

468472
// #471 ensure there is newline in comment so that line-splicing can be detected by tools
469473
ASSERT_EQUALS("// abc\ndef", readfile("// abc\\\ndef"));
@@ -570,9 +574,12 @@ static void define6()
570574

571575
static void define7()
572576
{
577+
simplecpp::DUI dui;
578+
dui.removeComments = true;
579+
573580
const char code[] = "#define A(X) X+1\n"
574581
"A(1 /*23*/)";
575-
ASSERT_EQUALS("\n1 + 1", preprocess(code));
582+
ASSERT_EQUALS("\n1 + 1", preprocess(code, dui));
576583
}
577584

578585
static void define8() // 6.10.3.10

0 commit comments

Comments
 (0)