rippled
Loading...
Searching...
No Matches
tests/libxrpl/json/Output.cpp
1#include <xrpl/json/Output.h>
2#include <xrpl/json/json_reader.h>
3#include <xrpl/json/json_writer.h>
4
5#include <doctest/doctest.h>
6
7#include <string>
8
9using namespace ripple;
10using namespace Json;
11
12TEST_SUITE_BEGIN("JsonOutput");
13
14static void
15checkOutput(std::string const& valueDesc)
16{
17 std::string output;
18 Json::Value value;
19 REQUIRE(Json::Reader().parse(valueDesc, value));
20 auto out = stringOutput(output);
21 outputJson(value, out);
22
23 auto expected = Json::FastWriter().write(value);
24 CHECK(output == expected);
25 CHECK(output == valueDesc);
26 CHECK(output == jsonAsString(value));
27}
28
29TEST_CASE("output cases")
30{
31 checkOutput("{}");
32 checkOutput("[]");
33 checkOutput(R"([23,4.25,true,null,"string"])");
34 checkOutput(R"({"hello":"world"})");
35 checkOutput("[{}]");
36 checkOutput("[[]]");
37 checkOutput(R"({"array":[{"12":23},{},null,false,0.5]})");
38}
39
40TEST_SUITE_END();
Outputs a Value in JSON format without formatting (not human friendly).
Definition json_writer.h:35
std::string write(Value const &root) override
Unserialize a JSON document into a Value.
Definition json_reader.h:20
Represents a JSON value.
Definition json_value.h:130
JSON (JavaScript Object Notation).
Definition json_errors.h:6
Output stringOutput(std::string &s)
std::string jsonAsString(Json::Value const &)
Return the minimal string representation of a Json::Value in O(n) time.
void outputJson(Json::Value const &, Output const &)
Writes a minimal representation of a Json value to an Output in O(n) time.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
T parse(T... args)