Moved some test cases from testtokenize into testsimplifytokens and added one TODO case.

This commit is contained in:
Reijo Tomperi 2009-10-06 12:40:50 +03:00
parent 272f0d3be5
commit 13fbd616da
2 changed files with 93 additions and 115 deletions

View File

@ -125,6 +125,7 @@ private:
TEST_CASE(simplifyTypedef4) TEST_CASE(simplifyTypedef4)
TEST_CASE(simplifyTypedef5) TEST_CASE(simplifyTypedef5)
TEST_CASE(reverseArraySyntax) TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition);
} }
std::string tok(const char code[], bool simplify = true) std::string tok(const char code[], bool simplify = true)
@ -1800,6 +1801,98 @@ private:
{ {
ASSERT_EQUALS("a [ 13 ]", tok("13[a]")); ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));
} }
void simplify_numeric_condition()
{
{
const char code[] =
"void f()\n"
"{\n"
"int x = 0;\n"
"if( !x || 0 )\n"
"{ g();\n"
"}\n"
"}";
ASSERT_EQUALS("void f ( ) { int x ; x = 0 ; { g ( ) ; } }", tok(code));
}
{
const char code[] =
"void f()\n"
"{\n"
"int x = 1;\n"
"if( !x )\n"
"{ g();\n"
"}\n"
"}";
ASSERT_EQUALS("void f ( ) { int x ; x = 1 ; }", tok(code));
}
{
const char code[] =
"void f()\n"
"{\n"
"bool x = true;\n"
"if( !x )\n"
"{ g();\n"
"}\n"
"}";
ASSERT_EQUALS("void f ( ) { bool x ; x = true ; }", tok(code));
}
{
const char code[] =
"void f()\n"
"{\n"
"bool x = false;\n"
"if( !x )\n"
"{ g();\n"
"}\n"
"}";
ASSERT_EQUALS("void f ( ) { bool x ; x = false ; { g ( ) ; } }", tok(code));
}
{
const char code[] = "void f()\n"
"{\n"
" if (5==5);\n"
"}\n";
ASSERT_EQUALS("void f ( ) { { ; } }", tok(code));
}
{
const char code[] = "void f()\n"
"{\n"
" if (4<5);\n"
"}\n";
ASSERT_EQUALS("void f ( ) { { ; } }", tok(code));
}
{
const char code[] = "void f()\n"
"{\n"
" if (5<5);\n"
"}\n";
ASSERT_EQUALS("void f ( ) { }", tok(code));
}
{
const char code[] = "void f()\n"
"{\n"
" if (13>12?true:false);\n"
"}\n";
TODO_ASSERT_EQUALS("void f ( ) { { ; } }", tok(code));
}
}
}; };
REGISTER_TEST(TestSimplifyTokens) REGISTER_TEST(TestSimplifyTokens)

View File

@ -64,7 +64,6 @@ private:
TEST_CASE(whileAddBraces); TEST_CASE(whileAddBraces);
TEST_CASE(doWhileAddBraces); TEST_CASE(doWhileAddBraces);
TEST_CASE(numeric_true_condition);
TEST_CASE(pointers_condition); TEST_CASE(pointers_condition);
TEST_CASE(simplifyKnownVariables1); TEST_CASE(simplifyKnownVariables1);
@ -127,7 +126,6 @@ private:
TEST_CASE(removeParantheses4); // Ticket #390 TEST_CASE(removeParantheses4); // Ticket #390
TEST_CASE(removeParantheses5); // Ticket #392 TEST_CASE(removeParantheses5); // Ticket #392
TEST_CASE(simplify_numeric_condition);
TEST_CASE(tokenize_double); TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings); TEST_CASE(tokenize_strings);
TEST_CASE(simplify_constants); TEST_CASE(simplify_constants);
@ -344,20 +342,6 @@ private:
} }
} }
void numeric_true_condition()
{
const char code[] = "void f()\n"
"{\n"
" if (5==5);\n"
"}\n";
ASSERT_EQUALS("void f ( )\n"
"{\n"
"{ ; }\n"
"}", tokenizeAndStringify(code, true));
}
void pointers_condition() void pointers_condition()
{ {
const char code[] = "void f()\n" const char code[] = "void f()\n"
@ -2032,105 +2016,6 @@ private:
} }
} }
void simplify_numeric_condition()
{
{
const char code[] =
"void f()\n"
"{\n"
"int x = 0;\n"
"if( !x || 0 )\n"
"{ g();\n"
"}\n"
"}";
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId();
tokenizer.simplifyTokenList();
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
ASSERT_EQUALS(" void f ( ) { int x ; x = 0 ; { g ( ) ; } }", ostr.str());
}
{
const char code[] =
"void f()\n"
"{\n"
"int x = 1;\n"
"if( !x )\n"
"{ g();\n"
"}\n"
"}";
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId();
tokenizer.simplifyTokenList();
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
ASSERT_EQUALS(" void f ( ) { int x ; x = 1 ; }", ostr.str());
}
{
const char code[] =
"void f()\n"
"{\n"
"bool x = true;\n"
"if( !x )\n"
"{ g();\n"
"}\n"
"}";
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId();
tokenizer.simplifyTokenList();
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
ASSERT_EQUALS(" void f ( ) { bool x ; x = true ; }", ostr.str());
}
{
const char code[] =
"void f()\n"
"{\n"
"bool x = false;\n"
"if( !x )\n"
"{ g();\n"
"}\n"
"}";
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId();
tokenizer.simplifyTokenList();
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
ASSERT_EQUALS(" void f ( ) { bool x ; x = false ; { g ( ) ; } }", ostr.str());
}
}
void tokenize_double() void tokenize_double()
{ {
const char code[] = "void f()\n" const char code[] = "void f()\n"