mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 11:36:36 +02:00
More test on object parsing
This commit is contained in:
@ -211,7 +211,12 @@ JsonNode* JsonParser::parseObject()
|
|||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
node->addChild(parseObjectKeyValue());
|
JsonNode* keyValueNode = parseObjectKeyValue();
|
||||||
|
|
||||||
|
if (!keyValueNode)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
node->addChild(keyValueNode);
|
||||||
|
|
||||||
skipSpaces();
|
skipSpaces();
|
||||||
|
|
||||||
@ -229,6 +234,9 @@ JsonNode* JsonParser::parseObjectKeyValue()
|
|||||||
{
|
{
|
||||||
const char* key = QuotedString::extractFrom(_ptr, &_ptr);
|
const char* key = QuotedString::extractFrom(_ptr, &_ptr);
|
||||||
|
|
||||||
|
if (!key)
|
||||||
|
return 0;
|
||||||
|
|
||||||
skipSpaces();
|
skipSpaces();
|
||||||
|
|
||||||
if (!isColon())
|
if (!isColon())
|
||||||
|
@ -10,7 +10,6 @@ void JsonWriter::writeString(char const* value)
|
|||||||
|
|
||||||
void JsonWriter::writeInteger(long value)
|
void JsonWriter::writeInteger(long value)
|
||||||
{
|
{
|
||||||
|
|
||||||
_length += _sink->print(value);
|
_length += _sink->print(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,5 +20,5 @@ void JsonWriter::writeBoolean(bool value)
|
|||||||
|
|
||||||
void JsonWriter::writeDouble(double value, int decimals)
|
void JsonWriter::writeDouble(double value, int decimals)
|
||||||
{
|
{
|
||||||
_length += _sink->print(value, decimals);
|
_length += _sink->print(value, decimals);
|
||||||
}
|
}
|
@ -91,7 +91,6 @@ char* QuotedString::extractFrom(char* input, char** endPtr)
|
|||||||
if (c == 0)
|
if (c == 0)
|
||||||
{
|
{
|
||||||
// premature ending
|
// premature ending
|
||||||
*endPtr = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +107,7 @@ char* QuotedString::extractFrom(char* input, char** endPtr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*writePtr++ = c;
|
*writePtr++ = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// end the string here
|
// end the string here
|
||||||
*writePtr = 0;
|
*writePtr = 0;
|
@ -54,6 +54,21 @@ TEST_F(JsonParser_Object_Test, MissingClosingBrace)
|
|||||||
sizeMustBe(0);
|
sizeMustBe(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(JsonParser_Object_Test, MissingColonAndValue)
|
||||||
|
{
|
||||||
|
whenInputIs("{\"key\"}");
|
||||||
|
parseMustFail();
|
||||||
|
sizeMustBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JsonParser_Object_Test, MissingQuotesAndColonAndValue)
|
||||||
|
{
|
||||||
|
whenInputIs("{key}");
|
||||||
|
parseMustFail();
|
||||||
|
sizeMustBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(JsonParser_Object_Test, OneStringNoSpace)
|
TEST_F(JsonParser_Object_Test, OneStringNoSpace)
|
||||||
{
|
{
|
||||||
whenInputIs("{\"key\":\"value\"}");
|
whenInputIs("{\"key\":\"value\"}");
|
||||||
|
Reference in New Issue
Block a user