Added test case double_plus and improved Token::printOut

This commit is contained in:
Reijo Tomperi 2009-02-12 20:32:59 +00:00
parent 5d3574bb03
commit 030b35c975
2 changed files with 34 additions and 4 deletions

View File

@ -471,12 +471,20 @@ void Token::printOut(const char *title) const
std::cout << "########"; std::cout << "########";
std::cout << "###" << std::endl; std::cout << "###" << std::endl;
unsigned int lineNum = 0;
for (const Token *t = this; t; t = t->next()) for (const Token *t = this; t; t = t->next())
{ {
std::cout << t->linenr() << ": " << t->str(); if (lineNum != t->linenr())
if (t->varId()) {
std::cout << " (" << t->varId() << ")"; std::cout << std::endl << t->linenr() << ": ";
lineNum = t->linenr();
}
std::cout << std::endl; std::cout << t->str();
// if (t->varId())
// std::cout << " (" << t->varId() << ")";
std::cout << " ";
} }
std::cout << std::endl;
} }

View File

@ -40,6 +40,7 @@ private:
TEST_CASE(sizeof1); TEST_CASE(sizeof1);
TEST_CASE(iftruefalse); TEST_CASE(iftruefalse);
TEST_CASE(combine_strings); TEST_CASE(combine_strings);
// TODO TEST_CASE(double_plus);
} }
std::string tok(const char code[]) std::string tok(const char code[])
@ -163,6 +164,27 @@ private:
"}\n"; "}\n";
ASSERT_EQUALS(tok(code2), tok(code1)); ASSERT_EQUALS(tok(code2), tok(code1));
} }
void double_plus()
{
{
const char code1[] = "void foo( int a )\n"
"{\n"
"a++;\n"
"a--;\n"
"++a;\n"
"--a;\n"
"}\n";
ASSERT_EQUALS("void foo ( int a ) { a ++ ; a -- ; ++ a ; -- a ; } ", tok(code1));
}
{
const char code1[] = "void foo( int a )\n"
"{\n"
"a=a+a;\n"
"}\n";
ASSERT_EQUALS("void foo ( int a ) { a = a + a ; } ", tok(code1));
}
}
}; };
REGISTER_TEST(TestSimplifyTokens) REGISTER_TEST(TestSimplifyTokens)