3 __| | __| | | | JSON for Modern C++ (test suite)
4 | | |__ | | | | | | version 3.10.5
5 |_____|_____|_____|_|___| https://github.com/nlohmann/json
7 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
8 SPDX-License-Identifier: MIT
9 Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include "doctest_compatibility.h"
32 #define JSON_TESTS_PRIVATE
33 #include <nlohmann/json.hpp>
36 TEST_CASE("iterators 1")
38 SECTION("basic behavior")
40 SECTION("uninitialized")
43 CHECK(it
.m_object
== nullptr);
45 json::const_iterator cit
;
46 CHECK(cit
.m_object
== nullptr);
54 SECTION("json + begin/end")
56 json::iterator it
= j
.begin();
61 CHECK(it
!= j
.begin());
65 CHECK(it
== j
.begin());
70 CHECK(it
!= j
.begin());
74 CHECK(it
== j
.begin());
79 SECTION("const json + begin/end")
81 json::const_iterator it
= j_const
.begin();
82 CHECK(it
!= j_const
.end());
83 CHECK(*it
== j_const
);
86 CHECK(it
!= j_const
.begin());
87 CHECK(it
== j_const
.end());
90 CHECK(it
== j_const
.begin());
91 CHECK(it
!= j_const
.end());
92 CHECK(*it
== j_const
);
95 CHECK(it
!= j_const
.begin());
96 CHECK(it
== j_const
.end());
99 CHECK(it
== j_const
.begin());
100 CHECK(it
!= j_const
.end());
101 CHECK(*it
== j_const
);
104 SECTION("json + cbegin/cend")
106 json::const_iterator it
= j
.cbegin();
107 CHECK(it
!= j
.cend());
111 CHECK(it
!= j
.cbegin());
112 CHECK(it
== j
.cend());
115 CHECK(it
== j
.cbegin());
116 CHECK(it
!= j
.cend());
120 CHECK(it
!= j
.cbegin());
121 CHECK(it
== j
.cend());
124 CHECK(it
== j
.cbegin());
125 CHECK(it
!= j
.cend());
129 SECTION("const json + cbegin/cend")
131 json::const_iterator it
= j_const
.cbegin();
132 CHECK(it
!= j_const
.cend());
133 CHECK(*it
== j_const
);
136 CHECK(it
!= j_const
.cbegin());
137 CHECK(it
== j_const
.cend());
140 CHECK(it
== j_const
.cbegin());
141 CHECK(it
!= j_const
.cend());
142 CHECK(*it
== j_const
);
145 CHECK(it
!= j_const
.cbegin());
146 CHECK(it
== j_const
.cend());
149 CHECK(it
== j_const
.cbegin());
150 CHECK(it
!= j_const
.cend());
151 CHECK(*it
== j_const
);
154 SECTION("json + rbegin/rend")
156 json::reverse_iterator it
= j
.rbegin();
157 CHECK(it
!= j
.rend());
161 CHECK(it
!= j
.rbegin());
162 CHECK(it
== j
.rend());
165 CHECK(it
== j
.rbegin());
166 CHECK(it
!= j
.rend());
170 CHECK(it
!= j
.rbegin());
171 CHECK(it
== j
.rend());
174 CHECK(it
== j
.rbegin());
175 CHECK(it
!= j
.rend());
179 SECTION("json + crbegin/crend")
181 json::const_reverse_iterator it
= j
.crbegin();
182 CHECK(it
!= j
.crend());
186 CHECK(it
!= j
.crbegin());
187 CHECK(it
== j
.crend());
190 CHECK(it
== j
.crbegin());
191 CHECK(it
!= j
.crend());
195 CHECK(it
!= j
.crbegin());
196 CHECK(it
== j
.crend());
199 CHECK(it
== j
.crbegin());
200 CHECK(it
!= j
.crend());
204 SECTION("const json + crbegin/crend")
206 json::const_reverse_iterator it
= j_const
.crbegin();
207 CHECK(it
!= j_const
.crend());
208 CHECK(*it
== j_const
);
211 CHECK(it
!= j_const
.crbegin());
212 CHECK(it
== j_const
.crend());
215 CHECK(it
== j_const
.crbegin());
216 CHECK(it
!= j_const
.crend());
217 CHECK(*it
== j_const
);
220 CHECK(it
!= j_const
.crbegin());
221 CHECK(it
== j_const
.crend());
224 CHECK(it
== j_const
.crbegin());
225 CHECK(it
!= j_const
.crend());
226 CHECK(*it
== j_const
);
229 SECTION("additional tests")
231 SECTION("!(begin != begin)")
233 CHECK(!(j
.begin() != j
.begin()));
236 SECTION("!(end != end)")
238 CHECK(!(j
.end() != j
.end()));
241 SECTION("begin < end")
243 CHECK(j
.begin() < j
.end());
246 SECTION("begin <= end")
248 CHECK(j
.begin() <= j
.end());
251 SECTION("end > begin")
253 CHECK(j
.end() > j
.begin());
256 SECTION("end >= begin")
258 CHECK(j
.end() >= j
.begin());
261 SECTION("end == end")
263 CHECK(j
.end() == j
.end());
266 SECTION("end <= end")
268 CHECK(j
.end() <= j
.end());
271 SECTION("begin == begin")
273 CHECK(j
.begin() == j
.begin());
276 SECTION("begin <= begin")
278 CHECK(j
.begin() <= j
.begin());
281 SECTION("begin >= begin")
283 CHECK(j
.begin() >= j
.begin());
286 SECTION("!(begin == end)")
288 CHECK(!(j
.begin() == j
.end()));
291 SECTION("begin != end")
293 CHECK(j
.begin() != j
.end());
296 SECTION("begin+1 == end")
298 CHECK(j
.begin() + 1 == j
.end());
301 SECTION("begin == end-1")
303 CHECK(j
.begin() == j
.end() - 1);
306 SECTION("begin != end+1")
308 CHECK(j
.begin() != j
.end() + 1);
311 SECTION("end != end+1")
313 CHECK(j
.end() != j
.end() + 1);
316 SECTION("begin+1 != begin+2")
318 CHECK(j
.begin() + 1 != j
.begin() + 2);
321 SECTION("begin+1 < begin+2")
323 CHECK(j
.begin() + 1 < j
.begin() + 2);
326 SECTION("begin+1 <= begin+2")
328 CHECK(j
.begin() + 1 <= j
.begin() + 2);
331 SECTION("end+1 != end+2")
333 CHECK(j
.end() + 1 != j
.end() + 2);
340 auto cit
= j_const
.cbegin();
341 CHECK_THROWS_AS(it
.key(), json::invalid_iterator
&);
342 CHECK_THROWS_WITH(it
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
343 CHECK(it
.value() == json(true));
344 CHECK_THROWS_AS(cit
.key(), json::invalid_iterator
&);
345 CHECK_THROWS_WITH(cit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
346 CHECK(cit
.value() == json(true));
349 auto crit
= j
.crend();
350 CHECK_THROWS_AS(rit
.key(), json::invalid_iterator
&);
351 CHECK_THROWS_AS(rit
.value(), json::invalid_iterator
&);
352 CHECK_THROWS_AS(crit
.key(), json::invalid_iterator
&);
353 CHECK_THROWS_AS(crit
.value(), json::invalid_iterator
&);
354 CHECK_THROWS_WITH(rit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
355 CHECK_THROWS_WITH(rit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
356 CHECK_THROWS_WITH(crit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
357 CHECK_THROWS_WITH(crit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
363 json j
= "hello world";
366 SECTION("json + begin/end")
368 json::iterator it
= j
.begin();
369 CHECK(it
!= j
.end());
373 CHECK(it
!= j
.begin());
374 CHECK(it
== j
.end());
377 CHECK(it
== j
.begin());
378 CHECK(it
!= j
.end());
382 CHECK(it
!= j
.begin());
383 CHECK(it
== j
.end());
386 CHECK(it
== j
.begin());
387 CHECK(it
!= j
.end());
391 SECTION("const json + begin/end")
393 json::const_iterator it
= j_const
.begin();
394 CHECK(it
!= j_const
.end());
395 CHECK(*it
== j_const
);
398 CHECK(it
!= j_const
.begin());
399 CHECK(it
== j_const
.end());
402 CHECK(it
== j_const
.begin());
403 CHECK(it
!= j_const
.end());
404 CHECK(*it
== j_const
);
407 CHECK(it
!= j_const
.begin());
408 CHECK(it
== j_const
.end());
411 CHECK(it
== j_const
.begin());
412 CHECK(it
!= j_const
.end());
413 CHECK(*it
== j_const
);
416 SECTION("json + cbegin/cend")
418 json::const_iterator it
= j
.cbegin();
419 CHECK(it
!= j
.cend());
423 CHECK(it
!= j
.cbegin());
424 CHECK(it
== j
.cend());
427 CHECK(it
== j
.cbegin());
428 CHECK(it
!= j
.cend());
432 CHECK(it
!= j
.cbegin());
433 CHECK(it
== j
.cend());
436 CHECK(it
== j
.cbegin());
437 CHECK(it
!= j
.cend());
441 SECTION("const json + cbegin/cend")
443 json::const_iterator it
= j_const
.cbegin();
444 CHECK(it
!= j_const
.cend());
445 CHECK(*it
== j_const
);
448 CHECK(it
!= j_const
.cbegin());
449 CHECK(it
== j_const
.cend());
452 CHECK(it
== j_const
.cbegin());
453 CHECK(it
!= j_const
.cend());
454 CHECK(*it
== j_const
);
457 CHECK(it
!= j_const
.cbegin());
458 CHECK(it
== j_const
.cend());
461 CHECK(it
== j_const
.cbegin());
462 CHECK(it
!= j_const
.cend());
463 CHECK(*it
== j_const
);
466 SECTION("json + rbegin/rend")
468 json::reverse_iterator it
= j
.rbegin();
469 CHECK(it
!= j
.rend());
473 CHECK(it
!= j
.rbegin());
474 CHECK(it
== j
.rend());
477 CHECK(it
== j
.rbegin());
478 CHECK(it
!= j
.rend());
482 CHECK(it
!= j
.rbegin());
483 CHECK(it
== j
.rend());
486 CHECK(it
== j
.rbegin());
487 CHECK(it
!= j
.rend());
491 SECTION("json + crbegin/crend")
493 json::const_reverse_iterator it
= j
.crbegin();
494 CHECK(it
!= j
.crend());
498 CHECK(it
!= j
.crbegin());
499 CHECK(it
== j
.crend());
502 CHECK(it
== j
.crbegin());
503 CHECK(it
!= j
.crend());
507 CHECK(it
!= j
.crbegin());
508 CHECK(it
== j
.crend());
511 CHECK(it
== j
.crbegin());
512 CHECK(it
!= j
.crend());
516 SECTION("const json + crbegin/crend")
518 json::const_reverse_iterator it
= j_const
.crbegin();
519 CHECK(it
!= j_const
.crend());
520 CHECK(*it
== j_const
);
523 CHECK(it
!= j_const
.crbegin());
524 CHECK(it
== j_const
.crend());
527 CHECK(it
== j_const
.crbegin());
528 CHECK(it
!= j_const
.crend());
529 CHECK(*it
== j_const
);
532 CHECK(it
!= j_const
.crbegin());
533 CHECK(it
== j_const
.crend());
536 CHECK(it
== j_const
.crbegin());
537 CHECK(it
!= j_const
.crend());
538 CHECK(*it
== j_const
);
544 auto cit
= j_const
.cbegin();
545 CHECK_THROWS_AS(it
.key(), json::invalid_iterator
&);
546 CHECK_THROWS_WITH(it
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
547 CHECK(it
.value() == json("hello world"));
548 CHECK_THROWS_AS(cit
.key(), json::invalid_iterator
&);
549 CHECK_THROWS_WITH(cit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
550 CHECK(cit
.value() == json("hello world"));
553 auto crit
= j
.crend();
554 CHECK_THROWS_AS(rit
.key(), json::invalid_iterator
&);
555 CHECK_THROWS_AS(rit
.value(), json::invalid_iterator
&);
556 CHECK_THROWS_AS(crit
.key(), json::invalid_iterator
&);
557 CHECK_THROWS_AS(crit
.value(), json::invalid_iterator
&);
558 CHECK_THROWS_WITH(rit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
559 CHECK_THROWS_WITH(rit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
560 CHECK_THROWS_WITH(crit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
561 CHECK_THROWS_WITH(crit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
570 SECTION("json + begin/end")
572 json::iterator it_begin
= j
.begin();
573 json::iterator it_end
= j
.end();
580 CHECK(it
!= it_begin
);
585 CHECK(it
!= it_begin
);
590 CHECK(it
!= it_begin
);
594 SECTION("const json + begin/end")
596 json::const_iterator it_begin
= j_const
.begin();
597 json::const_iterator it_end
= j_const
.end();
601 CHECK(*it
== j_const
[0]);
604 CHECK(it
!= it_begin
);
606 CHECK(*it
== j_const
[1]);
609 CHECK(it
!= it_begin
);
611 CHECK(*it
== j_const
[2]);
614 CHECK(it
!= it_begin
);
618 SECTION("json + cbegin/cend")
620 json::const_iterator it_begin
= j
.cbegin();
621 json::const_iterator it_end
= j
.cend();
628 CHECK(it
!= it_begin
);
633 CHECK(it
!= it_begin
);
638 CHECK(it
!= it_begin
);
642 SECTION("const json + cbegin/cend")
644 json::const_iterator it_begin
= j_const
.cbegin();
645 json::const_iterator it_end
= j_const
.cend();
652 CHECK(it
!= it_begin
);
657 CHECK(it
!= it_begin
);
662 CHECK(it
!= it_begin
);
666 SECTION("json + rbegin/rend")
668 json::reverse_iterator it_begin
= j
.rbegin();
669 json::reverse_iterator it_end
= j
.rend();
676 CHECK(it
!= it_begin
);
681 CHECK(it
!= it_begin
);
686 CHECK(it
!= it_begin
);
690 SECTION("json + crbegin/crend")
692 json::const_reverse_iterator it_begin
= j
.crbegin();
693 json::const_reverse_iterator it_end
= j
.crend();
700 CHECK(it
!= it_begin
);
705 CHECK(it
!= it_begin
);
710 CHECK(it
!= it_begin
);
714 SECTION("const json + crbegin/crend")
716 json::const_reverse_iterator it_begin
= j_const
.crbegin();
717 json::const_reverse_iterator it_end
= j_const
.crend();
724 CHECK(it
!= it_begin
);
729 CHECK(it
!= it_begin
);
734 CHECK(it
!= it_begin
);
741 auto cit
= j_const
.cbegin();
742 CHECK_THROWS_AS(it
.key(), json::invalid_iterator
&);
743 CHECK_THROWS_WITH(it
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
744 CHECK(it
.value() == json(1));
745 CHECK_THROWS_AS(cit
.key(), json::invalid_iterator
&);
746 CHECK_THROWS_WITH(cit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
747 CHECK(cit
.value() == json(1));
753 json j
= {{"A", 1}, {"B", 2}, {"C", 3}};
756 SECTION("json + begin/end")
758 json::iterator it_begin
= j
.begin();
759 json::iterator it_end
= j
.end();
763 CHECK(*it
== j
["A"]);
766 CHECK(it
!= it_begin
);
768 CHECK(*it
== j
["B"]);
771 CHECK(it
!= it_begin
);
773 CHECK(*it
== j
["C"]);
776 CHECK(it
!= it_begin
);
780 SECTION("const json + begin/end")
782 json::const_iterator it_begin
= j_const
.begin();
783 json::const_iterator it_end
= j_const
.end();
787 CHECK(*it
== j_const
["A"]);
790 CHECK(it
!= it_begin
);
792 CHECK(*it
== j_const
["B"]);
795 CHECK(it
!= it_begin
);
797 CHECK(*it
== j_const
["C"]);
800 CHECK(it
!= it_begin
);
804 SECTION("json + cbegin/cend")
806 json::const_iterator it_begin
= j
.cbegin();
807 json::const_iterator it_end
= j
.cend();
811 CHECK(*it
== j
["A"]);
814 CHECK(it
!= it_begin
);
816 CHECK(*it
== j
["B"]);
819 CHECK(it
!= it_begin
);
821 CHECK(*it
== j
["C"]);
824 CHECK(it
!= it_begin
);
828 SECTION("const json + cbegin/cend")
830 json::const_iterator it_begin
= j_const
.cbegin();
831 json::const_iterator it_end
= j_const
.cend();
835 CHECK(*it
== j_const
["A"]);
838 CHECK(it
!= it_begin
);
840 CHECK(*it
== j_const
["B"]);
843 CHECK(it
!= it_begin
);
845 CHECK(*it
== j_const
["C"]);
848 CHECK(it
!= it_begin
);
852 SECTION("json + rbegin/rend")
854 json::reverse_iterator it_begin
= j
.rbegin();
855 json::reverse_iterator it_end
= j
.rend();
859 CHECK(*it
== j
["C"]);
862 CHECK(it
!= it_begin
);
864 CHECK(*it
== j
["B"]);
867 CHECK(it
!= it_begin
);
869 CHECK(*it
== j
["A"]);
872 CHECK(it
!= it_begin
);
876 SECTION("json + crbegin/crend")
878 json::const_reverse_iterator it_begin
= j
.crbegin();
879 json::const_reverse_iterator it_end
= j
.crend();
883 CHECK(*it
== j
["C"]);
886 CHECK(it
!= it_begin
);
888 CHECK(*it
== j
["B"]);
891 CHECK(it
!= it_begin
);
893 CHECK(*it
== j
["A"]);
896 CHECK(it
!= it_begin
);
900 SECTION("const json + crbegin/crend")
902 json::const_reverse_iterator it_begin
= j_const
.crbegin();
903 json::const_reverse_iterator it_end
= j_const
.crend();
907 CHECK(*it
== j
["C"]);
910 CHECK(it
!= it_begin
);
912 CHECK(*it
== j
["B"]);
915 CHECK(it
!= it_begin
);
917 CHECK(*it
== j
["A"]);
920 CHECK(it
!= it_begin
);
927 auto cit
= j_const
.cbegin();
928 CHECK(it
.key() == "A");
929 CHECK(it
.value() == json(1));
930 CHECK(cit
.key() == "A");
931 CHECK(cit
.value() == json(1));
935 SECTION("number (integer)")
940 SECTION("json + begin/end")
942 json::iterator it
= j
.begin();
943 CHECK(it
!= j
.end());
947 CHECK(it
!= j
.begin());
948 CHECK(it
== j
.end());
951 CHECK(it
== j
.begin());
952 CHECK(it
!= j
.end());
956 CHECK(it
!= j
.begin());
957 CHECK(it
== j
.end());
960 CHECK(it
== j
.begin());
961 CHECK(it
!= j
.end());
965 SECTION("const json + begin/end")
967 json::const_iterator it
= j_const
.begin();
968 CHECK(it
!= j_const
.end());
969 CHECK(*it
== j_const
);
972 CHECK(it
!= j_const
.begin());
973 CHECK(it
== j_const
.end());
976 CHECK(it
== j_const
.begin());
977 CHECK(it
!= j_const
.end());
978 CHECK(*it
== j_const
);
981 CHECK(it
!= j_const
.begin());
982 CHECK(it
== j_const
.end());
985 CHECK(it
== j_const
.begin());
986 CHECK(it
!= j_const
.end());
987 CHECK(*it
== j_const
);
990 SECTION("json + cbegin/cend")
992 json::const_iterator it
= j
.cbegin();
993 CHECK(it
!= j
.cend());
997 CHECK(it
!= j
.cbegin());
998 CHECK(it
== j
.cend());
1001 CHECK(it
== j
.cbegin());
1002 CHECK(it
!= j
.cend());
1006 CHECK(it
!= j
.cbegin());
1007 CHECK(it
== j
.cend());
1010 CHECK(it
== j
.cbegin());
1011 CHECK(it
!= j
.cend());
1015 SECTION("const json + cbegin/cend")
1017 json::const_iterator it
= j_const
.cbegin();
1018 CHECK(it
!= j_const
.cend());
1019 CHECK(*it
== j_const
);
1022 CHECK(it
!= j_const
.cbegin());
1023 CHECK(it
== j_const
.cend());
1026 CHECK(it
== j_const
.cbegin());
1027 CHECK(it
!= j_const
.cend());
1028 CHECK(*it
== j_const
);
1031 CHECK(it
!= j_const
.cbegin());
1032 CHECK(it
== j_const
.cend());
1035 CHECK(it
== j_const
.cbegin());
1036 CHECK(it
!= j_const
.cend());
1037 CHECK(*it
== j_const
);
1040 SECTION("json + rbegin/rend")
1042 json::reverse_iterator it
= j
.rbegin();
1043 CHECK(it
!= j
.rend());
1047 CHECK(it
!= j
.rbegin());
1048 CHECK(it
== j
.rend());
1051 CHECK(it
== j
.rbegin());
1052 CHECK(it
!= j
.rend());
1056 CHECK(it
!= j
.rbegin());
1057 CHECK(it
== j
.rend());
1060 CHECK(it
== j
.rbegin());
1061 CHECK(it
!= j
.rend());
1065 SECTION("json + crbegin/crend")
1067 json::const_reverse_iterator it
= j
.crbegin();
1068 CHECK(it
!= j
.crend());
1072 CHECK(it
!= j
.crbegin());
1073 CHECK(it
== j
.crend());
1076 CHECK(it
== j
.crbegin());
1077 CHECK(it
!= j
.crend());
1081 CHECK(it
!= j
.crbegin());
1082 CHECK(it
== j
.crend());
1085 CHECK(it
== j
.crbegin());
1086 CHECK(it
!= j
.crend());
1090 SECTION("const json + crbegin/crend")
1092 json::const_reverse_iterator it
= j_const
.crbegin();
1093 CHECK(it
!= j_const
.crend());
1094 CHECK(*it
== j_const
);
1097 CHECK(it
!= j_const
.crbegin());
1098 CHECK(it
== j_const
.crend());
1101 CHECK(it
== j_const
.crbegin());
1102 CHECK(it
!= j_const
.crend());
1103 CHECK(*it
== j_const
);
1106 CHECK(it
!= j_const
.crbegin());
1107 CHECK(it
== j_const
.crend());
1110 CHECK(it
== j_const
.crbegin());
1111 CHECK(it
!= j_const
.crend());
1112 CHECK(*it
== j_const
);
1115 SECTION("key/value")
1117 auto it
= j
.begin();
1118 auto cit
= j_const
.cbegin();
1119 CHECK_THROWS_AS(it
.key(), json::invalid_iterator
&);
1120 CHECK_THROWS_WITH(it
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1121 CHECK(it
.value() == json(23));
1122 CHECK_THROWS_AS(cit
.key(), json::invalid_iterator
&);
1123 CHECK_THROWS_WITH(cit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1124 CHECK(cit
.value() == json(23));
1126 auto rit
= j
.rend();
1127 auto crit
= j
.crend();
1128 CHECK_THROWS_AS(rit
.key(), json::invalid_iterator
&);
1129 CHECK_THROWS_AS(rit
.value(), json::invalid_iterator
&);
1130 CHECK_THROWS_AS(crit
.key(), json::invalid_iterator
&);
1131 CHECK_THROWS_AS(crit
.value(), json::invalid_iterator
&);
1132 CHECK_THROWS_WITH(rit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1133 CHECK_THROWS_WITH(rit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1134 CHECK_THROWS_WITH(crit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1135 CHECK_THROWS_WITH(crit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1139 SECTION("number (unsigned)")
1144 SECTION("json + begin/end")
1146 json::iterator it
= j
.begin();
1147 CHECK(it
!= j
.end());
1151 CHECK(it
!= j
.begin());
1152 CHECK(it
== j
.end());
1155 CHECK(it
== j
.begin());
1156 CHECK(it
!= j
.end());
1160 CHECK(it
!= j
.begin());
1161 CHECK(it
== j
.end());
1164 CHECK(it
== j
.begin());
1165 CHECK(it
!= j
.end());
1169 SECTION("const json + begin/end")
1171 json::const_iterator it
= j_const
.begin();
1172 CHECK(it
!= j_const
.end());
1173 CHECK(*it
== j_const
);
1176 CHECK(it
!= j_const
.begin());
1177 CHECK(it
== j_const
.end());
1180 CHECK(it
== j_const
.begin());
1181 CHECK(it
!= j_const
.end());
1182 CHECK(*it
== j_const
);
1185 CHECK(it
!= j_const
.begin());
1186 CHECK(it
== j_const
.end());
1189 CHECK(it
== j_const
.begin());
1190 CHECK(it
!= j_const
.end());
1191 CHECK(*it
== j_const
);
1194 SECTION("json + cbegin/cend")
1196 json::const_iterator it
= j
.cbegin();
1197 CHECK(it
!= j
.cend());
1201 CHECK(it
!= j
.cbegin());
1202 CHECK(it
== j
.cend());
1205 CHECK(it
== j
.cbegin());
1206 CHECK(it
!= j
.cend());
1210 CHECK(it
!= j
.cbegin());
1211 CHECK(it
== j
.cend());
1214 CHECK(it
== j
.cbegin());
1215 CHECK(it
!= j
.cend());
1219 SECTION("const json + cbegin/cend")
1221 json::const_iterator it
= j_const
.cbegin();
1222 CHECK(it
!= j_const
.cend());
1223 CHECK(*it
== j_const
);
1226 CHECK(it
!= j_const
.cbegin());
1227 CHECK(it
== j_const
.cend());
1230 CHECK(it
== j_const
.cbegin());
1231 CHECK(it
!= j_const
.cend());
1232 CHECK(*it
== j_const
);
1235 CHECK(it
!= j_const
.cbegin());
1236 CHECK(it
== j_const
.cend());
1239 CHECK(it
== j_const
.cbegin());
1240 CHECK(it
!= j_const
.cend());
1241 CHECK(*it
== j_const
);
1244 SECTION("json + rbegin/rend")
1246 json::reverse_iterator it
= j
.rbegin();
1247 CHECK(it
!= j
.rend());
1251 CHECK(it
!= j
.rbegin());
1252 CHECK(it
== j
.rend());
1255 CHECK(it
== j
.rbegin());
1256 CHECK(it
!= j
.rend());
1260 CHECK(it
!= j
.rbegin());
1261 CHECK(it
== j
.rend());
1264 CHECK(it
== j
.rbegin());
1265 CHECK(it
!= j
.rend());
1269 SECTION("json + crbegin/crend")
1271 json::const_reverse_iterator it
= j
.crbegin();
1272 CHECK(it
!= j
.crend());
1276 CHECK(it
!= j
.crbegin());
1277 CHECK(it
== j
.crend());
1280 CHECK(it
== j
.crbegin());
1281 CHECK(it
!= j
.crend());
1285 CHECK(it
!= j
.crbegin());
1286 CHECK(it
== j
.crend());
1289 CHECK(it
== j
.crbegin());
1290 CHECK(it
!= j
.crend());
1294 SECTION("const json + crbegin/crend")
1296 json::const_reverse_iterator it
= j_const
.crbegin();
1297 CHECK(it
!= j_const
.crend());
1298 CHECK(*it
== j_const
);
1301 CHECK(it
!= j_const
.crbegin());
1302 CHECK(it
== j_const
.crend());
1305 CHECK(it
== j_const
.crbegin());
1306 CHECK(it
!= j_const
.crend());
1307 CHECK(*it
== j_const
);
1310 CHECK(it
!= j_const
.crbegin());
1311 CHECK(it
== j_const
.crend());
1314 CHECK(it
== j_const
.crbegin());
1315 CHECK(it
!= j_const
.crend());
1316 CHECK(*it
== j_const
);
1319 SECTION("key/value")
1321 auto it
= j
.begin();
1322 auto cit
= j_const
.cbegin();
1323 CHECK_THROWS_AS(it
.key(), json::invalid_iterator
&);
1324 CHECK_THROWS_WITH(it
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1325 CHECK(it
.value() == json(23));
1326 CHECK_THROWS_AS(cit
.key(), json::invalid_iterator
&);
1327 CHECK_THROWS_WITH(cit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1328 CHECK(cit
.value() == json(23));
1330 auto rit
= j
.rend();
1331 auto crit
= j
.crend();
1332 CHECK_THROWS_AS(rit
.key(), json::invalid_iterator
&);
1333 CHECK_THROWS_AS(rit
.value(), json::invalid_iterator
&);
1334 CHECK_THROWS_AS(crit
.key(), json::invalid_iterator
&);
1335 CHECK_THROWS_AS(crit
.value(), json::invalid_iterator
&);
1336 CHECK_THROWS_WITH(rit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1337 CHECK_THROWS_WITH(rit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1338 CHECK_THROWS_WITH(crit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1339 CHECK_THROWS_WITH(crit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1343 SECTION("number (float)")
1348 SECTION("json + begin/end")
1350 json::iterator it
= j
.begin();
1351 CHECK(it
!= j
.end());
1355 CHECK(it
!= j
.begin());
1356 CHECK(it
== j
.end());
1359 CHECK(it
== j
.begin());
1360 CHECK(it
!= j
.end());
1364 CHECK(it
!= j
.begin());
1365 CHECK(it
== j
.end());
1368 CHECK(it
== j
.begin());
1369 CHECK(it
!= j
.end());
1373 SECTION("const json + begin/end")
1375 json::const_iterator it
= j_const
.begin();
1376 CHECK(it
!= j_const
.end());
1377 CHECK(*it
== j_const
);
1380 CHECK(it
!= j_const
.begin());
1381 CHECK(it
== j_const
.end());
1384 CHECK(it
== j_const
.begin());
1385 CHECK(it
!= j_const
.end());
1386 CHECK(*it
== j_const
);
1389 CHECK(it
!= j_const
.begin());
1390 CHECK(it
== j_const
.end());
1393 CHECK(it
== j_const
.begin());
1394 CHECK(it
!= j_const
.end());
1395 CHECK(*it
== j_const
);
1398 SECTION("json + cbegin/cend")
1400 json::const_iterator it
= j
.cbegin();
1401 CHECK(it
!= j
.cend());
1405 CHECK(it
!= j
.cbegin());
1406 CHECK(it
== j
.cend());
1409 CHECK(it
== j
.cbegin());
1410 CHECK(it
!= j
.cend());
1414 CHECK(it
!= j
.cbegin());
1415 CHECK(it
== j
.cend());
1418 CHECK(it
== j
.cbegin());
1419 CHECK(it
!= j
.cend());
1423 SECTION("const json + cbegin/cend")
1425 json::const_iterator it
= j_const
.cbegin();
1426 CHECK(it
!= j_const
.cend());
1427 CHECK(*it
== j_const
);
1430 CHECK(it
!= j_const
.cbegin());
1431 CHECK(it
== j_const
.cend());
1434 CHECK(it
== j_const
.cbegin());
1435 CHECK(it
!= j_const
.cend());
1436 CHECK(*it
== j_const
);
1439 CHECK(it
!= j_const
.cbegin());
1440 CHECK(it
== j_const
.cend());
1443 CHECK(it
== j_const
.cbegin());
1444 CHECK(it
!= j_const
.cend());
1445 CHECK(*it
== j_const
);
1448 SECTION("json + rbegin/rend")
1450 json::reverse_iterator it
= j
.rbegin();
1451 CHECK(it
!= j
.rend());
1455 CHECK(it
!= j
.rbegin());
1456 CHECK(it
== j
.rend());
1459 CHECK(it
== j
.rbegin());
1460 CHECK(it
!= j
.rend());
1464 CHECK(it
!= j
.rbegin());
1465 CHECK(it
== j
.rend());
1468 CHECK(it
== j
.rbegin());
1469 CHECK(it
!= j
.rend());
1473 SECTION("json + crbegin/crend")
1475 json::const_reverse_iterator it
= j
.crbegin();
1476 CHECK(it
!= j
.crend());
1480 CHECK(it
!= j
.crbegin());
1481 CHECK(it
== j
.crend());
1484 CHECK(it
== j
.crbegin());
1485 CHECK(it
!= j
.crend());
1489 CHECK(it
!= j
.crbegin());
1490 CHECK(it
== j
.crend());
1493 CHECK(it
== j
.crbegin());
1494 CHECK(it
!= j
.crend());
1498 SECTION("const json + crbegin/crend")
1500 json::const_reverse_iterator it
= j_const
.crbegin();
1501 CHECK(it
!= j_const
.crend());
1502 CHECK(*it
== j_const
);
1505 CHECK(it
!= j_const
.crbegin());
1506 CHECK(it
== j_const
.crend());
1509 CHECK(it
== j_const
.crbegin());
1510 CHECK(it
!= j_const
.crend());
1511 CHECK(*it
== j_const
);
1514 CHECK(it
!= j_const
.crbegin());
1515 CHECK(it
== j_const
.crend());
1518 CHECK(it
== j_const
.crbegin());
1519 CHECK(it
!= j_const
.crend());
1520 CHECK(*it
== j_const
);
1523 SECTION("key/value")
1525 auto it
= j
.begin();
1526 auto cit
= j_const
.cbegin();
1527 CHECK_THROWS_AS(it
.key(), json::invalid_iterator
&);
1528 CHECK_THROWS_WITH(it
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1529 CHECK(it
.value() == json(23.42));
1530 CHECK_THROWS_AS(cit
.key(), json::invalid_iterator
&);
1531 CHECK_THROWS_WITH(cit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1532 CHECK(cit
.value() == json(23.42));
1534 auto rit
= j
.rend();
1535 auto crit
= j
.crend();
1536 CHECK_THROWS_AS(rit
.key(), json::invalid_iterator
&);
1537 CHECK_THROWS_AS(rit
.value(), json::invalid_iterator
&);
1538 CHECK_THROWS_AS(crit
.key(), json::invalid_iterator
&);
1539 CHECK_THROWS_AS(crit
.value(), json::invalid_iterator
&);
1540 CHECK_THROWS_WITH(rit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1541 CHECK_THROWS_WITH(rit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1542 CHECK_THROWS_WITH(crit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1543 CHECK_THROWS_WITH(crit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1552 SECTION("json + begin/end")
1554 json::iterator it
= j
.begin();
1555 CHECK(it
== j
.end());
1558 SECTION("const json + begin/end")
1560 json::const_iterator it_begin
= j_const
.begin();
1561 json::const_iterator it_end
= j_const
.end();
1562 CHECK(it_begin
== it_end
);
1565 SECTION("json + cbegin/cend")
1567 json::const_iterator it_begin
= j
.cbegin();
1568 json::const_iterator it_end
= j
.cend();
1569 CHECK(it_begin
== it_end
);
1572 SECTION("const json + cbegin/cend")
1574 json::const_iterator it_begin
= j_const
.cbegin();
1575 json::const_iterator it_end
= j_const
.cend();
1576 CHECK(it_begin
== it_end
);
1579 SECTION("json + rbegin/rend")
1581 json::reverse_iterator it
= j
.rbegin();
1582 CHECK(it
== j
.rend());
1585 SECTION("json + crbegin/crend")
1587 json::const_reverse_iterator it
= j
.crbegin();
1588 CHECK(it
== j
.crend());
1591 SECTION("const json + crbegin/crend")
1593 json::const_reverse_iterator it
= j_const
.crbegin();
1594 CHECK(it
== j_const
.crend());
1597 SECTION("key/value")
1599 auto it
= j
.begin();
1600 auto cit
= j_const
.cbegin();
1601 CHECK_THROWS_AS(it
.key(), json::invalid_iterator
&);
1602 CHECK_THROWS_AS(it
.value(), json::invalid_iterator
&);
1603 CHECK_THROWS_AS(cit
.key(), json::invalid_iterator
&);
1604 CHECK_THROWS_AS(cit
.value(), json::invalid_iterator
&);
1605 CHECK_THROWS_WITH(it
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1606 CHECK_THROWS_WITH(it
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1607 CHECK_THROWS_WITH(cit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1608 CHECK_THROWS_WITH(cit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1610 auto rit
= j
.rend();
1611 auto crit
= j
.crend();
1612 CHECK_THROWS_AS(rit
.key(), json::invalid_iterator
&);
1613 CHECK_THROWS_AS(rit
.value(), json::invalid_iterator
&);
1614 CHECK_THROWS_AS(crit
.key(), json::invalid_iterator
&);
1615 CHECK_THROWS_AS(crit
.value(), json::invalid_iterator
&);
1616 CHECK_THROWS_WITH(rit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1617 CHECK_THROWS_WITH(rit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1618 CHECK_THROWS_WITH(crit
.key(), "[json.exception.invalid_iterator.207] cannot use key() for non-object iterators");
1619 CHECK_THROWS_WITH(crit
.value(), "[json.exception.invalid_iterator.214] cannot get value");
1624 SECTION("conversion from iterator to const iterator")
1629 json::const_iterator it
= j
.begin();
1630 CHECK(it
== j
.cbegin());
1632 CHECK(it
== j
.cbegin());
1636 json j
= "hello world";
1637 json::const_iterator it
= j
.begin();
1638 CHECK(it
== j
.cbegin());
1640 CHECK(it
== j
.cbegin());
1645 json::const_iterator it
= j
.begin();
1646 CHECK(it
== j
.cbegin());
1648 CHECK(it
== j
.cbegin());
1652 json j
= {{"A", 1}, {"B", 2}, {"C", 3}};
1653 json::const_iterator it
= j
.begin();
1654 CHECK(it
== j
.cbegin());
1656 CHECK(it
== j
.cbegin());
1658 SECTION("number (integer)")
1661 json::const_iterator it
= j
.begin();
1662 CHECK(it
== j
.cbegin());
1664 CHECK(it
== j
.cbegin());
1666 SECTION("number (unsigned)")
1669 json::const_iterator it
= j
.begin();
1670 CHECK(it
== j
.cbegin());
1672 CHECK(it
== j
.cbegin());
1674 SECTION("number (float)")
1677 json::const_iterator it
= j
.begin();
1678 CHECK(it
== j
.cbegin());
1680 CHECK(it
== j
.cbegin());
1685 json::const_iterator it
= j
.begin();
1686 CHECK(it
== j
.cbegin());
1688 CHECK(it
== j
.cbegin());