diff --git a/JsonGeneratorTests/JsonArray.h b/JsonGeneratorTests/JsonArray.h index b731fef7..895e0af3 100644 --- a/JsonGeneratorTests/JsonArray.h +++ b/JsonGeneratorTests/JsonArray.h @@ -40,29 +40,23 @@ public: void add(const char* value) { - if (itemCount >= N) return; - - items[itemCount].type = JSON_STRING; - items[itemCount].value.string = value; - itemCount++; + JsonObjectValue v; + v.string = value; + addItem(JSON_STRING, v); } void add(double value) { - if (itemCount >= N) return; - - items[itemCount].type = JSON_NUMBER; - items[itemCount].value.number = value; - itemCount++; + JsonObjectValue v; + v.number = value; + addItem(JSON_NUMBER, v); } void add(bool value) { - if (itemCount >= N) return; - - items[itemCount].type = JSON_BOOLEAN; - items[itemCount].value.boolean = value; - itemCount++; + JsonObjectValue v; + v.boolean = value; + addItem(JSON_BOOLEAN, v); } void writeTo(char* buffer, size_t bufferSize) @@ -107,5 +101,14 @@ private: sb.append("]"); } + + void addItem(JsonObjectType type, JsonObjectValue value) + { + if (itemCount >= N) return; + + items[itemCount].type = type; + items[itemCount].value = value; + itemCount++; + } }; diff --git a/JsonGeneratorTests/JsonArrayTests.cpp b/JsonGeneratorTests/JsonArrayTests.cpp index ec5e3ccd..64dcf594 100644 --- a/JsonGeneratorTests/JsonArrayTests.cpp +++ b/JsonGeneratorTests/JsonArrayTests.cpp @@ -102,6 +102,18 @@ namespace JsonGeneratorTests AssertJsonIs("[false,true]"); } + /* + + TEST_METHOD(AddOneEmptyNestedArray) + { + JsonArray<0> nestedArray; + + arr.add(nestedArray); + + AssertJsonIs("[[]]"); + } + + */ void AssertJsonIs(const char* expected) { char buffer[256];