From fa34a14d57bb8149179584b4ce00f59d90f93a06 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Fri, 18 Nov 2011 21:05:35 +0100 Subject: [PATCH] Add more tests for flow control simplification. --- test/testsimplifytokens.cpp | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index f96042267..2afe82da2 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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)); + } } }