diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 5b5c00204..5be123417 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -39,6 +39,9 @@ private: TEST_CASE(strValue); TEST_CASE(deleteLast); + + TEST_CASE(match1); + TEST_CASE(match2); } void nextprevious() @@ -121,6 +124,124 @@ private: tok.deleteNext(); ASSERT_EQUALS(true, tokensBack == &tok); } + + + + void match1() + { + // Match "%var% | %var%" + { + const std::string code("abc|def"); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Match.. + ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "%var% | %var%")); + } + + // Match "%var% || %var%" + { + const std::string code("abc||def"); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Match.. + ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "%var% || %var%")); + } + } + + void match2() + { + { + const std::string code(""); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Match.. + ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "!!else")); + } + + { + const std::string code(""); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Match.. + ASSERT_EQUALS(false, Token::Match(tokenizer.tokens(), "!!else something")); + } + + { + const std::string code("if ;"); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Match.. + ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "!!return if")); + } + + { + const std::string code("if ;"); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Match.. + ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "if ; !!else")); + } + + { + const std::string code("if ; something"); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Match.. + ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "if ; !!else")); + } + + { + const std::string code("else"); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Match.. + ASSERT_EQUALS(false, Token::Match(tokenizer.tokens(), "!!else")); + } + + { + const std::string code("if ; else"); + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Match.. + ASSERT_EQUALS(false, Token::Match(tokenizer.tokens(), "if ; !!else")); + } + } }; REGISTER_TEST(TestToken) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 9bfa20b59..9e6ff07ff 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -120,10 +120,6 @@ private: TEST_CASE(simplifyKnownVariables28); TEST_CASE(simplifyKnownVariables29); // ticket #1811 - TEST_CASE(match1); - - TEST_CASE(match2); - TEST_CASE(varid1); TEST_CASE(varid2); TEST_CASE(varid3); @@ -1785,122 +1781,6 @@ private: } } - void match1() - { - // Match "%var% | %var%" - { - const std::string code("abc|def"); - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Match.. - ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "%var% | %var%")); - } - - // Match "%var% || %var%" - { - const std::string code("abc||def"); - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Match.. - ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "%var% || %var%")); - } - } - - void match2() - { - { - const std::string code(""); - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Match.. - ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "!!else")); - } - - { - const std::string code(""); - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Match.. - ASSERT_EQUALS(false, Token::Match(tokenizer.tokens(), "!!else something")); - } - - { - const std::string code("if ;"); - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Match.. - ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "!!return if")); - } - - { - const std::string code("if ;"); - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Match.. - ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "if ; !!else")); - } - - { - const std::string code("if ; something"); - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Match.. - ASSERT_EQUALS(true, Token::Match(tokenizer.tokens(), "if ; !!else")); - } - - { - const std::string code("else"); - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Match.. - ASSERT_EQUALS(false, Token::Match(tokenizer.tokens(), "!!else")); - } - - { - const std::string code("if ; else"); - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - // Match.. - ASSERT_EQUALS(false, Token::Match(tokenizer.tokens(), "if ; !!else")); - } - } - std::string tokenizeDebugListing(const std::string &code, bool simplify = false) { Tokenizer tokenizer;