Files
ArduinoJson/test/QuotedString_ExtractFrom_Tests.cpp

116 lines
2.6 KiB
C++
Raw Normal View History

2014-10-16 21:54:42 +02:00
#include <gtest/gtest.h>
#include <ArduinoJson/Internals/QuotedString.h>
2014-10-16 21:54:42 +02:00
using namespace ArduinoJson::Internals;
class QuotedString_ExtractFrom_Tests : public testing::Test
2014-10-16 21:54:42 +02:00
{
protected:
void whenInputIs(const char* json)
{
strcpy(_jsonString, json);
_result = QuotedString::extractFrom(_jsonString, &_endp);
2014-10-16 21:54:42 +02:00
}
void outputMustBe(const char* expected)
{
EXPECT_STREQ(expected, _result);
EXPECT_EQ(_endp, _result + )
2014-10-16 21:54:42 +02:00
}
private:
2014-10-16 21:54:42 +02:00
char _jsonString[256];
char* _result;
char* _endp;
2014-10-16 21:54:42 +02:00
};
2014-10-17 19:57:00 +02:00
TEST_F(QuotedString_ExtractFrom_Tests, EmptyDoubleQuotedString)
2014-10-17 19:57:00 +02:00
{
whenInputIs("\"\"");
outputMustBe("");
}
TEST_F(QuotedString_ExtractFrom_Tests, EmptySingleQuotedString)
{
whenInputIs("''");
outputMustBe("");
}
TEST_F(QuotedString_ExtractFrom_Tests, SimpleDoubleQuotedString)
2014-10-16 21:54:42 +02:00
{
whenInputIs("\"hello world\"");
outputMustBe("hello world");
}
TEST_F(QuotedString_ExtractFrom_Tests, CurlyBraces)
2014-10-16 21:54:42 +02:00
{
whenInputIs("\"{hello:world}\"");
outputMustBe("{hello:world}");
}
TEST_F(QuotedString_ExtractFrom_Tests, SquareBraquets)
2014-10-16 21:54:42 +02:00
{
whenInputIs("\"[hello,world]\"");
outputMustBe("[hello,world]");
}
TEST_F(QuotedString_ExtractFrom_Tests, EscapedDoubleQuote)
2014-10-16 21:54:42 +02:00
{
whenInputIs("\"hello \\\"world\\\"\"");
outputMustBe("hello \"world\"");
2014-10-17 19:57:00 +02:00
}
TEST_F(QuotedString_ExtractFrom_Tests, EscapedSingleQuote)
2014-10-17 19:57:00 +02:00
{
whenInputIs("\"hello \\\'world\\\'\"");
outputMustBe("hello 'world'");
2014-10-17 22:32:55 +02:00
}
TEST_F(QuotedString_ExtractFrom_Tests, EscapedSolidus)
2014-10-17 22:32:55 +02:00
{
whenInputIs("\"hello \\/world\\/\"");
outputMustBe("hello /world/");
}
TEST_F(QuotedString_ExtractFrom_Tests, EscapedReverseSolidus)
2014-10-17 22:32:55 +02:00
{
whenInputIs("\"hello \\\\world\\\\\"");
outputMustBe("hello \\world\\");
}
TEST_F(QuotedString_ExtractFrom_Tests, EscapedBackspace)
2014-10-17 22:32:55 +02:00
{
whenInputIs("\"hello \\bworld\\b\"");
2014-10-17 22:32:55 +02:00
outputMustBe("hello \bworld\b");
}
TEST_F(QuotedString_ExtractFrom_Tests, EscapedFormfeed)
2014-10-17 22:32:55 +02:00
{
whenInputIs("\"hello \\fworld\\f\"");
2014-10-17 22:32:55 +02:00
outputMustBe("hello \fworld\f");
}
TEST_F(QuotedString_ExtractFrom_Tests, EscapedNewline)
2014-10-17 22:32:55 +02:00
{
whenInputIs("\"hello \\nworld\\n\"");
2014-10-17 22:32:55 +02:00
outputMustBe("hello \nworld\n");
}
TEST_F(QuotedString_ExtractFrom_Tests, EscapedCarriageReturn)
2014-10-17 22:32:55 +02:00
{
whenInputIs("\"hello \\rworld\\r\"");
2014-10-17 22:32:55 +02:00
outputMustBe("hello \rworld\r");
}
TEST_F(QuotedString_ExtractFrom_Tests, EscapedTab)
2014-10-17 22:32:55 +02:00
{
whenInputIs("\"hello \\tworld\\t\"");
2014-10-17 22:32:55 +02:00
outputMustBe("hello \tworld\t");
}
TEST_F(QuotedString_ExtractFrom_Tests, AllEscapedCharsTogether)
2014-10-17 22:32:55 +02:00
{
whenInputIs("\"1\\\"2\\\\3\\/4\\b5\\f6\\n7\\r8\\t9\"");
outputMustBe("1\"2\\3/4\b5\f6\n7\r8\t9");
2014-10-16 21:54:42 +02:00
}