Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ static std::string preprocess(const char code[], const simplecpp::DUI &dui, simp
std::vector<std::string> files;
simplecpp::FileDataCache cache;
simplecpp::TokenList tokens = makeTokenList(code,files);
tokens.removeComments();
if (dui.removeComments)
tokens.removeComments();
simplecpp::TokenList tokens2(files);
simplecpp::preprocess(tokens2, tokens, files, cache, dui, outputList);
simplecpp::cleanup(cache);
Expand Down Expand Up @@ -432,33 +433,36 @@ static void comment()

static void comment_multiline()
{
simplecpp::DUI dui;
dui.removeComments = true;

const char code[] = "#define ABC {// \\\n"
"}\n"
"void f() ABC\n";
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code));
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code, dui));

const char code1[] = "#define ABC {// \\\r\n"
"}\n"
"void f() ABC\n";
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code1));
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code1, dui));

const char code2[] = "#define A 1// \\\r"
"\r"
"2\r"
"A\r";
ASSERT_EQUALS("\n\n2\n1", preprocess(code2));
ASSERT_EQUALS("\n\n2\n1", preprocess(code2, dui));

const char code3[] = "void f() {// \\ \n}\n";
ASSERT_EQUALS("void f ( ) {", preprocess(code3));
ASSERT_EQUALS("void f ( ) {", preprocess(code3, dui));

const char code4[] = "void f() {// \\\\\\\t\t\n}\n";
ASSERT_EQUALS("void f ( ) {", preprocess(code4));
ASSERT_EQUALS("void f ( ) {", preprocess(code4, dui));

const char code5[] = "void f() {// \\\\\\a\n}\n";
ASSERT_EQUALS("void f ( ) {\n}", preprocess(code5));
ASSERT_EQUALS("void f ( ) {\n}", preprocess(code5, dui));

const char code6[] = "void f() {// \\\n\n\n}\n";
ASSERT_EQUALS("void f ( ) {\n\n\n}", preprocess(code6));
ASSERT_EQUALS("void f ( ) {\n\n\n}", preprocess(code6, dui));

// #471 ensure there is newline in comment so that line-splicing can be detected by tools
ASSERT_EQUALS("// abc\ndef", readfile("// abc\\\ndef"));
Expand Down Expand Up @@ -565,9 +569,12 @@ static void define6()

static void define7()
{
simplecpp::DUI dui;
dui.removeComments = true;

const char code[] = "#define A(X) X+1\n"
"A(1 /*23*/)";
ASSERT_EQUALS("\n1 + 1", preprocess(code));
ASSERT_EQUALS("\n1 + 1", preprocess(code, dui));
}

static void define8() // 6.10.3.10
Expand Down
Loading