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 <gtest/gtest.h>
6
7#include <string>
8
9using namespace xrpl;
10using namespace Json;
11
12static void
13checkOutput(std::string const& valueDesc)
14{
15 std::string output;
16 Json::Value value;
17 ASSERT_TRUE(Json::Reader().parse(valueDesc, value));
18 auto out = stringOutput(output);
19 outputJson(value, out);
20
21 auto expected = Json::FastWriter().write(value);
22 EXPECT_EQ(output, expected);
23 EXPECT_EQ(output, valueDesc);
24 EXPECT_EQ(output, jsonAsString(value));
25}
26
27TEST(JsonOutput, output_cases)
28{
29 checkOutput("{}");
30 checkOutput("[]");
31 checkOutput(R"([23,4.25,true,null,"string"])");
32 checkOutput(R"({"hello":"world"})");
33 checkOutput("[{}]");
34 checkOutput("[[]]");
35 checkOutput(R"({"array":[{"12":23},{},null,false,0.5]})");
36}
Outputs a Value in JSON format without formatting (not human friendly).
Definition json_writer.h:34
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
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:5
T parse(T... args)