-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTester.cpp
More file actions
81 lines (67 loc) · 1.55 KB
/
Tester.cpp
File metadata and controls
81 lines (67 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include "json11.hpp"
#include "PrettyRoutine.hpp"
using namespace std;
void allObjectsTest()
{
json11::Json json = json11::Json::object{
{ "book", json11::Json::object{
{ "name", "book1" },
{ "author", "person1" },
{ "year", 2019 }
}},
{ "test", 12.367 },
{ "null", json11::Json{} }
};
cout << "raw:\n" << json.dump() << endl;
json11::exts::PrettyRoutine routine{ json };
cout << "prettify:\n" << routine.dump() << endl;
routine.dumpFile("all_objects.json");
}
void arrayTest()
{
json11::Json json = json11::Json::array{
json11::Json::object{
{ "test", "hello world" },
{ "test2", "from json" }
},
json11::Json::object{
{ "test", "hello world" },
{ "test2", "from json" }
}
};
cout << "raw:\n" << json.dump() << endl;
json11::exts::PrettyRoutine routine{ json };
cout << "prettify:\n" << routine.dump() << endl;
routine.dumpFile("array_test.json");
}
void compoundTest()
{
json11::Json json;
std::string err;
json = json11::Json::parse(R"({"test": "hello world", "array": [ 2, "t", 35.6 ]})", err);
if (err.empty())
{
cout << "raw:\n" << json.dump() << endl;
json11::exts::PrettyRoutine routine{ json };
cout << "prettify:\n" << routine.dump() << endl;
routine.dumpFile("compound_test.json");
}
else
{
cout << err << endl;
}
}
int main(int argc, char** argv)
{
cout << "===All objects test===" << endl;
allObjectsTest();
cout << endl;
cout << "===Array test===" << endl;
arrayTest();
cout << endl;
cout << "===compoundTest" << endl;
compoundTest();
cout << endl;
return 0;
}