@@ -533,12 +533,15 @@ static void combineOperators_ellipsis()
533533
534534static void comment ()
535535{
536+ simplecpp::DUI dui;
537+ dui.removeComments = true ;
538+
536539 ASSERT_EQUALS (" // abc" , readfile (" // abc" ));
537- ASSERT_EQUALS (" " , preprocess (" // abc" ));
540+ ASSERT_EQUALS (" " , preprocess (" // abc" , dui ));
538541 ASSERT_EQUALS (" /*\n\n */abc" , readfile (" /*\n\n */abc" ));
539- ASSERT_EQUALS (" \n\n abc" , preprocess (" /*\n\n */abc" ));
542+ ASSERT_EQUALS (" \n\n abc" , preprocess (" /*\n\n */abc" , dui ));
540543 ASSERT_EQUALS (" * p = a / * b / * c ;" , readfile (" *p=a/ *b/ *c;" ));
541- ASSERT_EQUALS (" * p = a / * b / * c ;" , preprocess (" *p=a/ *b/ *c;" ));
544+ ASSERT_EQUALS (" * p = a / * b / * c ;" , preprocess (" *p=a/ *b/ *c;" , dui ));
542545}
543546
544547static void comment_multiline ()
@@ -578,6 +581,27 @@ static void comment_multiline()
578581 ASSERT_EQUALS (" // abc\n def" , readfile (" // abc\\\n def" ));
579582}
580583
584+ static void keep_comments ()
585+ {
586+ simplecpp::DUI dui;
587+ dui.removeComments = false ;
588+
589+ {
590+ const char code[] = " /* comment */\n " ;
591+ ASSERT_EQUALS (" /* comment */" , preprocess (code,dui));
592+ }
593+
594+ {
595+ const char code[] = " // comment\n " ;
596+ ASSERT_EQUALS (" // comment" , preprocess (code,dui));
597+ }
598+
599+ {
600+ const char code[] = " #define MACRO /* comment */\n MACRO\n " ;
601+ ASSERT_EQUALS (" \n /* comment */" , preprocess (code,dui));
602+ }
603+ }
604+
581605
582606static void constFold ()
583607{
@@ -2584,13 +2608,16 @@ static void location11()
25842608
25852609static void location12 ()
25862610{
2611+ simplecpp::DUI dui;
2612+ dui.removeComments = true ;
2613+
25872614 const char code[] =
25882615 " /**//**/#/**//**/line/**//**/3/**//**/\" file.c\" /**/\n "
25892616 " __LINE__ __FILE__\n " ;
25902617 ASSERT_EQUALS (" \n "
25912618 " #line 3 \" file.c\"\n "
25922619 " 3 \" file.c\" " ,
2593- preprocess (code));
2620+ preprocess (code, dui ));
25942621}
25952622
25962623
@@ -3244,6 +3271,7 @@ static void include9()
32443271 simplecpp::TokenList out (files);
32453272 simplecpp::DUI dui;
32463273 dui.includePaths .emplace_back (" ." );
3274+ dui.removeComments = true ;
32473275 simplecpp::preprocess (out, rawtokens_c, files, cache, dui);
32483276
32493277 ASSERT_EQUALS (" \n #line 2 \" 1.h\"\n x = 1 ;" , out.stringify ());
@@ -4383,6 +4411,7 @@ static void runTests(int argc, char **argv, Input input)
43834411
43844412 TEST_CASE (comment);
43854413 TEST_CASE (comment_multiline);
4414+ TEST_CASE (keep_comments);
43864415
43874416 TEST_CASE (constFold);
43884417
0 commit comments