Lines Matching full:json
2 // __| | __| | | | JSON for Modern C++ (supporting code)
4 // |_____|_____|_____|_|___| https://github.com/nlohmann/json
12 #include <nlohmann/json.hpp>
20 TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_json)
24 …Json j = {{"integer", 1}, {"unsigned", 1u}, {"floating", 42.23}, {"null", nullptr}, {"string", "he…
25 const Json j_const = j;
31 CHECK(j.at("integer") == Json(1));
32 CHECK(j.at("unsigned") == Json(1u));
33 CHECK(j.at("boolean") == Json(true));
34 CHECK(j.at("null") == Json(nullptr));
35 CHECK(j.at("string") == Json("hello world"));
36 CHECK(j.at("floating") == Json(42.23));
37 CHECK(j.at("object") == Json::object());
38 CHECK(j.at("array") == Json({1, 2, 3}));
40 CHECK(j_const.at("integer") == Json(1));
41 CHECK(j_const.at("unsigned") == Json(1u));
42 CHECK(j_const.at("boolean") == Json(true));
43 CHECK(j_const.at("null") == Json(nullptr));
44 CHECK(j_const.at("string") == Json("hello world"));
45 CHECK(j_const.at("floating") == Json(42.23));
46 CHECK(j_const.at("object") == Json::object());
47 CHECK(j_const.at("array") == Json({1, 2, 3}));
50 CHECK(j.at(std::string_view("integer")) == Json(1));
51 CHECK(j.at(std::string_view("unsigned")) == Json(1u));
52 CHECK(j.at(std::string_view("boolean")) == Json(true));
53 CHECK(j.at(std::string_view("null")) == Json(nullptr));
54 CHECK(j.at(std::string_view("string")) == Json("hello world"));
55 CHECK(j.at(std::string_view("floating")) == Json(42.23));
56 CHECK(j.at(std::string_view("object")) == Json::object());
57 CHECK(j.at(std::string_view("array")) == Json({1, 2, 3}));
59 CHECK(j_const.at(std::string_view("integer")) == Json(1));
60 CHECK(j_const.at(std::string_view("unsigned")) == Json(1u));
61 CHECK(j_const.at(std::string_view("boolean")) == Json(true));
62 CHECK(j_const.at(std::string_view("null")) == Json(nullptr));
63 CHECK(j_const.at(std::string_view("string")) == Json("hello world"));
64 CHECK(j_const.at(std::string_view("floating")) == Json(42.23));
65 CHECK(j_const.at(std::string_view("object")) == Json::object());
66 CHECK(j_const.at(std::string_view("array")) == Json({1, 2, 3}));
72 …CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typenam…
73 …CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", t…
76 …_WITH_AS(j.at(std::string_view("foo")), "[json.exception.out_of_range.403] key 'foo' not found", t…
77 …AS(j_const.at(std::string_view("foo")), "[json.exception.out_of_range.403] key 'foo' not found", t…
85 Json j_nonobject(Json::value_t::null);
86 const Json j_nonobject_const(j_nonobject);
87 …THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with null",…
88 …_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with null",…
91 …tring_view(std::string_view("foo"))), "[json.exception.type_error.304] cannot use at() with null",…
92 …tring_view(std::string_view("foo"))), "[json.exception.type_error.304] cannot use at() with null",…
98 Json j_nonobject(Json::value_t::boolean);
99 const Json j_nonobject_const(j_nonobject);
100 …HROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean…
101 …WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean…
104 …nobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with boolean…
105 …t_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with boolean…
111 Json j_nonobject(Json::value_t::string);
112 const Json j_nonobject_const(j_nonobject);
113 …HROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with string"…
114 …WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with string"…
117 …nobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with string"…
118 …t_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with string"…
124 Json j_nonobject(Json::value_t::array);
125 const Json j_nonobject_const(j_nonobject);
126 …THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with array"…
127 …_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with array"…
130 …onobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with array"…
131 …ct_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with array"…
137 Json j_nonobject(Json::value_t::number_integer);
138 const Json j_nonobject_const(j_nonobject);
139 …HROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number"…
140 …WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number"…
143 …nobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number"…
144 …t_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number"…
150 Json j_nonobject(Json::value_t::number_unsigned);
151 const Json j_nonobject_const(j_nonobject);
152 …HROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number"…
153 …WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number"…
156 …nobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number"…
157 …t_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number"…
163 Json j_nonobject(Json::value_t::number_float);
164 const Json j_nonobject_const(j_nonobject);
165 …HROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number"…
166 …WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number"…
169 …nobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number"…
170 …t_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number"…
186 CHECK(j.value("null", Json(1)) == Json());
192 CHECK(j.value("object", Json({{"foo", "bar"}})) == Json::object());
193 CHECK(j.value("array", Json({10, 100})) == Json({1, 2, 3}));
204 CHECK(j_const.value("object", Json({{"foo", "bar"}})) == Json::object());
205 CHECK(j_const.value("array", Json({10, 100})) == Json({1, 2, 3}));
212 CHECK(j.value(std::string_view("null"), Json(1)) == Json());
218 … CHECK(j.value(std::string_view("object"), Json({{"foo", "bar"}})) == Json::object());
219 CHECK(j.value(std::string_view("array"), Json({10, 100})) == Json({1, 2, 3}));
230 … CHECK(j_const.value(std::string_view("object"), Json({{"foo", "bar"}})) == Json::object());
231 … CHECK(j_const.value(std::string_view("array"), Json({10, 100})) == Json({1, 2, 3}));
242 CHECK(j.value("_", Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
243 CHECK(j.value("_", Json({10, 100})) == Json({10, 100}));
250 CHECK(j_const.value("_", Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
251 CHECK(j_const.value("_", Json({10, 100})) == Json({10, 100}));
259 … CHECK(j.value(std::string_view("_"), Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
260 CHECK(j.value(std::string_view("_"), Json({10, 100})) == Json({10, 100}));
267 … CHECK(j_const.value(std::string_view("_"), Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
268 CHECK(j_const.value(std::string_view("_"), Json({10, 100})) == Json({10, 100}));
276 Json j_nonobject(Json::value_t::null);
277 const Json j_nonobject_const(Json::value_t::null);
278 …WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with null…
279 …S(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with null…
282 …t.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with null…
283 …t.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with null…
289 Json j_nonobject(Json::value_t::boolean);
290 const Json j_nonobject_const(Json::value_t::boolean);
291 …TH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with boolea…
292 …j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with boolea…
295 …value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with boolea…
296 …value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with boolea…
302 Json j_nonobject(Json::value_t::string);
303 const Json j_nonobject_const(Json::value_t::string);
304 …ITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with strin…
305 …(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with strin…
308 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with strin…
309 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with strin…
315 Json j_nonobject(Json::value_t::array);
316 const Json j_nonobject_const(Json::value_t::array);
317 …ITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with array…
318 …(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with array…
321 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with array…
322 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with array…
328 Json j_nonobject(Json::value_t::number_integer);
329 const Json j_nonobject_const(Json::value_t::number_integer);
330 …ITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with numbe…
331 …(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with numbe…
334 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with numbe…
335 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with numbe…
341 Json j_nonobject(Json::value_t::number_unsigned);
342 const Json j_nonobject_const(Json::value_t::number_unsigned);
343 …ITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with numbe…
344 …(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with numbe…
347 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with numbe…
348 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with numbe…
354 Json j_nonobject(Json::value_t::number_float);
355 const Json j_nonobject_const(Json::value_t::number_float);
356 …ITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with numbe…
357 …(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with numbe…
360 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with numbe…
361 ….value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with numbe…
367 SECTION("given a JSON pointer")
375 CHECK(j.value("/null"_json_pointer, Json(1)) == Json());
381 … CHECK(j.value("/object"_json_pointer, Json({{"foo", "bar"}})) == Json::object());
382 CHECK(j.value("/array"_json_pointer, Json({10, 100})) == Json({1, 2, 3}));
393 … CHECK(j_const.value("/object"_json_pointer, Json({{"foo", "bar"}})) == Json::object());
394 CHECK(j_const.value("/array"_json_pointer, Json({10, 100})) == Json({1, 2, 3}));
401 Json j_nonobject(Json::value_t::null);
402 const Json j_nonobject_const(Json::value_t::null);
403 …bject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with null…
404 …const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with null…
409 Json j_nonobject(Json::value_t::boolean);
410 const Json j_nonobject_const(Json::value_t::boolean);
411 …ect.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with boolea…
412 …nst.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with boolea…
417 Json j_nonobject(Json::value_t::string);
418 const Json j_nonobject_const(Json::value_t::string);
419 …ject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with strin…
420 …onst.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with strin…
425 Json j_nonobject(Json::value_t::array);
426 const Json j_nonobject_const(Json::value_t::array);
427 …ject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with array…
428 …onst.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with array…
433 Json j_nonobject(Json::value_t::number_integer);
434 const Json j_nonobject_const(Json::value_t::number_integer);
435 …ject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with numbe…
436 …onst.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with numbe…
441 Json j_nonobject(Json::value_t::number_unsigned);
442 const Json j_nonobject_const(Json::value_t::number_unsigned);
443 …ject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with numbe…
444 …onst.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with numbe…
449 Json j_nonobject(Json::value_t::number_float);
450 const Json j_nonobject_const(Json::value_t::number_float);
451 …ject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with numbe…
452 …onst.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with numbe…
461 Json j_null;
472 Json j_null;
485 if (std::is_same<Json, nlohmann::ordered_json>::value)
488 CHECK(j.front() == Json(1));
489 CHECK(j_const.front() == Json(1));
491 CHECK(j.back() == Json({1, 2, 3}));
492 CHECK(j_const.back() == Json({1, 2, 3}));
497 CHECK(j.front() == Json({1, 2, 3}));
498 CHECK(j_const.front() == Json({1, 2, 3}));
500 CHECK(j.back() == Json(1u));
501 CHECK(j_const.back() == Json(1u));
509 CHECK(j["integer"] == Json(1));
510 CHECK(j[typename Json::object_t::key_type("integer")] == j["integer"]);
512 CHECK(j["unsigned"] == Json(1u));
513 CHECK(j[typename Json::object_t::key_type("unsigned")] == j["unsigned"]);
515 CHECK(j["boolean"] == Json(true));
516 CHECK(j[typename Json::object_t::key_type("boolean")] == j["boolean"]);
518 CHECK(j["null"] == Json(nullptr));
519 CHECK(j[typename Json::object_t::key_type("null")] == j["null"]);
521 CHECK(j["string"] == Json("hello world"));
522 CHECK(j[typename Json::object_t::key_type("string")] == j["string"]);
524 CHECK(j["floating"] == Json(42.23));
525 CHECK(j[typename Json::object_t::key_type("floating")] == j["floating"]);
527 CHECK(j["object"] == Json::object());
528 CHECK(j[typename Json::object_t::key_type("object")] == j["object"]);
530 CHECK(j["array"] == Json({1, 2, 3}));
531 CHECK(j[typename Json::object_t::key_type("array")] == j["array"]);
533 CHECK(j_const["integer"] == Json(1));
534 CHECK(j_const[typename Json::object_t::key_type("integer")] == j["integer"]);
536 CHECK(j_const["boolean"] == Json(true));
537 CHECK(j_const[typename Json::object_t::key_type("boolean")] == j["boolean"]);
539 CHECK(j_const["null"] == Json(nullptr));
540 CHECK(j_const[typename Json::object_t::key_type("null")] == j["null"]);
542 CHECK(j_const["string"] == Json("hello world"));
543 CHECK(j_const[typename Json::object_t::key_type("string")] == j["string"]);
545 CHECK(j_const["floating"] == Json(42.23));
546 CHECK(j_const[typename Json::object_t::key_type("floating")] == j["floating"]);
548 CHECK(j_const["object"] == Json::object());
549 CHECK(j_const[typename Json::object_t::key_type("object")] == j["object"]);
551 CHECK(j_const["array"] == Json({1, 2, 3}));
552 CHECK(j_const[typename Json::object_t::key_type("array")] == j["array"]);
558 CHECK(j["integer"] == Json(1));
561 CHECK(j["unsigned"] == Json(1u));
564 CHECK(j["boolean"] == Json(true));
567 CHECK(j["null"] == Json(nullptr));
570 CHECK(j["string"] == Json("hello world"));
573 CHECK(j["floating"] == Json(42.23));
576 CHECK(j["object"] == Json::object());
579 CHECK(j["array"] == Json({1, 2, 3}));
582 CHECK(j_const["integer"] == Json(1));
585 CHECK(j_const["boolean"] == Json(true));
588 CHECK(j_const["null"] == Json(nullptr));
591 CHECK(j_const["string"] == Json("hello world"));
594 CHECK(j_const["floating"] == Json(42.23));
597 CHECK(j_const["object"] == Json::object());
600 CHECK(j_const["array"] == Json({1, 2, 3}));
609 Json j_nonobject(Json::value_t::null);
610 Json j_nonobject2(Json::value_t::null);
611 const Json j_const_nonobject(j_nonobject);
614 CHECK_NOTHROW(j_nonobject2[typename Json::object_t::key_type("foo")]);
615 …const_nonobject["foo"], "[json.exception.type_error.305] cannot use operator[] with a string argum…
616 …ypename Json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] w…
620 …d::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argum…
626 Json j_nonobject(Json::value_t::boolean);
627 const Json j_const_nonobject(j_nonobject);
629 …"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typen…
630 CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")],
631 …"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typen…
633 …"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typen…
634 … CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")],
635 …"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typen…
638 …:string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argumen…
639 …:string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argumen…
645 Json j_nonobject(Json::value_t::string);
646 const Json j_const_nonobject(j_nonobject);
648 …"[json.exception.type_error.305] cannot use operator[] with a string argument with string", typena…
649 CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")],
650 …"[json.exception.type_error.305] cannot use operator[] with a string argument with string", typena…
652 …"[json.exception.type_error.305] cannot use operator[] with a string argument with string", typena…
653 … CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")],
654 …"[json.exception.type_error.305] cannot use operator[] with a string argument with string", typena…
657 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
658 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
664 Json j_nonobject(Json::value_t::array);
665 const Json j_const_nonobject(j_nonobject);
667 …"[json.exception.type_error.305] cannot use operator[] with a string argument with array", typenam…
668 …pename Json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] wi…
670 …"[json.exception.type_error.305] cannot use operator[] with a string argument with array", typenam…
671 … CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")],
672 …"[json.exception.type_error.305] cannot use operator[] with a string argument with array", typenam…
675 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
676 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
682 Json j_nonobject(Json::value_t::number_integer);
683 const Json j_const_nonobject(j_nonobject);
685 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
686 CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")],
687 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
689 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
690 … CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")],
691 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
694 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
695 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
701 Json j_nonobject(Json::value_t::number_unsigned);
702 const Json j_const_nonobject(j_nonobject);
704 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
705 CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")],
706 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
708 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
709 … CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")],
710 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
713 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
714 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
720 Json j_nonobject(Json::value_t::number_float);
721 const Json j_const_nonobject(j_nonobject);
723 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
724 CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")],
725 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
727 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
728 … CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")],
729 …"[json.exception.type_error.305] cannot use operator[] with a string argument with number", typena…
732 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
733 …::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argume…
834 Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
835 typename Json::iterator const it2 = jobject.erase(jobject.begin());
836 CHECK(jobject == Json({{"b", 1}, {"c", 17u}}));
837 CHECK(*it2 == Json(1));
840 Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
841 typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin());
842 CHECK(jobject == Json({{"b", 1}, {"c", 17u}}));
843 CHECK(*it2 == Json(1));
850 Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
851 typename Json::iterator it2 = jobject.erase(jobject.begin(), jobject.end());
852 CHECK(jobject == Json::object());
856 Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
857 … typename Json::const_iterator it2 = jobject.erase(jobject.cbegin(), jobject.cend());
858 CHECK(jobject == Json::object());
866 Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
867 … typename Json::iterator const it2 = jobject.erase(jobject.begin(), jobject.begin());
868 CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}}));
869 CHECK(*it2 == Json("a"));
872 Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
873 … typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin(), jobject.cbegin());
874 CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}}));
875 CHECK(*it2 == Json("a"));
882 Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
883 typename Json::iterator const it = jobject.find("b");
884 typename Json::iterator const it2 = jobject.erase(it);
885 CHECK(jobject == Json({{"a", "a"}, {"c", 17u}}));
886 CHECK(*it2 == Json(17));
889 Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
890 typename Json::const_iterator const it = jobject.find("b");
891 typename Json::const_iterator const it2 = jobject.erase(it);
892 CHECK(jobject == Json({{"a", "a"}, {"c", 17u}}));
893 CHECK(*it2 == Json(17));
900 … Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
901 … typename Json::iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e"));
902 CHECK(jobject == Json({{"a", "a"}, {"e", true}}));
903 CHECK(*it2 == Json(true));
906 … Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
907 … typename Json::const_iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e"));
908 CHECK(jobject == Json({{"a", "a"}, {"e", true}}));
909 CHECK(*it2 == Json(true));
916 … Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
917 Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
919 …"[json.exception.invalid_iterator.202] iterator does not fit current value", typename Json::invali…
921 …"[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid…
923 …"[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid…
925 …"[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid…
928 … Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
929 Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
931 …"[json.exception.invalid_iterator.202] iterator does not fit current value", typename Json::invali…
933 …"[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid…
935 …"[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid…
937 …"[json.exception.invalid_iterator.203] iterators do not fit current value", typename Json::invalid…
946 Json j_nonobject(Json::value_t::null);
947 …WS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with null…
950 …ject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with null…
956 Json j_nonobject(Json::value_t::boolean);
957 …_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with boolea…
960 …ct.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with boolea…
966 Json j_nonobject(Json::value_t::string);
967 …S_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with strin…
970 …ect.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with strin…
976 Json j_nonobject(Json::value_t::array);
977 …S_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with array…
980 …ect.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with array…
986 Json j_nonobject(Json::value_t::number_integer);
987 …S_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with numbe…
990 …ect.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with numbe…
996 Json j_nonobject(Json::value_t::number_float);
997 …S_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with numbe…
1000 …ect.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with numbe…
1047 Json j_nonarray(Json::value_t::null);
1048 const Json j_nonarray_const(j_nonarray);
1061 Json j_nonarray(Json::value_t::string);
1062 const Json j_nonarray_const(j_nonarray);
1075 Json j_nonarray(Json::value_t::object);
1076 const Json j_nonarray_const(j_nonarray);
1089 Json j_nonarray(Json::value_t::array);
1090 const Json j_nonarray_const(j_nonarray);
1103 Json j_nonarray(Json::value_t::boolean);
1104 const Json j_nonarray_const(j_nonarray);
1117 Json j_nonarray(Json::value_t::number_integer);
1118 const Json j_nonarray_const(j_nonarray);
1131 Json j_nonarray(Json::value_t::number_unsigned);
1132 const Json j_nonarray_const(j_nonarray);
1145 Json j_nonarray(Json::value_t::number_float);
1146 const Json j_nonarray_const(j_nonarray);
1196 Json j_nonobject(Json::value_t::null);
1197 const Json j_nonobject_const(Json::value_t::null);
1210 Json j_nonobject(Json::value_t::string);
1211 const Json j_nonobject_const(Json::value_t::string);
1224 Json j_nonobject(Json::value_t::object);
1225 const Json j_nonobject_const(Json::value_t::object);
1238 Json j_nonobject(Json::value_t::array);
1239 const Json j_nonobject_const(Json::value_t::array);
1252 Json j_nonobject(Json::value_t::boolean);
1253 const Json j_nonobject_const(Json::value_t::boolean);
1266 Json j_nonobject(Json::value_t::number_integer);
1267 const Json j_nonobject_const(Json::value_t::number_integer);
1280 Json j_nonobject(Json::value_t::number_unsigned);
1281 const Json j_nonobject_const(Json::value_t::number_unsigned);
1294 Json j_nonobject(Json::value_t::number_float);
1295 const Json j_nonobject_const(Json::value_t::number_float);
1346 Json j_nonobject(Json::value_t::null);
1347 const Json j_nonobject_const(Json::value_t::null);
1360 Json j_nonobject(Json::value_t::string);
1361 const Json j_nonobject_const(Json::value_t::string);
1374 Json j_nonobject(Json::value_t::object);
1375 const Json j_nonobject_const(Json::value_t::object);
1388 Json j_nonobject(Json::value_t::array);
1389 const Json j_nonobject_const(Json::value_t::array);
1402 Json j_nonobject(Json::value_t::boolean);
1403 const Json j_nonobject_const(Json::value_t::boolean);
1416 Json j_nonobject(Json::value_t::number_integer);
1417 const Json j_nonobject_const(Json::value_t::number_integer);
1430 Json j_nonobject(Json::value_t::number_unsigned);
1431 const Json j_nonobject_const(Json::value_t::number_unsigned);
1444 Json j_nonobject(Json::value_t::number_float);
1445 const Json j_nonobject_const(Json::value_t::number_float);
1459 TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nlohmann::ordered_jso…
1463 …Json j = {{"integer", 1}, {"unsigned", 1u}, {"floating", 42.23}, {"null", nullptr}, {"string", "he…
1464 … Json j_const = {{"integer", 1}, {"unsigned", 1u}, {"floating", 42.23}, {"null", nullptr}, {"strin…
1468 SECTION("given a JSON pointer")
1477 … CHECK(j.value("/not/existing"_json_pointer, Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
1478 … CHECK(j.value("/not/existing"_json_pointer, Json({10, 100})) == Json({10, 100}));
1485 …CHECK(j_const.value("/not/existing"_json_pointer, Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}…
1486 … CHECK(j_const.value("/not/existing"_json_pointer, Json({10, 100})) == Json({10, 100}));
1495 TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann::json, nlohmann::o…
1497 using string_t = typename Json::string_t;
1498 using number_integer_t = typename Json::number_integer_t;
1501 REQUIRE(std::is_same<string_t, typename Json::object_t::key_type>::value);
1503 Json j
1538 …CHECK_THROWS_WITH_AS(Json().value("foo", "default"), "[json.exception.type_error.306] cannot use v…
1539 …CHECK_THROWS_WITH_AS(Json().value("foo", str), "[json.exception.type_error.306] cannot use value()…
1563 …CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use val…
1564 …CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() w…
1588 …CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use val…
1589 …CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() w…
1613 …CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use val…
1614 …CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() w…
1639 …CHECK_THROWS_WITH_AS(Json().value(key, "default"), "[json.exception.type_error.306] cannot use val…
1640 …CHECK_THROWS_WITH_AS(Json().value(key, str), "[json.exception.type_error.306] cannot use value() w…
1668 …OWS_WITH_AS(Json().template value<string_t>("foo", "default"), "[json.exception.type_error.306] ca…
1669 …THROWS_WITH_AS(Json().template value<string_t>("foo", str), "[json.exception.type_error.306] canno…
1697 …ROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] can…
1698 …_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot…
1726 …ROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] can…
1727 …_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot…
1751 …ROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] can…
1752 …_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot…
1788 …ROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] can…
1789 …_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot…