forked from bblanchon/ArduinoJson
Test an object with one member
This commit is contained in:
@ -7,5 +7,27 @@
|
|||||||
|
|
||||||
size_t IndentedPrintDecorator::write(uint8_t c)
|
size_t IndentedPrintDecorator::write(uint8_t c)
|
||||||
{
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '{':
|
||||||
|
indent++;
|
||||||
|
return sink.write(c) + writeln();
|
||||||
|
|
||||||
|
case '}':
|
||||||
|
indent--;
|
||||||
|
return writeln() + sink.write(c);
|
||||||
|
|
||||||
|
default:
|
||||||
return sink.write(c);
|
return sink.write(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t IndentedPrintDecorator::writeln()
|
||||||
|
{
|
||||||
|
size_t n = sink.write('\n');
|
||||||
|
|
||||||
|
for (int i = 0; i < indent; i++)
|
||||||
|
n += sink.write(' ');
|
||||||
|
|
||||||
|
return n;
|
||||||
}
|
}
|
@ -13,14 +13,16 @@ class IndentedPrintDecorator : public Print
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
IndentedPrintDecorator(Print& p)
|
IndentedPrintDecorator(Print& p)
|
||||||
: currentLevel(0), sink(p)
|
: indent(0), sink(p)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int currentLevel;
|
int indent;
|
||||||
Print& sink;
|
Print& sink;
|
||||||
|
|
||||||
|
size_t writeln();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,6 +37,14 @@ namespace JsonGeneratorTests
|
|||||||
outputMustBe("[]");
|
outputMustBe("[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(ObjectWithOneMember)
|
||||||
|
{
|
||||||
|
whenInputIs("{\"key\":\"value\"}");
|
||||||
|
outputMustBe(
|
||||||
|
"{\n"
|
||||||
|
" \"key\":\"value\"\n"
|
||||||
|
"}");
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user