void chunkedYieldingTest () { setup ("chunkedYieldingTest"); std::string lastYield; auto yield = [&]() { lastYield = output_; }; auto output = chunkedYieldingOutput ( Json::stringOutput (output_), yield, 5); output ("hello"); expectResult ("hello"); expectEquals (lastYield, ""); output (", th"); // Goes over the boundary. expectResult ("hello, th"); expectEquals (lastYield, ""); output ("ere!"); // Forces a yield. expectResult ("hello, there!"); expectEquals (lastYield, "hello, th"); output ("!!"); expectResult ("hello, there!!!"); expectEquals (lastYield, "hello, th"); output (""); // Forces a yield. expectResult ("hello, there!!!"); expectEquals (lastYield, "hello, there!!!"); }
void testEmpty () { setup ("empty array"); writer_->startRoot (Writer::array); writer_->finish (); expectResult ("[]"); setup ("empty object"); writer_->startRoot (Writer::object); writer_->finish (); expectResult ("{}"); }
void testSubsShort () { setup ("subsShort"); { auto& root = makeRoot(); { // Add an array with three entries. auto array = root.setArray ("ar"); array.append (23); array.append (false); array.append (23.5); } // Add an object with one entry. root.setObject ("obj")["hello"] = "world"; { // Add another object with two entries. auto object = root.setObject ("obj2"); object.set("h", "w"); object.set("f", false); } } expectResult ( "{\"ar\":[23,false,23.5]," "\"obj\":{\"hello\":\"world\"}," "\"obj2\":{\"h\":\"w\",\"f\":false}}"); }
void testNearTrivial () { setup ("near trivial"); expect (output_.empty ()); writer_->output (0); expectResult("0"); }
void testArray () { setup ("empty array"); writer_->startRoot (Writer::array); writer_->append (12); writer_->finish (); expectResult ("[12]"); }
void testPrimitives () { setup ("true"); writer_->output (true); expectResult ("true"); setup ("false"); writer_->output (false); expectResult ("false"); setup ("23"); writer_->output (23); expectResult ("23"); setup ("23.0"); writer_->output (23.0); expectResult ("23.0"); setup ("23.5"); writer_->output (23.5); expectResult ("23.5"); setup ("a string"); writer_->output ("a string"); expectResult ("\"a string\""); setup ("nullptr"); writer_->output (nullptr); expectResult ("null"); }
void testObject () { setup ("object"); writer_->startRoot (Writer::object); writer_->set ("hello", "world"); writer_->finish (); expectResult ("{\"hello\":\"world\"}"); }
void testOneSub () { setup ("oneSub"); { auto& root = makeRoot(); root.setArray ("ar"); } expectResult ("{\"ar\":[]}"); }
void testEmbeddedArraySimple () { setup ("embedded array simple"); writer_->startRoot (Writer::array); writer_->startAppend (Writer::array); writer_->finish (); writer_->finish (); expectResult ("[[]]"); }
void testLongArray () { setup ("long array"); writer_->startRoot (Writer::array); writer_->append (12); writer_->append (true); writer_->append ("hello"); writer_->finish (); expectResult ("[12,true,\"hello\"]"); }
void testTrivial () { setup ("trivial"); { auto& root = makeRoot(); (void) root; } expectResult ("{}"); }
void testJson () { setup ("object"); Json::Value value (Json::objectValue); value["foo"] = 23; writer_->startRoot (Writer::object); writer_->set ("hello", value); writer_->finish (); expectResult ("{\"hello\":{\"foo\":23}}"); }
void testEscaping () { setup ("backslash"); writer_->output ("\\"); expectResult ("\"\\\\\""); setup ("quote"); writer_->output ("\""); expectResult ("\"\\\"\""); setup ("backslash and quote"); writer_->output ("\\\""); expectResult ("\"\\\\\\\"\""); setup ("escape embedded"); writer_->output ("this contains a \\ in the middle of it."); expectResult ("\"this contains a \\\\ in the middle of it.\""); setup ("remaining escapes"); writer_->output ("\b\f\n\r\t"); expectResult ("\"\\b\\f\\n\\r\\t\""); }
void testSimple () { setup ("simple"); { auto& root = makeRoot(); root["hello"] = "world"; root["skidoo"] = 23; root["awake"] = false; root["temperature"] = 98.6; } expectResult ( "{\"hello\":\"world\"," "\"skidoo\":23," "\"awake\":false," "\"temperature\":98.6}"); }
void testComplexObject () { setup ("complex object"); writer_->startRoot (Writer::object); writer_->set ("hello", "world"); writer_->startSet (Writer::array, "array"); writer_->append (true); writer_->append (12); writer_->startAppend (Writer::array); writer_->startAppend (Writer::object); writer_->set ("goodbye", "cruel world."); writer_->startSet (Writer::array, "subarray"); writer_->append (23.5); writer_->finishAll (); expectResult ("{\"hello\":\"world\",\"array\":[true,12," "[{\"goodbye\":\"cruel world.\"," "\"subarray\":[23.5]}]]}"); }
void testTrivial () { setup ("trivial"); BEAST_EXPECT(output_.empty ()); expectResult(""); }
void testTrivial () { setup ("trivial"); expect (output_.empty ()); expectResult(""); }