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