Added a tests that adds a 'null' to an array

This commit is contained in:
Benoit Blanchon
2014-06-24 21:24:38 +02:00
parent 1118dd7b53
commit 2a20c5a25c
2 changed files with 15 additions and 3 deletions

View File

@ -76,18 +76,23 @@ public:
if (i>0) if (i>0)
append(buffer, bufferSize, ","); append(buffer, bufferSize, ",");
JsonObjectValue value = items[i].value;
switch (items[i].type) switch (items[i].type)
{ {
case JSON_STRING: case JSON_STRING:
append(buffer, bufferSize, "'%s'", items[i].value.string); if (value.string)
append(buffer, bufferSize, "'%s'", value.string);
else
append(buffer, bufferSize, "null");
break; break;
case JSON_NUMBER: case JSON_NUMBER:
append(buffer, bufferSize, "%lg", items[i].value.number); append(buffer, bufferSize, "%lg", value.number);
break; break;
case JSON_BOOLEAN: case JSON_BOOLEAN:
append(buffer, bufferSize, items[i].value.boolean ? "true" : "false"); append(buffer, bufferSize, value.boolean ? "true" : "false");
break; break;
} }
} }

View File

@ -16,6 +16,13 @@ namespace JsonGeneratorTests
AssertJsonIs("[]"); AssertJsonIs("[]");
} }
TEST_METHOD(AddNull)
{
arr.add((char*)0);
AssertJsonIs("[null]");
}
TEST_METHOD(AddOneString) TEST_METHOD(AddOneString)
{ {
arr.add("hello"); arr.add("hello");