From b42ec0fe8bc30eebc9c7026cc8c9dcd69523739b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 13 Apr 2013 18:23:53 +0200 Subject: [PATCH] Simplify TestAssignIf test cases (else if) --- test/testassignif.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/testassignif.cpp b/test/testassignif.cpp index 0e61f78d8..11a604853 100644 --- a/test/testassignif.cpp +++ b/test/testassignif.cpp @@ -50,7 +50,15 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); + const std::string str1(tokenizer.tokens()->stringifyList(0,true)); tokenizer.simplifyTokenList(); + const std::string str2(tokenizer.tokens()->stringifyList(0,true)); + + // Ensure that the test case is not bad. + if (str1 != str2) { + warn(("Unsimplified code in test case\nstr1="+str1+"\nstr2="+str2).c_str()); + } + // Check char variable usage.. CheckAssignIf checkAssignIf(&tokenizer, &settings, this); @@ -124,7 +132,7 @@ private: check("void f(int x) {\n" " int y = x & 7;\n" " if (z) y=0;\n" - " else if (y==8);\n" // always false + " else { if (y==8); }\n" // always false "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false.\n", errout.str()); @@ -245,14 +253,14 @@ private: check("void foo(int x)\n" "{\n" " if (x & 7);\n" - " else if (x == 1);\n" + " else { if (x == 1); }\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 3.\n", errout.str()); check("void foo(int x)\n" "{\n" " if (x & 7);\n" - " else if (x & 1);\n" + " else { if (x & 1); }\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 3.\n", errout.str()); }