From 981adf19897d35648378ebdbe8a7efc744aaba69 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 25 Aug 2014 11:01:22 +0200 Subject: [PATCH] Test empty nested arrays --- JsonGenerator/IndentedPrintDecorator.cpp | 16 ++++++++++++++-- JsonGeneratorTests/Intented_Array_Tests.cpp | 10 ++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/JsonGenerator/IndentedPrintDecorator.cpp b/JsonGenerator/IndentedPrintDecorator.cpp index 32297f77..12aaa398 100644 --- a/JsonGenerator/IndentedPrintDecorator.cpp +++ b/JsonGenerator/IndentedPrintDecorator.cpp @@ -11,9 +11,21 @@ size_t IndentedPrintDecorator::write(uint8_t c) { case '{': case '[': - indent++; + + size_t n; + + if (previousChar == '{' || previousChar == '[') + { + n = writeln() + sink.write(c); + } + else + { + n = sink.write(c); + } + previousChar = c; - return sink.write(c); + indent++; + return n; case '}': case ']': diff --git a/JsonGeneratorTests/Intented_Array_Tests.cpp b/JsonGeneratorTests/Intented_Array_Tests.cpp index d3ad9fd4..65d8d13f 100644 --- a/JsonGeneratorTests/Intented_Array_Tests.cpp +++ b/JsonGeneratorTests/Intented_Array_Tests.cpp @@ -44,6 +44,16 @@ namespace JsonGeneratorTests "]"); } + TEST_METHOD(EmptyNestedArrays) + { + whenInputIs("[[],[]]"); + outputMustBe( + "[\n" + " [],\n" + " []\n" + "]"); + } + private: void whenInputIs(const char input[])