preprocessor check for #define A 0

This commit is contained in:
Greg Hewgill 2011-02-08 20:59:30 +13:00
parent 1e0d538273
commit c0d3e002a9
1 changed files with 33 additions and 13 deletions

View File

@ -1226,21 +1226,41 @@ private:
void if_cond7() void if_cond7()
{ {
const char filedata[] = "#define A 1\n" {
"#if A==1\n" const char filedata[] = "#define A 1\n"
"a1;\n" "#if A==1\n"
"#endif\n"; "a1;\n"
"#endif\n";
// Preprocess => actual result.. // Preprocess => actual result..
std::istringstream istr(filedata); std::istringstream istr(filedata);
std::map<std::string, std::string> actual; std::map<std::string, std::string> actual;
Settings settings; Settings settings;
Preprocessor preprocessor(&settings, this); Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c"); preprocessor.preprocess(istr, actual, "file.c");
// Compare results.. // Compare results..
ASSERT_EQUALS(1, (int)actual.size()); ASSERT_EQUALS(1, (int)actual.size());
ASSERT_EQUALS("\n\na1;\n\n", actual[""]); ASSERT_EQUALS("\n\na1;\n\n", actual[""]);
}
{
const char filedata[] = "#define A 0\n"
"#if A\n"
"foo();\n"
"#endif\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS(2, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("\n\n\n\n", actual[""]);
}
} }