mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 11:36:36 +02:00
Added JsonParser_String_Tests.cpp
This commit is contained in:
@ -26,7 +26,9 @@ public:
|
|||||||
|
|
||||||
JsonValue createValue();
|
JsonValue createValue();
|
||||||
|
|
||||||
JsonArray parseArray(char* string);
|
JsonArray parseArray(char* json);
|
||||||
|
|
||||||
|
JsonValue parseValue(char* json);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void* allocateNode() = 0;
|
virtual void* allocateNode() = 0;
|
||||||
@ -41,4 +43,3 @@ private:
|
|||||||
JsonNode* createObjectNode();
|
JsonNode* createObjectNode();
|
||||||
JsonNode* createStringNode(const char* value);
|
JsonNode* createStringNode(const char* value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,6 +25,12 @@ JsonArray JsonBuffer::parseArray(char* json)
|
|||||||
return JsonArray(parser.parseAnything());
|
return JsonArray(parser.parseAnything());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonValue JsonBuffer::parseValue(char* json)
|
||||||
|
{
|
||||||
|
JsonParser parser(this, json);
|
||||||
|
return JsonValue(parser.parseAnything());
|
||||||
|
}
|
||||||
|
|
||||||
JsonNode* JsonBuffer::createArrayNode()
|
JsonNode* JsonBuffer::createArrayNode()
|
||||||
{
|
{
|
||||||
JsonNode* node = createNode();
|
JsonNode* node = createNode();
|
||||||
|
46
test/JsonParser_String_Tests.cpp
Normal file
46
test/JsonParser_String_Tests.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <ArduinoJson/StaticJsonBuffer.h>
|
||||||
|
#include <ArduinoJson/JsonValue.h>
|
||||||
|
|
||||||
|
class JsonParser_String_Tests : public testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
void whenInputIs(const char* json)
|
||||||
|
{
|
||||||
|
strcpy(_jsonString, json);
|
||||||
|
_result = _jsonBuffer.parseValue(_jsonString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void outputMustBe(const char* expected)
|
||||||
|
{
|
||||||
|
EXPECT_STREQ(expected, _result);
|
||||||
|
}
|
||||||
|
|
||||||
|
char _jsonString[256];
|
||||||
|
StaticJsonBuffer<42> _jsonBuffer;
|
||||||
|
const char* _result;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(JsonParser_String_Tests, SimpleString)
|
||||||
|
{
|
||||||
|
whenInputIs("\"hello world\"");
|
||||||
|
outputMustBe("hello world");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JsonParser_String_Tests, CurlyBraces)
|
||||||
|
{
|
||||||
|
whenInputIs("\"{hello:world}\"");
|
||||||
|
outputMustBe("{hello:world}");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JsonParser_String_Tests, SquareBraquets)
|
||||||
|
{
|
||||||
|
whenInputIs("\"[hello,world]\"");
|
||||||
|
outputMustBe("[hello,world]");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JsonParser_String_Tests, EscapedQuote)
|
||||||
|
{
|
||||||
|
whenInputIs("\"hello \\\"world\\\"\"");
|
||||||
|
outputMustBe("hello \"world\"");
|
||||||
|
}
|
Reference in New Issue
Block a user