Few tests added for checking simplify of if sentences

This commit is contained in:
Reijo Tomperi 2008-12-21 15:10:44 +00:00
parent bb198aed5e
commit 56c1a91e67
1 changed files with 29 additions and 1 deletions

View File

@ -37,6 +37,7 @@ private:
{
TEST_CASE( cast0 );
TEST_CASE( sizeof1 );
TEST_CASE( iftruefalse );
}
std::string tok(const char code[])
@ -44,8 +45,8 @@ private:
std::istringstream istr(code);
Tokenizer tokenizer;
tokenizer.tokenize( istr, "test.cpp" );
tokenizer.setVarId();
tokenizer.simplifyTokenList();
std::string ret;
for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next() )
{
@ -68,6 +69,33 @@ private:
const char code2[] = " struct ABC *abc = malloc(100); ";
ASSERT_EQUALS( tok(code1), tok(code2) );
}
void iftruefalse()
{
{
const char code1[] = " void f() { int a; bool use = false; if( use ) { a=0; } else {a=1;} } ";
const char code2[] = " void f() { int a; bool use = false; if( false ) { a=0; } else {a=1;} } ";
ASSERT_EQUALS( tok(code1), tok(code2) );
}
{
const char code1[] = " void f() { int a; bool use = true; if( use ) { a=0; } else {a=1;} } ";
const char code2[] = " void f() { int a; bool use = true; if( true ) { a=0; } else {a=1;} } ";
ASSERT_EQUALS( tok(code1), tok(code2) );
}
{
const char code1[] = " void f() { int a; int use = 5; if( use ) { a=0; } else {a=1;} } ";
const char code2[] = " void f() { int a; int use = 5; if( true ) { a=0; } else {a=1;} } ";
ASSERT_EQUALS( tok(code1), tok(code2) );
}
{
const char code1[] = " void f() { int a; int use = 0; if( use ) { a=0; } else {a=1;} } ";
const char code2[] = " void f() { int a; int use = 0; if( false ) { a=0; } else {a=1;} } ";
ASSERT_EQUALS( tok(code1), tok(code2) );
}
}
};
REGISTER_TEST( TestSimplifyTokens )