TestTokenizer : Broke up TestTokenizer::ifAddBraces into a few separate tests

This commit is contained in:
Daniel Marjamäki 2008-12-22 18:05:22 +00:00
parent 30c86f7107
commit 7a3fd268e1
1 changed files with 49 additions and 47 deletions

View File

@ -46,7 +46,9 @@ private:
TEST_CASE( const_and_volatile_functions ); TEST_CASE( const_and_volatile_functions );
TEST_CASE( ifAddBraces ); TEST_CASE( ifAddBraces1 );
TEST_CASE( ifAddBraces2 );
TEST_CASE( ifAddBraces3 );
TEST_CASE( numeric_true_condition ); TEST_CASE( numeric_true_condition );
@ -222,64 +224,64 @@ private:
ASSERT_EQUALS( std::string(" void f ( ) { ; }"), ostr.str() ); ASSERT_EQUALS( std::string(" void f ( ) { ; }"), ostr.str() );
} }
void ifAddBraces() void ifAddBraces1()
{ {
{ const char code[] = "void f()\n"
const char code[] = "void f()\n" "{\n"
"{\n" " if (a);\n"
" if (a);\n" "}\n";
"}\n";
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer;
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS( true, tokenizer.simplifyIfAddBraces() ); ASSERT_EQUALS( true, tokenizer.simplifyIfAddBraces() );
std::ostringstream ostr; std::ostringstream ostr;
for (const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS( std::string(" void f ( ) { if ( a ) { ; } }"), ostr.str() ); ASSERT_EQUALS( std::string(" void f ( ) { if ( a ) { ; } }"), ostr.str() );
} }
{ void ifAddBraces2()
const char code[] = "void f()\n" {
"{\n" const char code[] = "void f()\n"
" if (a) if (b) { }\n" "{\n"
"}\n"; " if (a) if (b) { }\n"
"}\n";
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer;
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS( true, tokenizer.simplifyIfAddBraces() ); ASSERT_EQUALS( true, tokenizer.simplifyIfAddBraces() );
std::ostringstream ostr; std::ostringstream ostr;
for (const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS( std::string(" void f ( ) { if ( a ) { if ( b ) { } } }"), ostr.str() ); ASSERT_EQUALS( std::string(" void f ( ) { if ( a ) { if ( b ) { } } }"), ostr.str() );
} }
{ void ifAddBraces3()
const char code[] = "void f()\n" {
"{\n" const char code[] = "void f()\n"
" if (a) for (;;) { }\n" "{\n"
"}\n"; " if (a) for (;;) { }\n"
"}\n";
// tokenize.. // tokenize..
Tokenizer tokenizer; Tokenizer tokenizer;
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS( true, tokenizer.simplifyIfAddBraces() ); ASSERT_EQUALS( true, tokenizer.simplifyIfAddBraces() );
std::ostringstream ostr; std::ostringstream ostr;
for (const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS( std::string(" void f ( ) { if ( a ) { for ( ; ; ) { } } }"), ostr.str() ); ASSERT_EQUALS( std::string(" void f ( ) { if ( a ) { for ( ; ; ) { } } }"), ostr.str() );
}
} }
void simplify_known_variables() void simplify_known_variables()