예제 #1
0
    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!!!");
    }
예제 #2
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
    void testEmpty ()
    {
        setup ("empty array");
        writer_->startRoot (Writer::array);
        writer_->finish ();
        expectResult ("[]");

        setup ("empty object");
        writer_->startRoot (Writer::object);
        writer_->finish ();
        expectResult ("{}");
    }
예제 #3
0
    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}}");
    }
예제 #4
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
 void testNearTrivial ()
 {
     setup ("near trivial");
     expect (output_.empty ());
     writer_->output (0);
     expectResult("0");
 }
예제 #5
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
 void testArray ()
 {
     setup ("empty array");
     writer_->startRoot (Writer::array);
     writer_->append (12);
     writer_->finish ();
     expectResult ("[12]");
 }
예제 #6
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
    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");
    }
예제 #7
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
    void testObject ()
    {
        setup ("object");
        writer_->startRoot (Writer::object);
        writer_->set ("hello", "world");
        writer_->finish ();

        expectResult ("{\"hello\":\"world\"}");
    }
예제 #8
0
 void testOneSub ()
 {
     setup ("oneSub");
     {
         auto& root = makeRoot();
         root.setArray ("ar");
     }
     expectResult ("{\"ar\":[]}");
 }
예제 #9
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
 void testEmbeddedArraySimple ()
 {
     setup ("embedded array simple");
     writer_->startRoot (Writer::array);
     writer_->startAppend (Writer::array);
     writer_->finish ();
     writer_->finish ();
     expectResult ("[[]]");
 }
예제 #10
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
 void testLongArray ()
 {
     setup ("long array");
     writer_->startRoot (Writer::array);
     writer_->append (12);
     writer_->append (true);
     writer_->append ("hello");
     writer_->finish ();
     expectResult ("[12,true,\"hello\"]");
 }
예제 #11
0
    void testTrivial ()
    {
        setup ("trivial");

        {
            auto& root = makeRoot();
            (void) root;
        }
        expectResult ("{}");
    }
예제 #12
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
    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}}");
    }
예제 #13
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
    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\"");
    }
예제 #14
0
    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}");
    }
예제 #15
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
    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]}]]}");
    }
예제 #16
0
 void testTrivial ()
 {
     setup ("trivial");
     BEAST_EXPECT(output_.empty ());
     expectResult("");
 }
예제 #17
0
파일: Writer.test.cpp 프로젝트: xdv/divvyd
 void testTrivial ()
 {
     setup ("trivial");
     expect (output_.empty ());
     expectResult("");
 }