Added tests of the trailing string

This commit is contained in:
Benoit Blanchon
2014-10-18 22:25:48 +02:00
parent b19a37538c
commit 1abb8ac6ae

View File

@ -9,108 +9,134 @@ protected:
void whenInputIs(const char* json) void whenInputIs(const char* json)
{ {
strcpy(_jsonString, json); strcpy(_jsonString, json);
_result = QuotedString::extractFrom(_jsonString, &_endp); _result = QuotedString::extractFrom(_jsonString, &_trailing);
} }
void outputMustBe(const char* expected) void resultMustBe(const char* expected)
{ {
EXPECT_STREQ(expected, _result); EXPECT_STREQ(expected, _result);
EXPECT_EQ(_endp, _result + ) }
void trailingMustBe(const char* expected)
{
EXPECT_STREQ(expected, _trailing);
} }
private: private:
char _jsonString[256]; char _jsonString[256];
char* _result; char* _result;
char* _endp; char* _trailing;
}; };
TEST_F(QuotedString_ExtractFrom_Tests, EmptyDoubleQuotedString) TEST_F(QuotedString_ExtractFrom_Tests, EmptyDoubleQuotedString)
{ {
whenInputIs("\"\""); whenInputIs("\"\"");
outputMustBe("");
resultMustBe("");
trailingMustBe("");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EmptySingleQuotedString) TEST_F(QuotedString_ExtractFrom_Tests, EmptySingleQuotedString)
{ {
whenInputIs("''"); whenInputIs("''");
outputMustBe("");
resultMustBe("");
trailingMustBe("");
} }
TEST_F(QuotedString_ExtractFrom_Tests, SimpleDoubleQuotedString) TEST_F(QuotedString_ExtractFrom_Tests, SimpleDoubleQuotedString)
{ {
whenInputIs("\"hello world\""); whenInputIs("\"hello world\"");
outputMustBe("hello world");
resultMustBe("hello world");
trailingMustBe("");
}
TEST_F(QuotedString_ExtractFrom_Tests, DoubleQuotedStringWithTrailing)
{
whenInputIs("\"hello\" world");
resultMustBe("hello");
trailingMustBe(" world");
}
TEST_F(QuotedString_ExtractFrom_Tests, SingleQuotedStringWithTrailing)
{
whenInputIs("'hello' world");
resultMustBe("hello");
trailingMustBe(" world");
} }
TEST_F(QuotedString_ExtractFrom_Tests, CurlyBraces) TEST_F(QuotedString_ExtractFrom_Tests, CurlyBraces)
{ {
whenInputIs("\"{hello:world}\""); whenInputIs("\"{hello:world}\"");
outputMustBe("{hello:world}"); resultMustBe("{hello:world}");
} }
TEST_F(QuotedString_ExtractFrom_Tests, SquareBraquets) TEST_F(QuotedString_ExtractFrom_Tests, SquareBraquets)
{ {
whenInputIs("\"[hello,world]\""); whenInputIs("\"[hello,world]\"");
outputMustBe("[hello,world]"); resultMustBe("[hello,world]");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EscapedDoubleQuote) TEST_F(QuotedString_ExtractFrom_Tests, EscapedDoubleQuote)
{ {
whenInputIs("\"hello \\\"world\\\"\""); whenInputIs("\"hello \\\"world\\\"\"");
outputMustBe("hello \"world\""); resultMustBe("hello \"world\"");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EscapedSingleQuote) TEST_F(QuotedString_ExtractFrom_Tests, EscapedSingleQuote)
{ {
whenInputIs("\"hello \\\'world\\\'\""); whenInputIs("\"hello \\\'world\\\'\"");
outputMustBe("hello 'world'"); resultMustBe("hello 'world'");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EscapedSolidus) TEST_F(QuotedString_ExtractFrom_Tests, EscapedSolidus)
{ {
whenInputIs("\"hello \\/world\\/\""); whenInputIs("\"hello \\/world\\/\"");
outputMustBe("hello /world/"); resultMustBe("hello /world/");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EscapedReverseSolidus) TEST_F(QuotedString_ExtractFrom_Tests, EscapedReverseSolidus)
{ {
whenInputIs("\"hello \\\\world\\\\\""); whenInputIs("\"hello \\\\world\\\\\"");
outputMustBe("hello \\world\\"); resultMustBe("hello \\world\\");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EscapedBackspace) TEST_F(QuotedString_ExtractFrom_Tests, EscapedBackspace)
{ {
whenInputIs("\"hello \\bworld\\b\""); whenInputIs("\"hello \\bworld\\b\"");
outputMustBe("hello \bworld\b"); resultMustBe("hello \bworld\b");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EscapedFormfeed) TEST_F(QuotedString_ExtractFrom_Tests, EscapedFormfeed)
{ {
whenInputIs("\"hello \\fworld\\f\""); whenInputIs("\"hello \\fworld\\f\"");
outputMustBe("hello \fworld\f"); resultMustBe("hello \fworld\f");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EscapedNewline) TEST_F(QuotedString_ExtractFrom_Tests, EscapedNewline)
{ {
whenInputIs("\"hello \\nworld\\n\""); whenInputIs("\"hello \\nworld\\n\"");
outputMustBe("hello \nworld\n"); resultMustBe("hello \nworld\n");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EscapedCarriageReturn) TEST_F(QuotedString_ExtractFrom_Tests, EscapedCarriageReturn)
{ {
whenInputIs("\"hello \\rworld\\r\""); whenInputIs("\"hello \\rworld\\r\"");
outputMustBe("hello \rworld\r"); resultMustBe("hello \rworld\r");
} }
TEST_F(QuotedString_ExtractFrom_Tests, EscapedTab) TEST_F(QuotedString_ExtractFrom_Tests, EscapedTab)
{ {
whenInputIs("\"hello \\tworld\\t\""); whenInputIs("\"hello \\tworld\\t\"");
outputMustBe("hello \tworld\t"); resultMustBe("hello \tworld\t");
} }
TEST_F(QuotedString_ExtractFrom_Tests, AllEscapedCharsTogether) TEST_F(QuotedString_ExtractFrom_Tests, AllEscapedCharsTogether)
{ {
whenInputIs("\"1\\\"2\\\\3\\/4\\b5\\f6\\n7\\r8\\t9\""); whenInputIs("\"1\\\"2\\\\3\\/4\\b5\\f6\\n7\\r8\\t9\"");
outputMustBe("1\"2\\3/4\b5\f6\n7\r8\t9"); resultMustBe("1\"2\\3/4\b5\f6\n7\r8\t9");
} }