Skip to content

Commit 2bed69a

Browse files
committed
add/update tests
1 parent febf2f0 commit 2bed69a

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

test.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static std::string preprocess(const char code[], std::size_t size, const simplec
137137
std::vector<std::string> files;
138138
simplecpp::FileDataCache cache;
139139
simplecpp::TokenList tokens = makeTokenList(code, size, files, file);
140-
if (dui.removeComments)
140+
if (dui.removeSourceComments)
141141
tokens.removeComments();
142142
simplecpp::TokenList tokens2(files);
143143
simplecpp::preprocess(tokens2, tokens, files, cache, dui, outputList, macroUsage, ifCond);
@@ -528,7 +528,6 @@ static void comment()
528528
static void comment_multiline()
529529
{
530530
simplecpp::DUI dui;
531-
dui.removeComments = true;
532531

533532
const char code[] = "#define ABC {// \\\n"
534533
"}\n"
@@ -562,6 +561,27 @@ static void comment_multiline()
562561
ASSERT_EQUALS("// abc\ndef", readfile("// abc\\\ndef"));
563562
}
564563

564+
static void keep_comments()
565+
{
566+
simplecpp::DUI dui;
567+
dui.removeSourceComments = false;
568+
569+
{
570+
const char code[] = "/* comment */\n";
571+
ASSERT_EQUALS("/* comment */", preprocess(code,dui));
572+
}
573+
574+
{
575+
const char code[] = "// comment\n";
576+
ASSERT_EQUALS("// comment", preprocess(code,dui));
577+
}
578+
579+
{
580+
const char code[] = "#define MACRO /* comment */\nMACRO\n";
581+
ASSERT_EQUALS("\n/* comment */", preprocess(code,dui));
582+
}
583+
}
584+
565585

566586
static void constFold()
567587
{
@@ -664,7 +684,6 @@ static void define6()
664684
static void define7()
665685
{
666686
simplecpp::DUI dui;
667-
dui.removeComments = true;
668687

669688
const char code[] = "#define A(X) X+1\n"
670689
"A(1 /*23*/)";
@@ -1989,7 +2008,6 @@ static void has_include_2()
19892008
" #endif\n"
19902009
"#endif";
19912010
simplecpp::DUI dui;
1992-
dui.removeComments = true; // TODO: remove this
19932011
dui.includePaths.emplace_back(testSourceDir);
19942012
ASSERT_EQUALS("\n\nA", preprocess(code, dui)); // we default to latest standard internally
19952013
dui.std = "c++14";
@@ -2613,7 +2631,6 @@ static void missingHeader4()
26132631
const char code[] = "#/**/include <>\n";
26142632
simplecpp::OutputList outputList;
26152633
simplecpp::DUI dui;
2616-
dui.removeComments = true; // TODO: remove this
26172634
ASSERT_EQUALS("", preprocess(code, dui, &outputList));
26182635
ASSERT_EQUALS("file0,1,syntax_error,No header in #include\n", toString(outputList));
26192636
}
@@ -4066,6 +4083,7 @@ static void runTests(int argc, char **argv, Input input)
40664083

40674084
TEST_CASE(comment);
40684085
TEST_CASE(comment_multiline);
4086+
TEST_CASE(keep_comments);
40694087

40704088
TEST_CASE(constFold);
40714089

0 commit comments

Comments
 (0)