TestToken: Add more tests (#1806)

This commit is contained in:
Rikard Falkeborn 2019-04-25 07:08:13 +02:00 committed by Daniel Marjamäki
parent da46bff1b3
commit 0ca217daef
1 changed files with 34 additions and 0 deletions

View File

@ -58,6 +58,7 @@ private:
TEST_CASE(multiCompare5);
TEST_CASE(getStrLength);
TEST_CASE(getStrSize);
TEST_CASE(getCharAt);
TEST_CASE(strValue);
TEST_CASE(deleteLast);
@ -294,6 +295,9 @@ private:
void getStrSize() const {
Token tok;
tok.str("\"\"");
ASSERT_EQUALS(sizeof(""), Token::getStrSize(&tok));
tok.str("\"abc\"");
ASSERT_EQUALS(sizeof("abc"), Token::getStrSize(&tok));
@ -304,6 +308,28 @@ private:
ASSERT_EQUALS(sizeof("\\"), Token::getStrSize(&tok));
}
void getCharAt() const {
Token tok;
tok.str("\"asdf\"");
ASSERT_EQUALS("a", Token::getCharAt(&tok, 0));
ASSERT_EQUALS("s", Token::getCharAt(&tok, 1));
tok.str("\"a\\ts\"");
ASSERT_EQUALS("\\t", Token::getCharAt(&tok, 1));
tok.str("\"\"");
ASSERT_EQUALS("\\0", Token::getCharAt(&tok, 0));
tok.str("L\"a\\ts\"");
ASSERT_EQUALS("a", Token::getCharAt(&tok, 0));
ASSERT_EQUALS("\\t", Token::getCharAt(&tok, 1));
tok.str("u\"a\\ts\"");
ASSERT_EQUALS("\\t", Token::getCharAt(&tok, 1));
ASSERT_EQUALS("s", Token::getCharAt(&tok, 2));
}
void strValue() const {
Token tok;
@ -328,6 +354,11 @@ private:
tok.str("\"a\\0\"");
ASSERT_EQUALS("a", tok.strValue());
tok.str("L\"a\\t\"");
ASSERT_EQUALS("a\t", tok.strValue());
tok.str("U\"a\\0\"");
ASSERT_EQUALS("a", tok.strValue());
}
@ -954,6 +985,9 @@ private:
givenACodeSampleToTokenize data3("return (t){1,2};");
ASSERT_EQUALS("return(t){1,2}", data3.tokens()->expressionString());
givenACodeSampleToTokenize data4("return L\"a\";");
ASSERT_EQUALS("returnL\"a\"", data4.tokens()->expressionString());
}
};