mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -17,188 +17,201 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/json/json_writer.h>
|
||||
#include <ripple/json/Writer.h>
|
||||
#include <test/json/TestOutputSuite.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/json/Writer.h>
|
||||
#include <ripple/json/json_writer.h>
|
||||
#include <test/json/TestOutputSuite.h>
|
||||
|
||||
namespace Json {
|
||||
|
||||
class JsonWriter_test : public ripple::test::TestOutputSuite
|
||||
{
|
||||
public:
|
||||
void testTrivial ()
|
||||
void
|
||||
testTrivial()
|
||||
{
|
||||
setup ("trivial");
|
||||
BEAST_EXPECT(output_.empty ());
|
||||
setup("trivial");
|
||||
BEAST_EXPECT(output_.empty());
|
||||
expectResult("");
|
||||
}
|
||||
|
||||
void testNearTrivial ()
|
||||
void
|
||||
testNearTrivial()
|
||||
{
|
||||
setup ("near trivial");
|
||||
BEAST_EXPECT(output_.empty ());
|
||||
writer_->output (0);
|
||||
setup("near trivial");
|
||||
BEAST_EXPECT(output_.empty());
|
||||
writer_->output(0);
|
||||
expectResult("0");
|
||||
}
|
||||
|
||||
void testPrimitives ()
|
||||
void
|
||||
testPrimitives()
|
||||
{
|
||||
setup ("true");
|
||||
writer_->output (true);
|
||||
expectResult ("true");
|
||||
setup("true");
|
||||
writer_->output(true);
|
||||
expectResult("true");
|
||||
|
||||
setup ("false");
|
||||
writer_->output (false);
|
||||
expectResult ("false");
|
||||
setup("false");
|
||||
writer_->output(false);
|
||||
expectResult("false");
|
||||
|
||||
setup ("23");
|
||||
writer_->output (23);
|
||||
expectResult ("23");
|
||||
setup("23");
|
||||
writer_->output(23);
|
||||
expectResult("23");
|
||||
|
||||
setup ("23.0");
|
||||
writer_->output (23.0);
|
||||
expectResult ("23.0");
|
||||
setup("23.0");
|
||||
writer_->output(23.0);
|
||||
expectResult("23.0");
|
||||
|
||||
setup ("23.5");
|
||||
writer_->output (23.5);
|
||||
expectResult ("23.5");
|
||||
setup("23.5");
|
||||
writer_->output(23.5);
|
||||
expectResult("23.5");
|
||||
|
||||
setup ("a string");
|
||||
writer_->output ("a string");
|
||||
expectResult ("\"a string\"");
|
||||
setup("a string");
|
||||
writer_->output("a string");
|
||||
expectResult("\"a string\"");
|
||||
|
||||
setup ("nullptr");
|
||||
writer_->output (nullptr);
|
||||
expectResult ("null");
|
||||
setup("nullptr");
|
||||
writer_->output(nullptr);
|
||||
expectResult("null");
|
||||
}
|
||||
|
||||
void testEmpty ()
|
||||
void
|
||||
testEmpty()
|
||||
{
|
||||
setup ("empty array");
|
||||
writer_->startRoot (Writer::array);
|
||||
writer_->finish ();
|
||||
expectResult ("[]");
|
||||
setup("empty array");
|
||||
writer_->startRoot(Writer::array);
|
||||
writer_->finish();
|
||||
expectResult("[]");
|
||||
|
||||
setup ("empty object");
|
||||
writer_->startRoot (Writer::object);
|
||||
writer_->finish ();
|
||||
expectResult ("{}");
|
||||
setup("empty object");
|
||||
writer_->startRoot(Writer::object);
|
||||
writer_->finish();
|
||||
expectResult("{}");
|
||||
}
|
||||
|
||||
void testEscaping ()
|
||||
void
|
||||
testEscaping()
|
||||
{
|
||||
setup ("backslash");
|
||||
writer_->output ("\\");
|
||||
expectResult ("\"\\\\\"");
|
||||
setup("backslash");
|
||||
writer_->output("\\");
|
||||
expectResult("\"\\\\\"");
|
||||
|
||||
setup ("quote");
|
||||
writer_->output ("\"");
|
||||
expectResult ("\"\\\"\"");
|
||||
setup("quote");
|
||||
writer_->output("\"");
|
||||
expectResult("\"\\\"\"");
|
||||
|
||||
setup ("backslash and 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("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\"");
|
||||
setup("remaining escapes");
|
||||
writer_->output("\b\f\n\r\t");
|
||||
expectResult("\"\\b\\f\\n\\r\\t\"");
|
||||
}
|
||||
|
||||
void testArray ()
|
||||
void
|
||||
testArray()
|
||||
{
|
||||
setup ("empty array");
|
||||
writer_->startRoot (Writer::array);
|
||||
writer_->append (12);
|
||||
writer_->finish ();
|
||||
expectResult ("[12]");
|
||||
setup("empty array");
|
||||
writer_->startRoot(Writer::array);
|
||||
writer_->append(12);
|
||||
writer_->finish();
|
||||
expectResult("[12]");
|
||||
}
|
||||
|
||||
void testLongArray ()
|
||||
void
|
||||
testLongArray()
|
||||
{
|
||||
setup ("long array");
|
||||
writer_->startRoot (Writer::array);
|
||||
writer_->append (12);
|
||||
writer_->append (true);
|
||||
writer_->append ("hello");
|
||||
writer_->finish ();
|
||||
expectResult ("[12,true,\"hello\"]");
|
||||
setup("long array");
|
||||
writer_->startRoot(Writer::array);
|
||||
writer_->append(12);
|
||||
writer_->append(true);
|
||||
writer_->append("hello");
|
||||
writer_->finish();
|
||||
expectResult("[12,true,\"hello\"]");
|
||||
}
|
||||
|
||||
void testEmbeddedArraySimple ()
|
||||
void
|
||||
testEmbeddedArraySimple()
|
||||
{
|
||||
setup ("embedded array simple");
|
||||
writer_->startRoot (Writer::array);
|
||||
writer_->startAppend (Writer::array);
|
||||
writer_->finish ();
|
||||
writer_->finish ();
|
||||
expectResult ("[[]]");
|
||||
setup("embedded array simple");
|
||||
writer_->startRoot(Writer::array);
|
||||
writer_->startAppend(Writer::array);
|
||||
writer_->finish();
|
||||
writer_->finish();
|
||||
expectResult("[[]]");
|
||||
}
|
||||
|
||||
void testObject ()
|
||||
void
|
||||
testObject()
|
||||
{
|
||||
setup ("object");
|
||||
writer_->startRoot (Writer::object);
|
||||
writer_->set ("hello", "world");
|
||||
writer_->finish ();
|
||||
setup("object");
|
||||
writer_->startRoot(Writer::object);
|
||||
writer_->set("hello", "world");
|
||||
writer_->finish();
|
||||
|
||||
expectResult ("{\"hello\":\"world\"}");
|
||||
expectResult("{\"hello\":\"world\"}");
|
||||
}
|
||||
|
||||
void testComplexObject ()
|
||||
void
|
||||
testComplexObject()
|
||||
{
|
||||
setup ("complex object");
|
||||
writer_->startRoot (Writer::object);
|
||||
setup("complex object");
|
||||
writer_->startRoot(Writer::object);
|
||||
|
||||
writer_->set ("hello", "world");
|
||||
writer_->startSet (Writer::array, "array");
|
||||
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 ();
|
||||
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]}]]}");
|
||||
expectResult(
|
||||
"{\"hello\":\"world\",\"array\":[true,12,"
|
||||
"[{\"goodbye\":\"cruel world.\","
|
||||
"\"subarray\":[23.5]}]]}");
|
||||
}
|
||||
|
||||
void testJson ()
|
||||
void
|
||||
testJson()
|
||||
{
|
||||
setup ("object");
|
||||
Json::Value value (Json::objectValue);
|
||||
setup("object");
|
||||
Json::Value value(Json::objectValue);
|
||||
value["foo"] = 23;
|
||||
writer_->startRoot (Writer::object);
|
||||
writer_->set ("hello", value);
|
||||
writer_->finish ();
|
||||
writer_->startRoot(Writer::object);
|
||||
writer_->set("hello", value);
|
||||
writer_->finish();
|
||||
|
||||
expectResult ("{\"hello\":{\"foo\":23}}");
|
||||
expectResult("{\"hello\":{\"foo\":23}}");
|
||||
}
|
||||
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testTrivial ();
|
||||
testNearTrivial ();
|
||||
testPrimitives ();
|
||||
testEmpty ();
|
||||
testEscaping ();
|
||||
testArray ();
|
||||
testLongArray ();
|
||||
testEmbeddedArraySimple ();
|
||||
testObject ();
|
||||
testComplexObject ();
|
||||
testTrivial();
|
||||
testNearTrivial();
|
||||
testPrimitives();
|
||||
testEmpty();
|
||||
testEscaping();
|
||||
testArray();
|
||||
testLongArray();
|
||||
testEmbeddedArraySimple();
|
||||
testObject();
|
||||
testComplexObject();
|
||||
testJson();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(JsonWriter, ripple_basics, ripple);
|
||||
|
||||
} // Json
|
||||
} // namespace Json
|
||||
|
||||
Reference in New Issue
Block a user