-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
78 lines (58 loc) · 2.17 KB
/
test.cpp
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
#include <iostream>
#include "maxy/json.h"
using maxy::data::json;
int main ()
{
json j;
// assignment
j = 3; std::cout << " Assigned int{3}: " << j << "\n";
j = 1.7; std::cout << " Assigned float{1.7}: " << j << "\n";
// conversion
int x{j};
for (int i = 0; i < 5; i++) j[i] = i * 100;
j[5]["a"] = "b";
j[5]["b"] = 123;
j[5]["c"] = true;
j[7]["1234"] = nullptr;
j.push_back (false);
std::cout << "populated object:" << j << "\n";
std::cout << "\nArray iteration\n";
for (auto it : j)
std::cout << "first: " << it.first << ", second: " << it.second << "\n";
std::cout << "\nObject iteration\n";
for (auto it : j[5])
std::cout << "first: " << it.first << ", second: " << it.second << "\n";
auto flt = json::parse ("-12.34E-123");
std::cout << "parse float: " << flt << "\n";
std::cout << "Equality: " << (flt == -12.34E-123L) << "\n";
auto arr = json::parse ("[true,true,]");
std::cout << "parse array: " << arr << ", is_ok = " << arr.is_ok () << "\n";
arr.push_back ("push");
std::cout << "push_back: " << arr << "\n";
auto popped = arr.pop_back ();
std::cout << "pop_back: " << arr << ", popped = " << popped << "\n";
auto obj = json::parse ("{\"a\":true, \"b\":[1,2,],}");
std::cout << "parse object: " << obj << ", is_ok = " << obj.is_ok() << "\n";
auto err = json::parse ("ckpa8j,qwefasd\"mvif.qwe!#@[");
std::cout << "parse trash string: " << err << ", is_ok = " << err.is_ok () << "\n";
json cpy = obj;
std::cout << "Copied object: " << cpy << "\n";
std::cout << "Object and copy equality: " << (obj == cpy) << "\n";
cpy["new_field"] = 666;
std::cout << "Modified copy " << cpy << ", equality: " << (obj == cpy) << "\n";
json uni = json::parse ("[\"csaka\\x20\\\"quote\", \"U=\\u20AA!\"]");
std::cout << "Unicode: " << uni << "\n";
json x1 = json::parse ("{\"quote\\\"key\":123, inner: [{}, {\"a\" : \"b\"}]}");
std::cout << "Relaxed input: " << x1 << ", is_ok = " << x1.is_ok () << "\n";
json adhoc
{{
{"a", json{1}},
{"b", json
{{
{"lol", json{"kek"}}
}}
},
{"c", json{true}},
{"d", json{nullptr}}
}};
std::cout << "Ad hoc construction: " << adhoc << ", expected {\"a\":1,\"b\":{\"lol\":\"kek\"},\"c\":true,\"d\":null}\n";}