Add more tests for flow control simplification.

This commit is contained in:
Edoardo Prezioso 2011-11-18 21:05:35 +01:00
parent 44e348d018
commit fa34a14d57
1 changed files with 71 additions and 0 deletions

View File

@ -3143,6 +3143,67 @@ private:
ASSERT_EQUALS("void foo ( ) { " + *it + " ; { label : ; ok ( ) ; } }", tok(code));
}
{
std::string code = "void foo () {"
" " + *it + ";"
" switch (n) {"
" case 1:"
" label:"
" foo(); break;"
" default:"
" break;"
" }"
"}";
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; } }";
ASSERT_EQUALS(expected, tok(code));
}
{
std::string code = "void foo () {"
" " + *it + ";"
" switch (n) {"
" case 1:"
" label:"
" foo(); break;"
" default:"
" break; break;"
" }"
"}";
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; break ; } }";
std::string actual = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; } }";
TODO_ASSERT_EQUALS(expected, actual, tok(code));
}
{
std::string code = "void foo () {"
" " + *it + ";"
" switch (n) {"
" case 1:"
" label:"
" foo(); break; break;"
" default:"
" break;"
" }"
"}";
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; break ; } }";
ASSERT_EQUALS(expected, tok(code));
}
{
std::string code = "void foo () {"
" " + *it + ";"
" switch (n) {"
" case 1:"
" label:"
" foo(); break; break;"
" default:"
" break; break;"
" }"
"}";
std::string expected = "void foo ( ) { " + *it + " ; { label : ; foo ( ) ; break ; break ; } }";
ASSERT_EQUALS(expected, tok(code));
}
{
std::string code = "int f() { "
"switch (x) { case 1: " + *it + "; bar(); tack; { ticak(); " + *it + " } " + *it + " "
@ -3177,6 +3238,16 @@ private:
" case 3 : ; if ( blah6 ) { " + *it + " ; } break ; } }";
ASSERT_EQUALS(expected, tok(code));
}
{
std::string code = "void foo () {"
" " + *it + ";"
" switch (i) { case 0: switch (j) { case 0: foo(); }"
" case 1: switch (j) { case -1: bar(); label:; ok(); }"
" case 3: if (blah6) { boo(); break; } } }";
std::string expected = "void foo ( ) { " + *it + " ; { { label : ; ok ( ) ; } case 3 : ; if ( blah6 ) { boo ( ) ; break ; } } }";
ASSERT_EQUALS(expected, tok(code));
}
}
}