File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,7 +49,17 @@ namespace JSON {
4949
5050void Stringifier::stringify (const Var& any, std::ostream& out, unsigned int indent)
5151{
52- if ( any.type () == typeid (Object::Ptr) )
52+ if ( any.type () == typeid (Object) )
53+ {
54+ const Object& o = any.extract <Object>();
55+ o.stringify (out, indent == 0 ? 0 : indent + 2 );
56+ }
57+ else if ( any.type () == typeid (Array) )
58+ {
59+ const Array& a = any.extract <Array>();
60+ a.stringify (out, indent == 0 ? 0 : indent + 2 );
61+ }
62+ else if ( any.type () == typeid (Object::Ptr) )
5363 {
5464 const Object::Ptr& o = any.extract <Object::Ptr>();
5565 o->stringify (out, indent == 0 ? 0 : indent + 2 );
Original file line number Diff line number Diff line change @@ -74,6 +74,22 @@ void JSONTest::tearDown()
7474}
7575
7676
77+ void JSONTest::testStringifier ()
78+ {
79+ Object obj;
80+
81+ Array arr;
82+ Object obj2;
83+
84+ obj.set (" array" , arr);
85+ obj.set (" obj2" , obj2);
86+
87+ std::ostringstream ostr;
88+ obj.stringify (ostr);
89+ assert (ostr.str () == " {\" array\" :[],\" obj2\" :{}}" );
90+ }
91+
92+
7793void JSONTest::testNullProperty ()
7894{
7995 std::string json = " { \" test\" : null }" ;
@@ -806,6 +822,7 @@ CppUnit::Test* JSONTest::suite()
806822{
807823 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite (" JSONTest" );
808824
825+ CppUnit_addTest (pSuite, JSONTest, testStringifier);
809826 CppUnit_addTest (pSuite, JSONTest, testNullProperty);
810827 CppUnit_addTest (pSuite, JSONTest, testTrueProperty);
811828 CppUnit_addTest (pSuite, JSONTest, testFalseProperty);
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ class JSONTest: public CppUnit::TestCase
4646 JSONTest (const std::string& name);
4747 ~JSONTest ();
4848
49+ void testStringifier ();
4950 void testNullProperty ();
5051 void testTrueProperty ();
5152 void testFalseProperty ();
You can’t perform that action at this time.
0 commit comments