mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 04:52:22 +02:00
Renamed IndentedPrintDecorator to PrettyPrintDecorator
This commit is contained in:
89
JsonGeneratorTests/PrettyPrint_Array_Tests.cpp
Normal file
89
JsonGeneratorTests/PrettyPrint_Array_Tests.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Arduino JSON library
|
||||
* Benoit Blanchon 2014 - MIT License
|
||||
*/
|
||||
|
||||
#include "CppUnitTest.h"
|
||||
#include "PrettyPrintDecorator.h"
|
||||
#include "StringBuilder.h"
|
||||
|
||||
using namespace ArduinoJson::Internals;
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace JsonGeneratorTests
|
||||
{
|
||||
TEST_CLASS(PrettyPrint_Array_Tests)
|
||||
{
|
||||
char buffer[1024];
|
||||
size_t returnValue;
|
||||
|
||||
public:
|
||||
|
||||
TEST_METHOD(EmptyArray)
|
||||
{
|
||||
whenInputIs("[]");
|
||||
outputMustBe("[]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneElement)
|
||||
{
|
||||
whenInputIs("[1]");
|
||||
outputMustBe(
|
||||
"[\n"
|
||||
" 1\n"
|
||||
"]");
|
||||
}
|
||||
|
||||
TEST_METHOD(TwoElements)
|
||||
{
|
||||
whenInputIs("[1,2]");
|
||||
outputMustBe(
|
||||
"[\n"
|
||||
" 1,\n"
|
||||
" 2\n"
|
||||
"]");
|
||||
}
|
||||
|
||||
TEST_METHOD(EmptyNestedArrays)
|
||||
{
|
||||
whenInputIs("[[],[]]");
|
||||
outputMustBe(
|
||||
"[\n"
|
||||
" [],\n"
|
||||
" []\n"
|
||||
"]");
|
||||
}
|
||||
|
||||
TEST_METHOD(NestedArrays)
|
||||
{
|
||||
whenInputIs("[[1,2],[3,4]]");
|
||||
outputMustBe(
|
||||
"[\n"
|
||||
" [\n"
|
||||
" 1,\n"
|
||||
" 2\n"
|
||||
" ],\n"
|
||||
" [\n"
|
||||
" 3,\n"
|
||||
" 4\n"
|
||||
" ]\n"
|
||||
"]");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void whenInputIs(const char input[])
|
||||
{
|
||||
StringBuilder sb(buffer, sizeof(buffer));
|
||||
PrettyPrintDecorator decorator(sb);
|
||||
|
||||
returnValue = decorator.print(input);
|
||||
}
|
||||
|
||||
void outputMustBe(const char* expected)
|
||||
{
|
||||
Assert::AreEqual(expected, buffer);
|
||||
Assert::AreEqual(strlen(expected), returnValue);
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user