• Home
  • Raw
  • Download

Lines Matching full:json

2 //  __|  |   __|     |   | |  JSON for Modern C++ (supporting code)
4 // |_____|_____|_____|_|___| https://github.com/nlohmann/json
20 #include <nlohmann/json.hpp>
21 using nlohmann::json;
39 const json::object_t o_reference = {{"object", json::object()},
46 json j(o_reference);
48 SECTION("json::object_t")
50 json::object_t const o = j.get<json::object_t>();
51 CHECK(json(o) == j);
54 SECTION("std::map<json::string_t, json>")
56 const std::map<json::string_t, json> o =
57 j.get<std::map<json::string_t, json>>();
58 CHECK(json(o) == j);
61 SECTION("std::multimap<json::string_t, json>")
63 const std::multimap<json::string_t, json> o =
64 j.get<std::multimap<json::string_t, json>>();
65 CHECK(json(o) == j);
68 SECTION("std::unordered_map<json::string_t, json>")
70 const std::unordered_map<json::string_t, json> o =
71 j.get<std::unordered_map<json::string_t, json>>();
72 CHECK(json(o) == j);
75 SECTION("std::unordered_multimap<json::string_t, json>")
77 const std::unordered_multimap<json::string_t, json> o =
78 j.get<std::unordered_multimap<json::string_t, json>>();
79 CHECK(json(o) == j);
85 json(json::value_t::null).get<json::object_t>(),
86 … "[json.exception.type_error.302] type must be object, but is null", json::type_error&);
88 json(json::value_t::array).get<json::object_t>(),
89 … "[json.exception.type_error.302] type must be object, but is array", json::type_error&);
91 json(json::value_t::string).get<json::object_t>(),
92 … "[json.exception.type_error.302] type must be object, but is string", json::type_error&);
93 CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::object_t>(),
94 "[json.exception.type_error.302] type must be object, "
95 "but is boolean", json::type_error&);
97 json(json::value_t::number_integer).get<json::object_t>(),
98 … "[json.exception.type_error.302] type must be object, but is number", json::type_error&);
100 json(json::value_t::number_unsigned).get<json::object_t>(),
101 … "[json.exception.type_error.302] type must be object, but is number", json::type_error&);
103 json(json::value_t::number_float).get<json::object_t>(),
104 … "[json.exception.type_error.302] type must be object, but is number", json::type_error&);
110 const json::object_t o_reference = {{"object", json::object()},
117 json j(o_reference);
119 SECTION("json::object_t")
121 json::object_t o = {{"previous", "value"}};
123 CHECK(json(o) == j);
126 SECTION("std::map<json::string_t, json>")
128 std::map<json::string_t, json> o{{"previous", "value"}};
130 CHECK(json(o) == j);
133 SECTION("std::multimap<json::string_t, json>")
135 std::multimap<json::string_t, json> o{{"previous", "value"}};
137 CHECK(json(o) == j);
140 SECTION("std::unordered_map<json::string_t, json>")
142 std::unordered_map<json::string_t, json> o{{"previous", "value"}};
144 CHECK(json(o) == j);
147 SECTION("std::unordered_multimap<json::string_t, json>")
149 std::unordered_multimap<json::string_t, json> o{{"previous", "value"}};
151 CHECK(json(o) == j);
158 const json::object_t o_reference = {{"object", json::object()},
165 json j(o_reference);
167 SECTION("json::object_t")
169 const json::object_t o = j;
170 CHECK(json(o) == j);
173 SECTION("std::map<json::string_t, json>")
175 const std::map<json::string_t, json> o = j;
176 CHECK(json(o) == j);
179 SECTION("std::multimap<json::string_t, json>")
181 const std::multimap<json::string_t, json> o = j;
182 CHECK(json(o) == j);
185 SECTION("std::unordered_map<json::string_t, json>")
187 const std::unordered_map<json::string_t, json> o = j;
188 CHECK(json(o) == j);
191 SECTION("std::unordered_multimap<json::string_t, json>")
193 const std::unordered_multimap<json::string_t, json> o = j;
194 CHECK(json(o) == j);
201 const json::array_t a_reference{json(1), json(1u), json(2.2),
202 json(false), json("string"), json()};
203 json j(a_reference);
205 SECTION("json::array_t")
207 const json::array_t a = j.get<json::array_t>();
208 CHECK(json(a) == j);
211 SECTION("std::list<json>")
213 const std::list<json> a = j.get<std::list<json>>();
214 CHECK(json(a) == j);
217 SECTION("std::forward_list<json>")
219 const std::forward_list<json> a = j.get<std::forward_list<json>>();
220 CHECK(json(a) == j);
223 json(json::value_t::null).get<std::forward_list<json>>(),
224 … "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
227 SECTION("std::vector<json>")
229 const std::vector<json> a = j.get<std::vector<json>>();
230 CHECK(json(a) == j);
233 json(json::value_t::null).get<std::vector<json>>(),
234 … "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
240 const json j2({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
252 const json j2 = nbs;
253 const json j3 = str;
261 SECTION("std::deque<json>")
263 const std::deque<json> a = j.get<std::deque<json>>();
264 CHECK(json(a) == j);
270 json(json::value_t::object).get<std::vector<int>>(),
271 … "[json.exception.type_error.302] type must be array, but is object", json::type_error&);
273 json(json::value_t::null).get<json::array_t>(),
274 … "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
276 json(json::value_t::object).get<json::array_t>(),
277 … "[json.exception.type_error.302] type must be array, but is object", json::type_error&);
279 json(json::value_t::string).get<json::array_t>(),
280 … "[json.exception.type_error.302] type must be array, but is string", json::type_error&);
282 json(json::value_t::boolean).get<json::array_t>(),
283 … "[json.exception.type_error.302] type must be array, but is boolean", json::type_error&);
285 json(json::value_t::number_integer).get<json::array_t>(),
286 … "[json.exception.type_error.302] type must be array, but is number", json::type_error&);
288 json(json::value_t::number_unsigned).get<json::array_t>(),
289 … "[json.exception.type_error.302] type must be array, but is number", json::type_error&);
291 json(json::value_t::number_float).get<json::array_t>(),
292 … "[json.exception.type_error.302] type must be array, but is number", json::type_error&);
298 const json::array_t a_reference{json(1), json(1u), json(2.2),
299 json(false), json("string"), json()};
300 json j(a_reference);
302 SECTION("json::array_t")
304 json::array_t a{"previous", "value"};
306 CHECK(json(a) == j);
309 SECTION("std::valarray<json>")
311 std::valarray<json> a{"previous", "value"};
313 CHECK(json(a) == j);
316 SECTION("std::list<json>")
318 std::list<json> a{"previous", "value"};
320 CHECK(json(a) == j);
323 SECTION("std::forward_list<json>")
325 std::forward_list<json> a{"previous", "value"};
327 CHECK(json(a) == j);
330 SECTION("std::vector<json>")
332 std::vector<json> a{"previous", "value"};
334 CHECK(json(a) == j);
342 const json j2 = nbs;
347 SECTION("std::deque<json>")
349 std::deque<json> a{"previous", "value"};
351 CHECK(json(a) == j);
358 const json::array_t a_reference{json(1), json(1u), json(2.2),
359 json(false), json("string"), json()};
360 json j(a_reference);
362 SECTION("json::array_t")
364 const json::array_t a = j;
365 CHECK(json(a) == j);
368 SECTION("std::list<json>")
370 const std::list<json> a = j;
371 CHECK(json(a) == j);
374 SECTION("std::forward_list<json>")
376 const std::forward_list<json> a = j;
377 CHECK(json(a) == j);
380 SECTION("std::vector<json>")
382 const std::vector<json> a = j;
383 CHECK(json(a) == j);
386 SECTION("std::deque<json>")
388 const std::deque<json> a = j;
389 CHECK(json(a) == j);
396 const json::string_t s_reference{"Hello world"};
397 json j(s_reference);
401 const json::string_t s = j.get<json::string_t>();
402 CHECK(json(s) == j);
408 CHECK(json(s) == j);
414 CHECK(json(s) == j);
421 json(json::value_t::null).get<json::string_t>(),
422 … "[json.exception.type_error.302] type must be string, but is null", json::type_error&);
424 json(json::value_t::object).get<json::string_t>(),
425 … "[json.exception.type_error.302] type must be string, but is object", json::type_error&);
427 json(json::value_t::array).get<json::string_t>(),
428 … "[json.exception.type_error.302] type must be string, but is array", json::type_error&);
429 CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::string_t>(),
430 "[json.exception.type_error.302] type must be string, "
431 "but is boolean", json::type_error&);
433 json(json::value_t::number_integer).get<json::string_t>(),
434 … "[json.exception.type_error.302] type must be string, but is number", json::type_error&);
436 json(json::value_t::number_unsigned).get<json::string_t>(),
437 … "[json.exception.type_error.302] type must be string, but is number", json::type_error&);
439 json(json::value_t::number_float).get<json::string_t>(),
440 … "[json.exception.type_error.302] type must be string, but is number", json::type_error&);
446 CHECK_THROWS_WITH_AS(json(json::value_t::null).get<std::string_view>(),
447 … "[json.exception.type_error.302] type must be string, but is null", json::type_error&);
448 CHECK_THROWS_WITH_AS(json(json::value_t::object).get<std::string_view>(),
449 … "[json.exception.type_error.302] type must be string, but is object", json::type_error&);
450 CHECK_THROWS_WITH_AS(json(json::value_t::array).get<std::string_view>(),
451 … "[json.exception.type_error.302] type must be string, but is array", json::type_error&);
452 CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<std::string_view>(),
453 … "[json.exception.type_error.302] type must be string, but is boolean", json::type_error&);
454 CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<std::string_view>(),
455 … "[json.exception.type_error.302] type must be string, but is number", json::type_error&);
456 CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<std::string_view>(),
457 … "[json.exception.type_error.302] type must be string, but is number", json::type_error&);
458 CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<std::string_view>(),
459 … "[json.exception.type_error.302] type must be string, but is number", json::type_error&);
466 const json::string_t s_reference{"Hello world"};
467 json j(s_reference);
471 json::string_t s = "previous value";
473 CHECK(json(s) == j);
480 CHECK(json(s) == j);
488 CHECK(json(sv) == j);
496 const json j(n);
501 CHECK_THROWS_WITH_AS(json(json::value_t::string).get<std::nullptr_t>(),
502 … "[json.exception.type_error.302] type must be null, but is string", json::type_error&);
503 CHECK_THROWS_WITH_AS(json(json::value_t::object).get<std::nullptr_t>(),
504 … "[json.exception.type_error.302] type must be null, but is object", json::type_error&);
505 CHECK_THROWS_WITH_AS(json(json::value_t::array).get<std::nullptr_t>(),
506 … "[json.exception.type_error.302] type must be null, but is array", json::type_error&);
507 CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<std::nullptr_t>(),
508 … "[json.exception.type_error.302] type must be null, but is boolean", json::type_error&);
509 CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<std::nullptr_t>(),
510 … "[json.exception.type_error.302] type must be null, but is number", json::type_error&);
511 CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<std::nullptr_t>(),
512 … "[json.exception.type_error.302] type must be null, but is number", json::type_error&);
513 CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<std::nullptr_t>(),
514 … "[json.exception.type_error.302] type must be null, but is number", json::type_error&);
520 const json::string_t s_reference{"Hello world"};
521 json j(s_reference);
525 const json::string_t s = j;
526 CHECK(json(s) == j);
533 CHECK(json(s) == j);
540 CHECK(json(s) == j);
547 const json::boolean_t b_reference{true};
548 json j(b_reference);
552 auto b = j.get<json::boolean_t>();
553 CHECK(json(b) == j);
565 CHECK(json(b) == j);
570 CHECK_THROWS_AS(json(json::value_t::string).get<uint8_t>(),
571 json::type_error&);
574 json(json::value_t::null).get<json::boolean_t>(),
575 … "[json.exception.type_error.302] type must be boolean, but is null", json::type_error&);
576 CHECK_THROWS_WITH_AS(json(json::value_t::object).get<json::boolean_t>(),
577 "[json.exception.type_error.302] type must be boolean, "
578 "but is object", json::type_error&);
580 json(json::value_t::array).get<json::boolean_t>(),
581 … "[json.exception.type_error.302] type must be boolean, but is array", json::type_error&);
582 CHECK_THROWS_WITH_AS(json(json::value_t::string).get<json::boolean_t>(),
583 "[json.exception.type_error.302] type must be boolean, "
584 "but is string", json::type_error&);
586 json(json::value_t::number_integer).get<json::boolean_t>(),
587 "[json.exception.type_error.302] type must be boolean, but is "
588 "number", json::type_error&);
590 json(json::value_t::number_unsigned).get<json::boolean_t>(),
591 "[json.exception.type_error.302] type must be boolean, but is "
592 "number", json::type_error&);
594 json(json::value_t::number_float).get<json::boolean_t>(),
595 "[json.exception.type_error.302] type must be boolean, but is "
596 "number", json::type_error&);
603 const json::boolean_t b_reference{true};
604 json j(b_reference);
608 const json::boolean_t b = j;
609 CHECK(json(b) == j);
615 CHECK(json(b) == j);
622 const json::number_integer_t n_reference{42};
623 json j(n_reference);
624 const json::number_unsigned_t n_unsigned_reference{42u};
625 json j_unsigned(n_unsigned_reference);
629 auto n = j.get<json::number_integer_t>();
630 CHECK(json(n) == j);
635 auto n = j_unsigned.get<json::number_unsigned_t>();
636 CHECK(json(n) == j_unsigned);
642 CHECK(json(n) == j);
648 CHECK(json(n) == j);
654 CHECK(json(n) == j);
660 CHECK(json(n) == j);
666 CHECK(json(n) == j);
672 CHECK(json(n) == j);
678 CHECK(json(n) == j);
684 CHECK(json(n) == j);
690 CHECK(json(n) == j);
696 CHECK(json(n) == j);
702 CHECK(json(n) == j);
708 CHECK(json(n) == j);
714 CHECK(json(n) == j);
720 CHECK(json(n) == j);
726 CHECK(json(n) == j);
732 CHECK(json(n) == j);
738 CHECK(json(n) == j);
744 CHECK(json(n) == j);
750 CHECK(json(n) == j);
756 CHECK(json(n) == j);
762 CHECK(json(n) == j);
768 CHECK(json(n) == j);
774 CHECK(json(n) == j);
780 CHECK(json(n) == j);
786 CHECK(json(n) == j);
792 CHECK(json(n) == j);
798 CHECK(json(n) == j);
804 CHECK(json(n) == j);
810 CHECK(json(n) == j);
816 CHECK(json(n) == j);
822 CHECK(json(n) == j);
828 CHECK(json(n) == j);
834 json(json::value_t::null).get<json::number_integer_t>(),
835 … "[json.exception.type_error.302] type must be number, but is null", json::type_error&);
837 json(json::value_t::object).get<json::number_integer_t>(),
838 … "[json.exception.type_error.302] type must be number, but is object", json::type_error&);
840 json(json::value_t::array).get<json::number_integer_t>(),
841 … "[json.exception.type_error.302] type must be number, but is array", json::type_error&);
843 json(json::value_t::string).get<json::number_integer_t>(),
844 … "[json.exception.type_error.302] type must be number, but is string", json::type_error&);
846 json(json::value_t::boolean).get<json::number_integer_t>(),
847 "[json.exception.type_error.302] type must be number, but is "
848 "boolean", json::type_error&);
851 json(json::value_t::number_float).get<json::number_integer_t>());
853 json(json::value_t::number_float).get<json::number_unsigned_t>());
860 json::number_integer_t const n_reference{42};
861 json j(n_reference);
862 json::number_unsigned_t const n_unsigned_reference{42u};
863 json j_unsigned(n_unsigned_reference);
867 auto n = j.get<json::number_integer_t>();
868 CHECK(json(n) == j);
873 auto n = j_unsigned.get<json::number_unsigned_t>();
874 CHECK(json(n) == j_unsigned);
880 CHECK(json(n) == j);
886 CHECK(json(n) == j_unsigned);
892 CHECK(json(n) == j);
898 CHECK(json(n) == j_unsigned);
904 CHECK(json(n) == j);
910 CHECK(json(n) == j_unsigned);
916 CHECK(json(n) == j);
922 CHECK(json(n) == j_unsigned);
928 CHECK(json(n) == j);
934 CHECK(json(n) == j);
940 CHECK(json(n) == j);
946 CHECK(json(n) == j);
952 CHECK(json(n) == j);
958 CHECK(json(n) == j);
964 CHECK(json(n) == j);
970 CHECK(json(n) == j);
976 CHECK(json(n) == j);
982 CHECK(json(n) == j);
988 CHECK(json(n) == j);
994 CHECK(json(n) == j);
1000 CHECK(json(n) == j_unsigned);
1006 CHECK(json(n) == j_unsigned);
1012 CHECK(json(n) == j_unsigned);
1018 CHECK(json(n) == j_unsigned);
1024 CHECK(json(n) == j_unsigned);
1030 CHECK(json(n) == j_unsigned);
1036 CHECK(json(n) == j_unsigned);
1042 CHECK(json(n) == j_unsigned);
1048 CHECK(json(n) == j_unsigned);
1054 CHECK(json(n) == j_unsigned);
1060 CHECK(json(n) == j_unsigned);
1066 CHECK(json(n) == j_unsigned);
1073 json::number_float_t const n_reference{42.23};
1074 json const j(n_reference);
1078 auto n = j.get<json::number_float_t>();
1079 CHECK(json(n).m_data.m_value.number_float == Approx(j.m_data.m_value.number_float));
1085 CHECK(json(n).m_data.m_value.number_float == Approx(j.m_data.m_value.number_float));
1091 CHECK(json(n).m_data.m_value.number_float == Approx(j.m_data.m_value.number_float));
1097 json(json::value_t::null).get<json::number_float_t>(),
1098 … "[json.exception.type_error.302] type must be number, but is null", json::type_error&);
1100 json(json::value_t::object).get<json::number_float_t>(),
1101 … "[json.exception.type_error.302] type must be number, but is object", json::type_error&);
1103 json(json::value_t::array).get<json::number_float_t>(),
1104 … "[json.exception.type_error.302] type must be number, but is array", json::type_error&);
1106 json(json::value_t::string).get<json::number_float_t>(),
1107 … "[json.exception.type_error.302] type must be number, but is string", json::type_error&);
1109 json(json::value_t::boolean).get<json::number_float_t>(),
1110 "[json.exception.type_error.302] type must be number, but is "
1111 "boolean", json::type_error&);
1114 json(json::value_t::number_integer).get<json::number_float_t>());
1116 json(json::value_t::number_unsigned).get<json::number_float_t>());
1123 json::number_float_t const n_reference{42.23};
1124 json const j(n_reference);
1128 json::number_float_t const n = j;
1129 CHECK(json(n).m_data.m_value.number_float == Approx(j.m_data.m_value.number_float));
1135 CHECK(json(n).m_data.m_value.number_float == Approx(j.m_data.m_value.number_float));
1141 CHECK(json(n).m_data.m_value.number_float == Approx(j.m_data.m_value.number_float));
1148 json::binary_t const n_reference{{1, 2, 3}};
1149 json j(n_reference);
1153 json::binary_t const b = j.get<json::binary_t>();
1154 CHECK(*json(b).m_data.m_value.binary == *j.m_data.m_value.binary);
1162 CHECK(*json(b).m_data.m_value.binary == *j.m_data.m_value.binary);
1167 const json j_const = j;
1169 CHECK(*json(b).m_data.m_value.binary == *j.m_data.m_value.binary);
1175 json j_null(json::value_t::null);
1176 json j_object(json::value_t::object);
1177 json j_array(json::value_t::array);
1178 json j_string(json::value_t::string);
1179 json j_boolean(json::value_t::boolean);
1180 const json j_null_const(json::value_t::null);
1181 const json j_object_const(json::value_t::object);
1182 const json j_array_const(json::value_t::array);
1183 const json j_string_const(json::value_t::string);
1184 const json j_boolean_const(json::value_t::boolean);
1186 CHECK_THROWS_WITH_AS(j_null.get<json::binary_t>(),
1187 "[json.exception.type_error.302] type must be binary, but is null",
1188 json::type_error&);
1189 CHECK_THROWS_WITH_AS(j_object.get<json::binary_t>(),
1190 … "[json.exception.type_error.302] type must be binary, but is object",
1191 json::type_error&);
1192 CHECK_THROWS_WITH_AS(j_array.get<json::binary_t>(),
1193 … "[json.exception.type_error.302] type must be binary, but is array",
1194 json::type_error&);
1195 CHECK_THROWS_WITH_AS(j_string.get<json::binary_t>(),
1196 … "[json.exception.type_error.302] type must be binary, but is string",
1197 json::type_error&);
1198 CHECK_THROWS_WITH_AS(j_boolean.get<json::binary_t>(),
1199 … "[json.exception.type_error.302] type must be binary, but is boolean",
1200 json::type_error&);
1202 CHECK_THROWS_WITH_AS(j_null_const.get<json::binary_t>(),
1203 "[json.exception.type_error.302] type must be binary, but is null",
1204 json::type_error&);
1205 CHECK_THROWS_WITH_AS(j_object_const.get<json::binary_t>(),
1206 … "[json.exception.type_error.302] type must be binary, but is object",
1207 json::type_error&);
1208 CHECK_THROWS_WITH_AS(j_array_const.get<json::binary_t>(),
1209 … "[json.exception.type_error.302] type must be binary, but is array",
1210 json::type_error&);
1211 CHECK_THROWS_WITH_AS(j_string_const.get<json::binary_t>(),
1212 … "[json.exception.type_error.302] type must be binary, but is string",
1213 json::type_error&);
1214 CHECK_THROWS_WITH_AS(j_boolean_const.get<json::binary_t>(),
1215 … "[json.exception.type_error.302] type must be binary, but is boolean",
1216 json::type_error&);
1219 "[json.exception.type_error.302] type must be binary, but is null",
1220 json::type_error&);
1222 … "[json.exception.type_error.302] type must be binary, but is object",
1223 json::type_error&);
1225 … "[json.exception.type_error.302] type must be binary, but is array",
1226 json::type_error&);
1228 … "[json.exception.type_error.302] type must be binary, but is string",
1229 json::type_error&);
1231 … "[json.exception.type_error.302] type must be binary, but is boolean",
1232 json::type_error&);
1235 "[json.exception.type_error.302] type must be binary, but is null",
1236 json::type_error&);
1238 … "[json.exception.type_error.302] type must be binary, but is object",
1239 json::type_error&);
1241 … "[json.exception.type_error.302] type must be binary, but is array",
1242 json::type_error&);
1244 … "[json.exception.type_error.302] type must be binary, but is string",
1245 json::type_error&);
1247 … "[json.exception.type_error.302] type must be binary, but is boolean",
1248 json::type_error&);
1255 json::binary_t const n_reference{{1, 2, 3}};
1256 json const j(n_reference);
1260 json::binary_t const b = j;
1261 CHECK(*json(b).m_data.m_value.binary == *j.m_data.m_value.binary);
1271 CHECK(json(value_1).get<c_enum>() == value_1);
1272 CHECK(json(cpp_enum::value_1).get<cpp_enum>() == cpp_enum::value_1);
1279 json const j1 = {{"one", 1}, {"two", 2}, {"three", 3}};
1280 json const j2 = {{"one", 1u}, {"two", 2u}, {"three", 3u}};
1281 json const j3 = {{"one", 1.1}, {"two", 2.2}, {"three", 3.3}};
1282 json const j4 = {{"one", true}, {"two", false}, {"three", true}};
1283 json const j5 = {{"one", "eins"}, {"two", "zwei"}, {"three", "drei"}};
1327 (json().get<std::map<std::string, int>>()),
1328 … "[json.exception.type_error.302] type must be object, but is null", json::type_error&);
1334 json const j1 = {1, 2, 3, 4};
1335 json const j2 = {1u, 2u, 3u, 4u};
1336 json const j3 = {1.2, 2.3, 3.4, 4.5};
1337 json const j4 = {true, false, true};
1338 json const j5 = {"one", "two", "three"};
1366 SECTION("std::array is larger than JSON")
1369 CHECK_THROWS_WITH_AS(j1.get_to(arr6), "[json.exception.out_of_range.401] "
1370 "array index 4 is out of range", json::out_of_range&);
1373 SECTION("std::array is smaller than JSON")
1430 json const j6 = m;
1435 json const j7 = {0, 1, 2, 3};
1436 json const j8 = 2;
1438 "[json.exception.type_error.302] type must be array, "
1439 "but is number", json::type_error&);
1441 "[json.exception.type_error.302] type must be array, "
1442 "but is number", json::type_error&);
1446 json const j9 = {{0, 1, 2}, {1, 2, 3}, {2, 3, 4}};
1455 json const j6 = m;
1460 json const j7 = {0, 1, 2, 3};
1461 json const j8 = 2;
1463 "[json.exception.type_error.302] type must be array, "
1464 "but is number", json::type_error&);
1466 "[json.exception.type_error.302] type must be array, "
1467 "but is number", json::type_error&);
1471 json const j9{{0, 1, 2}, {1, 2, 3}, {2, 3, 4}};
1482 (json().get<std::list<int>>()),
1483 … "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
1485 (json().get<std::vector<int>>()),
1486 … "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
1488 (json().get<std::vector<json>>()),
1489 … "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
1491 (json().get<std::list<json>>()),
1492 … "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
1494 (json().get<std::valarray<int>>()),
1495 … "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
1497 (json().get<std::map<int, int>>()),
1498 … "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
1533 TEST_CASE("JSON to enum mapping")
1537 // enum -> json
1538 CHECK(json(cards::kreuz) == "kreuz");
1539 CHECK(json(cards::pik) == "pik");
1540 CHECK(json(cards::herz) == "herz");
1541 CHECK(json(cards::karo) == "karo");
1543 // json -> enum
1544 CHECK(cards::kreuz == json("kreuz"));
1545 CHECK(cards::pik == json("pik"));
1546 CHECK(cards::herz == json("herz"));
1547 CHECK(cards::karo == json("karo"));
1549 // invalid json -> first enum
1550 CHECK(cards::kreuz == json("what?").get<cards>());
1555 // enum -> json
1556 CHECK(json(TS_STOPPED) == "stopped");
1557 CHECK(json(TS_RUNNING) == "running");
1558 CHECK(json(TS_COMPLETED) == "completed");
1559 CHECK(json(TS_INVALID) == json());
1561 // json -> enum
1562 CHECK(TS_STOPPED == json("stopped"));
1563 CHECK(TS_RUNNING == json("running"));
1564 CHECK(TS_COMPLETED == json("completed"));
1565 CHECK(TS_INVALID == json());
1567 // invalid json -> first enum
1568 CHECK(TS_INVALID == json("what?").get<TaskState>());