From 0ca217daef05433e8e3803563041fcd7f95fc1fb Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Thu, 25 Apr 2019 07:08:13 +0200 Subject: [PATCH] TestToken: Add more tests (#1806) --- test/testtoken.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 8c42c6a74..0c1970dba 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -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()); } };