diff --git a/JsonGenerator/IndentedPrintDecorator.cpp b/JsonGenerator/IndentedPrintDecorator.cpp index 49bff98d..32297f77 100644 --- a/JsonGenerator/IndentedPrintDecorator.cpp +++ b/JsonGenerator/IndentedPrintDecorator.cpp @@ -10,14 +10,16 @@ size_t IndentedPrintDecorator::write(uint8_t c) switch (c) { case '{': + case '[': indent++; previousChar = c; return sink.write(c); case '}': + case ']': indent--; - if (previousChar == '{') + if (previousChar == '{' || previousChar == '[') { previousChar = c; return sink.write(c); @@ -58,7 +60,7 @@ size_t IndentedPrintDecorator::write(uint8_t c) default: - if (previousChar == '{') + if (previousChar == '{' || previousChar == '[') { previousChar = c; return writeln() + sink.write(c); diff --git a/JsonGeneratorTests/Intented_Array_Tests.cpp b/JsonGeneratorTests/Intented_Array_Tests.cpp index 193b4ba4..b59c4871 100644 --- a/JsonGeneratorTests/Intented_Array_Tests.cpp +++ b/JsonGeneratorTests/Intented_Array_Tests.cpp @@ -12,7 +12,7 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework; namespace JsonGeneratorTests { - TEST_CLASS(IntentedPrintTests) + TEST_CLASS(Indented_Array_Tests) { char buffer[1024]; size_t returnValue; @@ -25,6 +25,15 @@ namespace JsonGeneratorTests outputMustBe("[]"); } + TEST_METHOD(OneElement) + { + whenInputIs("[1]"); + outputMustBe( + "[\n" + " 1\n" + "]"); + } + private: void whenInputIs(const char input[]) diff --git a/JsonGeneratorTests/Intented_Object_Tests.cpp b/JsonGeneratorTests/Intented_Object_Tests.cpp index a4c458ef..a1ce73f7 100644 --- a/JsonGeneratorTests/Intented_Object_Tests.cpp +++ b/JsonGeneratorTests/Intented_Object_Tests.cpp @@ -12,7 +12,7 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework; namespace JsonGeneratorTests { - TEST_CLASS(IntentedPrintTests) + TEST_CLASS(Indented_Object_Tests) { char buffer[1024]; size_t returnValue; diff --git a/JsonGeneratorTests/Intented_String_Tests.cpp b/JsonGeneratorTests/Intented_String_Tests.cpp index f29ad88f..5d7c2452 100644 --- a/JsonGeneratorTests/Intented_String_Tests.cpp +++ b/JsonGeneratorTests/Intented_String_Tests.cpp @@ -12,7 +12,7 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework; namespace JsonGeneratorTests { - TEST_CLASS(IntentedPrintTests) + TEST_CLASS(Intented_String_Tests) { char buffer[1024]; size_t returnValue;