simplifyIfAddBraces : Fixed minor bug that caused the closing brace to be put on the wrong place
This commit is contained in:
parent
3a4e113f64
commit
78f46c5848
|
@ -49,6 +49,7 @@ private:
|
|||
TEST_CASE( ifAddBraces1 );
|
||||
TEST_CASE( ifAddBraces2 );
|
||||
TEST_CASE( ifAddBraces3 );
|
||||
TEST_CASE( ifAddBraces4 );
|
||||
|
||||
TEST_CASE( numeric_true_condition );
|
||||
|
||||
|
@ -288,6 +289,31 @@ private:
|
|||
ASSERT_EQUALS( std::string(" void f ( ) { if ( a ) { for ( ; ; ) { } } }"), ostr.str() );
|
||||
}
|
||||
|
||||
void ifAddBraces4()
|
||||
{
|
||||
const char code[] = "char * foo ()\n"
|
||||
"{\n"
|
||||
" char *str = malloc(10);\n"
|
||||
" if (somecondition)\n"
|
||||
" for ( ; ; )\n"
|
||||
" { }\n"
|
||||
" return str;\n"
|
||||
"}\n";
|
||||
|
||||
|
||||
// tokenize..
|
||||
Tokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
ASSERT_EQUALS( true, tokenizer.simplifyIfAddBraces() );
|
||||
|
||||
std::ostringstream ostr;
|
||||
for (const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||
ostr << " " << tok->str();
|
||||
ASSERT_EQUALS( std::string(" char * foo ( ) { char * str = malloc ( 10 ) ; if ( somecondition ) { for ( ; ; ) { } } return str ; }"), ostr.str() );
|
||||
}
|
||||
|
||||
void simplifyKnownVariables1()
|
||||
{
|
||||
const char code[] = "void f()\n"
|
||||
|
|
|
@ -1242,6 +1242,7 @@ bool Tokenizer::simplifyIfAddBraces()
|
|||
|
||||
// insert open brace..
|
||||
tok->insertToken("{");
|
||||
tok = tok->next();
|
||||
|
||||
// insert close brace..
|
||||
// In most cases it would work to just search for the next ';' and insert a closing brace after it.
|
||||
|
|
Loading…
Reference in New Issue