mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-14 11:06:35 +02:00
Changed JsonParser_String_Tests into QuotedString_ExtractFrom_Tests
This commit is contained in:
@ -1,113 +1,115 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <ArduinoJson/StaticJsonBuffer.h>
|
#include <ArduinoJson/Internals/QuotedString.h>
|
||||||
#include <ArduinoJson/JsonValue.h>
|
|
||||||
|
|
||||||
class JsonParser_String_Tests : public testing::Test
|
using namespace ArduinoJson::Internals;
|
||||||
|
|
||||||
|
class QuotedString_ExtractFrom_Tests : public testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void whenInputIs(const char* json)
|
void whenInputIs(const char* json)
|
||||||
{
|
{
|
||||||
strcpy(_jsonString, json);
|
strcpy(_jsonString, json);
|
||||||
_result = _jsonBuffer.parseValue(_jsonString);
|
_result = QuotedString::extractFrom(_jsonString, &_endp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void outputMustBe(const char* expected)
|
void outputMustBe(const char* expected)
|
||||||
{
|
{
|
||||||
EXPECT_STREQ(expected, _result);
|
EXPECT_STREQ(expected, _result);
|
||||||
|
EXPECT_EQ(_endp, _result + )
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char _jsonString[256];
|
char _jsonString[256];
|
||||||
StaticJsonBuffer<42> _jsonBuffer;
|
char* _result;
|
||||||
const char* _result;
|
char* _endp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EmptyDoubleQuotedString)
|
TEST_F(QuotedString_ExtractFrom_Tests, EmptyDoubleQuotedString)
|
||||||
{
|
{
|
||||||
whenInputIs("\"\"");
|
whenInputIs("\"\"");
|
||||||
outputMustBe("");
|
outputMustBe("");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EmptySingleQuotedString)
|
TEST_F(QuotedString_ExtractFrom_Tests, EmptySingleQuotedString)
|
||||||
{
|
{
|
||||||
whenInputIs("''");
|
whenInputIs("''");
|
||||||
outputMustBe("");
|
outputMustBe("");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, SimpleDoubleQuotedString)
|
TEST_F(QuotedString_ExtractFrom_Tests, SimpleDoubleQuotedString)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello world\"");
|
whenInputIs("\"hello world\"");
|
||||||
outputMustBe("hello world");
|
outputMustBe("hello world");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, CurlyBraces)
|
TEST_F(QuotedString_ExtractFrom_Tests, CurlyBraces)
|
||||||
{
|
{
|
||||||
whenInputIs("\"{hello:world}\"");
|
whenInputIs("\"{hello:world}\"");
|
||||||
outputMustBe("{hello:world}");
|
outputMustBe("{hello:world}");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, SquareBraquets)
|
TEST_F(QuotedString_ExtractFrom_Tests, SquareBraquets)
|
||||||
{
|
{
|
||||||
whenInputIs("\"[hello,world]\"");
|
whenInputIs("\"[hello,world]\"");
|
||||||
outputMustBe("[hello,world]");
|
outputMustBe("[hello,world]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EscapedDoubleQuote)
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedDoubleQuote)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello \\\"world\\\"\"");
|
whenInputIs("\"hello \\\"world\\\"\"");
|
||||||
outputMustBe("hello \"world\"");
|
outputMustBe("hello \"world\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EscapedSingleQuote)
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedSingleQuote)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello \\\'world\\\'\"");
|
whenInputIs("\"hello \\\'world\\\'\"");
|
||||||
outputMustBe("hello 'world'");
|
outputMustBe("hello 'world'");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EscapedSolidus)
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedSolidus)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello \\/world\\/\"");
|
whenInputIs("\"hello \\/world\\/\"");
|
||||||
outputMustBe("hello /world/");
|
outputMustBe("hello /world/");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EscapedReverseSolidus)
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedReverseSolidus)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello \\\\world\\\\\"");
|
whenInputIs("\"hello \\\\world\\\\\"");
|
||||||
outputMustBe("hello \\world\\");
|
outputMustBe("hello \\world\\");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EscapedBackspace)
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedBackspace)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello \\bworld\\b\"");
|
whenInputIs("\"hello \\bworld\\b\"");
|
||||||
outputMustBe("hello \bworld\b");
|
outputMustBe("hello \bworld\b");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EscapedFormfeed)
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedFormfeed)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello \\fworld\\f\"");
|
whenInputIs("\"hello \\fworld\\f\"");
|
||||||
outputMustBe("hello \fworld\f");
|
outputMustBe("hello \fworld\f");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EscapedNewline)
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedNewline)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello \\nworld\\n\"");
|
whenInputIs("\"hello \\nworld\\n\"");
|
||||||
outputMustBe("hello \nworld\n");
|
outputMustBe("hello \nworld\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EscapedCarriageReturn)
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedCarriageReturn)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello \\rworld\\r\"");
|
whenInputIs("\"hello \\rworld\\r\"");
|
||||||
outputMustBe("hello \rworld\r");
|
outputMustBe("hello \rworld\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_Tests, EscapedTab)
|
TEST_F(QuotedString_ExtractFrom_Tests, EscapedTab)
|
||||||
{
|
{
|
||||||
whenInputIs("\"hello \\tworld\\t\"");
|
whenInputIs("\"hello \\tworld\\t\"");
|
||||||
outputMustBe("hello \tworld\t");
|
outputMustBe("hello \tworld\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(JsonParser_String_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");
|
outputMustBe("1\"2\\3/4\b5\f6\n7\r8\t9");
|
Reference in New Issue
Block a user