unit testing: moved TestTokenizer::match tests to the TestToken

This commit is contained in:
Daniel Marjamäki 2010-09-07 20:42:29 +02:00
parent 5688412f00
commit 86a08b9f0e
2 changed files with 121 additions and 120 deletions

View File

@ -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)

View File

@ -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;