• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     __ _____ _____ _____
3  __|  |   __|     |   | |  JSON for Modern C++ (test suite)
4 |  |  |__   |  |  | | | |  version 3.10.0
5 |_____|_____|_____|_|___|  https://github.com/nlohmann/json
6 
7 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
8 SPDX-License-Identifier: MIT
9 Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
10 
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:
17 
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
20 
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
27 SOFTWARE.
28 */
29 
30 #include "doctest_compatibility.h"
31 
32 #define JSON_TESTS_PRIVATE
33 #include <nlohmann/json.hpp>
34 using nlohmann::json;
35 
36 TEST_CASE("iterators 1")
37 {
38     SECTION("basic behavior")
39     {
40         SECTION("uninitialized")
41         {
42             json::iterator it;
43             CHECK(it.m_object == nullptr);
44 
45             json::const_iterator cit;
46             CHECK(cit.m_object == nullptr);
47         }
48 
49         SECTION("boolean")
50         {
51             json j = true;
52             json j_const(j);
53 
54             SECTION("json + begin/end")
55             {
56                 json::iterator it = j.begin();
57                 CHECK(it != j.end());
58                 CHECK(*it == j);
59 
60                 it++;
61                 CHECK(it != j.begin());
62                 CHECK(it == j.end());
63 
64                 it--;
65                 CHECK(it == j.begin());
66                 CHECK(it != j.end());
67                 CHECK(*it == j);
68 
69                 ++it;
70                 CHECK(it != j.begin());
71                 CHECK(it == j.end());
72 
73                 --it;
74                 CHECK(it == j.begin());
75                 CHECK(it != j.end());
76                 CHECK(*it == j);
77             }
78 
79             SECTION("const json + begin/end")
80             {
81                 json::const_iterator it = j_const.begin();
82                 CHECK(it != j_const.end());
83                 CHECK(*it == j_const);
84 
85                 it++;
86                 CHECK(it != j_const.begin());
87                 CHECK(it == j_const.end());
88 
89                 it--;
90                 CHECK(it == j_const.begin());
91                 CHECK(it != j_const.end());
92                 CHECK(*it == j_const);
93 
94                 ++it;
95                 CHECK(it != j_const.begin());
96                 CHECK(it == j_const.end());
97 
98                 --it;
99                 CHECK(it == j_const.begin());
100                 CHECK(it != j_const.end());
101                 CHECK(*it == j_const);
102             }
103 
104             SECTION("json + cbegin/cend")
105             {
106                 json::const_iterator it = j.cbegin();
107                 CHECK(it != j.cend());
108                 CHECK(*it == j);
109 
110                 it++;
111                 CHECK(it != j.cbegin());
112                 CHECK(it == j.cend());
113 
114                 it--;
115                 CHECK(it == j.cbegin());
116                 CHECK(it != j.cend());
117                 CHECK(*it == j);
118 
119                 ++it;
120                 CHECK(it != j.cbegin());
121                 CHECK(it == j.cend());
122 
123                 --it;
124                 CHECK(it == j.cbegin());
125                 CHECK(it != j.cend());
126                 CHECK(*it == j);
127             }
128 
129             SECTION("const json + cbegin/cend")
130             {
131                 json::const_iterator it = j_const.cbegin();
132                 CHECK(it != j_const.cend());
133                 CHECK(*it == j_const);
134 
135                 it++;
136                 CHECK(it != j_const.cbegin());
137                 CHECK(it == j_const.cend());
138 
139                 it--;
140                 CHECK(it == j_const.cbegin());
141                 CHECK(it != j_const.cend());
142                 CHECK(*it == j_const);
143 
144                 ++it;
145                 CHECK(it != j_const.cbegin());
146                 CHECK(it == j_const.cend());
147 
148                 --it;
149                 CHECK(it == j_const.cbegin());
150                 CHECK(it != j_const.cend());
151                 CHECK(*it == j_const);
152             }
153 
154             SECTION("json + rbegin/rend")
155             {
156                 json::reverse_iterator it = j.rbegin();
157                 CHECK(it != j.rend());
158                 CHECK(*it == j);
159 
160                 it++;
161                 CHECK(it != j.rbegin());
162                 CHECK(it == j.rend());
163 
164                 it--;
165                 CHECK(it == j.rbegin());
166                 CHECK(it != j.rend());
167                 CHECK(*it == j);
168 
169                 ++it;
170                 CHECK(it != j.rbegin());
171                 CHECK(it == j.rend());
172 
173                 --it;
174                 CHECK(it == j.rbegin());
175                 CHECK(it != j.rend());
176                 CHECK(*it == j);
177             }
178 
179             SECTION("json + crbegin/crend")
180             {
181                 json::const_reverse_iterator it = j.crbegin();
182                 CHECK(it != j.crend());
183                 CHECK(*it == j);
184 
185                 it++;
186                 CHECK(it != j.crbegin());
187                 CHECK(it == j.crend());
188 
189                 it--;
190                 CHECK(it == j.crbegin());
191                 CHECK(it != j.crend());
192                 CHECK(*it == j);
193 
194                 ++it;
195                 CHECK(it != j.crbegin());
196                 CHECK(it == j.crend());
197 
198                 --it;
199                 CHECK(it == j.crbegin());
200                 CHECK(it != j.crend());
201                 CHECK(*it == j);
202             }
203 
204             SECTION("const json + crbegin/crend")
205             {
206                 json::const_reverse_iterator it = j_const.crbegin();
207                 CHECK(it != j_const.crend());
208                 CHECK(*it == j_const);
209 
210                 it++;
211                 CHECK(it != j_const.crbegin());
212                 CHECK(it == j_const.crend());
213 
214                 it--;
215                 CHECK(it == j_const.crbegin());
216                 CHECK(it != j_const.crend());
217                 CHECK(*it == j_const);
218 
219                 ++it;
220                 CHECK(it != j_const.crbegin());
221                 CHECK(it == j_const.crend());
222 
223                 --it;
224                 CHECK(it == j_const.crbegin());
225                 CHECK(it != j_const.crend());
226                 CHECK(*it == j_const);
227             }
228 
229             SECTION("additional tests")
230             {
231                 SECTION("!(begin != begin)")
232                 {
233                     CHECK(!(j.begin() != j.begin()));
234                 }
235 
236                 SECTION("!(end != end)")
237                 {
238                     CHECK(!(j.end() != j.end()));
239                 }
240 
241                 SECTION("begin < end")
242                 {
243                     CHECK(j.begin() < j.end());
244                 }
245 
246                 SECTION("begin <= end")
247                 {
248                     CHECK(j.begin() <= j.end());
249                 }
250 
251                 SECTION("end > begin")
252                 {
253                     CHECK(j.end() > j.begin());
254                 }
255 
256                 SECTION("end >= begin")
257                 {
258                     CHECK(j.end() >= j.begin());
259                 }
260 
261                 SECTION("end == end")
262                 {
263                     CHECK(j.end() == j.end());
264                 }
265 
266                 SECTION("end <= end")
267                 {
268                     CHECK(j.end() <= j.end());
269                 }
270 
271                 SECTION("begin == begin")
272                 {
273                     CHECK(j.begin() == j.begin());
274                 }
275 
276                 SECTION("begin <= begin")
277                 {
278                     CHECK(j.begin() <= j.begin());
279                 }
280 
281                 SECTION("begin >= begin")
282                 {
283                     CHECK(j.begin() >= j.begin());
284                 }
285 
286                 SECTION("!(begin == end)")
287                 {
288                     CHECK(!(j.begin() == j.end()));
289                 }
290 
291                 SECTION("begin != end")
292                 {
293                     CHECK(j.begin() != j.end());
294                 }
295 
296                 SECTION("begin+1 == end")
297                 {
298                     CHECK(j.begin() + 1 == j.end());
299                 }
300 
301                 SECTION("begin == end-1")
302                 {
303                     CHECK(j.begin() == j.end() - 1);
304                 }
305 
306                 SECTION("begin != end+1")
307                 {
308                     CHECK(j.begin() != j.end() + 1);
309                 }
310 
311                 SECTION("end != end+1")
312                 {
313                     CHECK(j.end() != j.end() + 1);
314                 }
315 
316                 SECTION("begin+1 != begin+2")
317                 {
318                     CHECK(j.begin() + 1 != j.begin() + 2);
319                 }
320 
321                 SECTION("begin+1 < begin+2")
322                 {
323                     CHECK(j.begin() + 1 < j.begin() + 2);
324                 }
325 
326                 SECTION("begin+1 <= begin+2")
327                 {
328                     CHECK(j.begin() + 1 <= j.begin() + 2);
329                 }
330 
331                 SECTION("end+1 != end+2")
332                 {
333                     CHECK(j.end() + 1 != j.end() + 2);
334                 }
335             }
336 
337             SECTION("key/value")
338             {
339                 auto it = j.begin();
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));
347 
348                 auto rit = j.rend();
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");
358             }
359         }
360 
361         SECTION("string")
362         {
363             json j = "hello world";
364             json j_const(j);
365 
366             SECTION("json + begin/end")
367             {
368                 json::iterator it = j.begin();
369                 CHECK(it != j.end());
370                 CHECK(*it == j);
371 
372                 it++;
373                 CHECK(it != j.begin());
374                 CHECK(it == j.end());
375 
376                 it--;
377                 CHECK(it == j.begin());
378                 CHECK(it != j.end());
379                 CHECK(*it == j);
380 
381                 ++it;
382                 CHECK(it != j.begin());
383                 CHECK(it == j.end());
384 
385                 --it;
386                 CHECK(it == j.begin());
387                 CHECK(it != j.end());
388                 CHECK(*it == j);
389             }
390 
391             SECTION("const json + begin/end")
392             {
393                 json::const_iterator it = j_const.begin();
394                 CHECK(it != j_const.end());
395                 CHECK(*it == j_const);
396 
397                 it++;
398                 CHECK(it != j_const.begin());
399                 CHECK(it == j_const.end());
400 
401                 it--;
402                 CHECK(it == j_const.begin());
403                 CHECK(it != j_const.end());
404                 CHECK(*it == j_const);
405 
406                 ++it;
407                 CHECK(it != j_const.begin());
408                 CHECK(it == j_const.end());
409 
410                 --it;
411                 CHECK(it == j_const.begin());
412                 CHECK(it != j_const.end());
413                 CHECK(*it == j_const);
414             }
415 
416             SECTION("json + cbegin/cend")
417             {
418                 json::const_iterator it = j.cbegin();
419                 CHECK(it != j.cend());
420                 CHECK(*it == j);
421 
422                 it++;
423                 CHECK(it != j.cbegin());
424                 CHECK(it == j.cend());
425 
426                 it--;
427                 CHECK(it == j.cbegin());
428                 CHECK(it != j.cend());
429                 CHECK(*it == j);
430 
431                 ++it;
432                 CHECK(it != j.cbegin());
433                 CHECK(it == j.cend());
434 
435                 --it;
436                 CHECK(it == j.cbegin());
437                 CHECK(it != j.cend());
438                 CHECK(*it == j);
439             }
440 
441             SECTION("const json + cbegin/cend")
442             {
443                 json::const_iterator it = j_const.cbegin();
444                 CHECK(it != j_const.cend());
445                 CHECK(*it == j_const);
446 
447                 it++;
448                 CHECK(it != j_const.cbegin());
449                 CHECK(it == j_const.cend());
450 
451                 it--;
452                 CHECK(it == j_const.cbegin());
453                 CHECK(it != j_const.cend());
454                 CHECK(*it == j_const);
455 
456                 ++it;
457                 CHECK(it != j_const.cbegin());
458                 CHECK(it == j_const.cend());
459 
460                 --it;
461                 CHECK(it == j_const.cbegin());
462                 CHECK(it != j_const.cend());
463                 CHECK(*it == j_const);
464             }
465 
466             SECTION("json + rbegin/rend")
467             {
468                 json::reverse_iterator it = j.rbegin();
469                 CHECK(it != j.rend());
470                 CHECK(*it == j);
471 
472                 it++;
473                 CHECK(it != j.rbegin());
474                 CHECK(it == j.rend());
475 
476                 it--;
477                 CHECK(it == j.rbegin());
478                 CHECK(it != j.rend());
479                 CHECK(*it == j);
480 
481                 ++it;
482                 CHECK(it != j.rbegin());
483                 CHECK(it == j.rend());
484 
485                 --it;
486                 CHECK(it == j.rbegin());
487                 CHECK(it != j.rend());
488                 CHECK(*it == j);
489             }
490 
491             SECTION("json + crbegin/crend")
492             {
493                 json::const_reverse_iterator it = j.crbegin();
494                 CHECK(it != j.crend());
495                 CHECK(*it == j);
496 
497                 it++;
498                 CHECK(it != j.crbegin());
499                 CHECK(it == j.crend());
500 
501                 it--;
502                 CHECK(it == j.crbegin());
503                 CHECK(it != j.crend());
504                 CHECK(*it == j);
505 
506                 ++it;
507                 CHECK(it != j.crbegin());
508                 CHECK(it == j.crend());
509 
510                 --it;
511                 CHECK(it == j.crbegin());
512                 CHECK(it != j.crend());
513                 CHECK(*it == j);
514             }
515 
516             SECTION("const json + crbegin/crend")
517             {
518                 json::const_reverse_iterator it = j_const.crbegin();
519                 CHECK(it != j_const.crend());
520                 CHECK(*it == j_const);
521 
522                 it++;
523                 CHECK(it != j_const.crbegin());
524                 CHECK(it == j_const.crend());
525 
526                 it--;
527                 CHECK(it == j_const.crbegin());
528                 CHECK(it != j_const.crend());
529                 CHECK(*it == j_const);
530 
531                 ++it;
532                 CHECK(it != j_const.crbegin());
533                 CHECK(it == j_const.crend());
534 
535                 --it;
536                 CHECK(it == j_const.crbegin());
537                 CHECK(it != j_const.crend());
538                 CHECK(*it == j_const);
539             }
540 
541             SECTION("key/value")
542             {
543                 auto it = j.begin();
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"));
551 
552                 auto rit = j.rend();
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");
562             }
563         }
564 
565         SECTION("array")
566         {
567             json j = {1, 2, 3};
568             json j_const(j);
569 
570             SECTION("json + begin/end")
571             {
572                 json::iterator it_begin = j.begin();
573                 json::iterator it_end = j.end();
574 
575                 auto it = it_begin;
576                 CHECK(it != it_end);
577                 CHECK(*it == j[0]);
578 
579                 it++;
580                 CHECK(it != it_begin);
581                 CHECK(it != it_end);
582                 CHECK(*it == j[1]);
583 
584                 ++it;
585                 CHECK(it != it_begin);
586                 CHECK(it != it_end);
587                 CHECK(*it == j[2]);
588 
589                 ++it;
590                 CHECK(it != it_begin);
591                 CHECK(it == it_end);
592             }
593 
594             SECTION("const json + begin/end")
595             {
596                 json::const_iterator it_begin = j_const.begin();
597                 json::const_iterator it_end = j_const.end();
598 
599                 auto it = it_begin;
600                 CHECK(it != it_end);
601                 CHECK(*it == j_const[0]);
602 
603                 it++;
604                 CHECK(it != it_begin);
605                 CHECK(it != it_end);
606                 CHECK(*it == j_const[1]);
607 
608                 ++it;
609                 CHECK(it != it_begin);
610                 CHECK(it != it_end);
611                 CHECK(*it == j_const[2]);
612 
613                 ++it;
614                 CHECK(it != it_begin);
615                 CHECK(it == it_end);
616             }
617 
618             SECTION("json + cbegin/cend")
619             {
620                 json::const_iterator it_begin = j.cbegin();
621                 json::const_iterator it_end = j.cend();
622 
623                 auto it = it_begin;
624                 CHECK(it != it_end);
625                 CHECK(*it == j[0]);
626 
627                 it++;
628                 CHECK(it != it_begin);
629                 CHECK(it != it_end);
630                 CHECK(*it == j[1]);
631 
632                 ++it;
633                 CHECK(it != it_begin);
634                 CHECK(it != it_end);
635                 CHECK(*it == j[2]);
636 
637                 ++it;
638                 CHECK(it != it_begin);
639                 CHECK(it == it_end);
640             }
641 
642             SECTION("const json + cbegin/cend")
643             {
644                 json::const_iterator it_begin = j_const.cbegin();
645                 json::const_iterator it_end = j_const.cend();
646 
647                 auto it = it_begin;
648                 CHECK(it != it_end);
649                 CHECK(*it == j[0]);
650 
651                 it++;
652                 CHECK(it != it_begin);
653                 CHECK(it != it_end);
654                 CHECK(*it == j[1]);
655 
656                 ++it;
657                 CHECK(it != it_begin);
658                 CHECK(it != it_end);
659                 CHECK(*it == j[2]);
660 
661                 ++it;
662                 CHECK(it != it_begin);
663                 CHECK(it == it_end);
664             }
665 
666             SECTION("json + rbegin/rend")
667             {
668                 json::reverse_iterator it_begin = j.rbegin();
669                 json::reverse_iterator it_end = j.rend();
670 
671                 auto it = it_begin;
672                 CHECK(it != it_end);
673                 CHECK(*it == j[2]);
674 
675                 it++;
676                 CHECK(it != it_begin);
677                 CHECK(it != it_end);
678                 CHECK(*it == j[1]);
679 
680                 ++it;
681                 CHECK(it != it_begin);
682                 CHECK(it != it_end);
683                 CHECK(*it == j[0]);
684 
685                 ++it;
686                 CHECK(it != it_begin);
687                 CHECK(it == it_end);
688             }
689 
690             SECTION("json + crbegin/crend")
691             {
692                 json::const_reverse_iterator it_begin = j.crbegin();
693                 json::const_reverse_iterator it_end = j.crend();
694 
695                 auto it = it_begin;
696                 CHECK(it != it_end);
697                 CHECK(*it == j[2]);
698 
699                 it++;
700                 CHECK(it != it_begin);
701                 CHECK(it != it_end);
702                 CHECK(*it == j[1]);
703 
704                 ++it;
705                 CHECK(it != it_begin);
706                 CHECK(it != it_end);
707                 CHECK(*it == j[0]);
708 
709                 ++it;
710                 CHECK(it != it_begin);
711                 CHECK(it == it_end);
712             }
713 
714             SECTION("const json + crbegin/crend")
715             {
716                 json::const_reverse_iterator it_begin = j_const.crbegin();
717                 json::const_reverse_iterator it_end = j_const.crend();
718 
719                 auto it = it_begin;
720                 CHECK(it != it_end);
721                 CHECK(*it == j[2]);
722 
723                 it++;
724                 CHECK(it != it_begin);
725                 CHECK(it != it_end);
726                 CHECK(*it == j[1]);
727 
728                 ++it;
729                 CHECK(it != it_begin);
730                 CHECK(it != it_end);
731                 CHECK(*it == j[0]);
732 
733                 ++it;
734                 CHECK(it != it_begin);
735                 CHECK(it == it_end);
736             }
737 
738             SECTION("key/value")
739             {
740                 auto it = j.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));
748             }
749         }
750 
751         SECTION("object")
752         {
753             json j = {{"A", 1}, {"B", 2}, {"C", 3}};
754             json j_const(j);
755 
756             SECTION("json + begin/end")
757             {
758                 json::iterator it_begin = j.begin();
759                 json::iterator it_end = j.end();
760 
761                 auto it = it_begin;
762                 CHECK(it != it_end);
763                 CHECK(*it == j["A"]);
764 
765                 it++;
766                 CHECK(it != it_begin);
767                 CHECK(it != it_end);
768                 CHECK(*it == j["B"]);
769 
770                 ++it;
771                 CHECK(it != it_begin);
772                 CHECK(it != it_end);
773                 CHECK(*it == j["C"]);
774 
775                 ++it;
776                 CHECK(it != it_begin);
777                 CHECK(it == it_end);
778             }
779 
780             SECTION("const json + begin/end")
781             {
782                 json::const_iterator it_begin = j_const.begin();
783                 json::const_iterator it_end = j_const.end();
784 
785                 auto it = it_begin;
786                 CHECK(it != it_end);
787                 CHECK(*it == j_const["A"]);
788 
789                 it++;
790                 CHECK(it != it_begin);
791                 CHECK(it != it_end);
792                 CHECK(*it == j_const["B"]);
793 
794                 ++it;
795                 CHECK(it != it_begin);
796                 CHECK(it != it_end);
797                 CHECK(*it == j_const["C"]);
798 
799                 ++it;
800                 CHECK(it != it_begin);
801                 CHECK(it == it_end);
802             }
803 
804             SECTION("json + cbegin/cend")
805             {
806                 json::const_iterator it_begin = j.cbegin();
807                 json::const_iterator it_end = j.cend();
808 
809                 auto it = it_begin;
810                 CHECK(it != it_end);
811                 CHECK(*it == j["A"]);
812 
813                 it++;
814                 CHECK(it != it_begin);
815                 CHECK(it != it_end);
816                 CHECK(*it == j["B"]);
817 
818                 ++it;
819                 CHECK(it != it_begin);
820                 CHECK(it != it_end);
821                 CHECK(*it == j["C"]);
822 
823                 ++it;
824                 CHECK(it != it_begin);
825                 CHECK(it == it_end);
826             }
827 
828             SECTION("const json + cbegin/cend")
829             {
830                 json::const_iterator it_begin = j_const.cbegin();
831                 json::const_iterator it_end = j_const.cend();
832 
833                 auto it = it_begin;
834                 CHECK(it != it_end);
835                 CHECK(*it == j_const["A"]);
836 
837                 it++;
838                 CHECK(it != it_begin);
839                 CHECK(it != it_end);
840                 CHECK(*it == j_const["B"]);
841 
842                 ++it;
843                 CHECK(it != it_begin);
844                 CHECK(it != it_end);
845                 CHECK(*it == j_const["C"]);
846 
847                 ++it;
848                 CHECK(it != it_begin);
849                 CHECK(it == it_end);
850             }
851 
852             SECTION("json + rbegin/rend")
853             {
854                 json::reverse_iterator it_begin = j.rbegin();
855                 json::reverse_iterator it_end = j.rend();
856 
857                 auto it = it_begin;
858                 CHECK(it != it_end);
859                 CHECK(*it == j["C"]);
860 
861                 it++;
862                 CHECK(it != it_begin);
863                 CHECK(it != it_end);
864                 CHECK(*it == j["B"]);
865 
866                 ++it;
867                 CHECK(it != it_begin);
868                 CHECK(it != it_end);
869                 CHECK(*it == j["A"]);
870 
871                 ++it;
872                 CHECK(it != it_begin);
873                 CHECK(it == it_end);
874             }
875 
876             SECTION("json + crbegin/crend")
877             {
878                 json::const_reverse_iterator it_begin = j.crbegin();
879                 json::const_reverse_iterator it_end = j.crend();
880 
881                 auto it = it_begin;
882                 CHECK(it != it_end);
883                 CHECK(*it == j["C"]);
884 
885                 it++;
886                 CHECK(it != it_begin);
887                 CHECK(it != it_end);
888                 CHECK(*it == j["B"]);
889 
890                 ++it;
891                 CHECK(it != it_begin);
892                 CHECK(it != it_end);
893                 CHECK(*it == j["A"]);
894 
895                 ++it;
896                 CHECK(it != it_begin);
897                 CHECK(it == it_end);
898             }
899 
900             SECTION("const json + crbegin/crend")
901             {
902                 json::const_reverse_iterator it_begin = j_const.crbegin();
903                 json::const_reverse_iterator it_end = j_const.crend();
904 
905                 auto it = it_begin;
906                 CHECK(it != it_end);
907                 CHECK(*it == j["C"]);
908 
909                 it++;
910                 CHECK(it != it_begin);
911                 CHECK(it != it_end);
912                 CHECK(*it == j["B"]);
913 
914                 ++it;
915                 CHECK(it != it_begin);
916                 CHECK(it != it_end);
917                 CHECK(*it == j["A"]);
918 
919                 ++it;
920                 CHECK(it != it_begin);
921                 CHECK(it == it_end);
922             }
923 
924             SECTION("key/value")
925             {
926                 auto it = j.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));
932             }
933         }
934 
935         SECTION("number (integer)")
936         {
937             json j = 23;
938             json j_const(j);
939 
940             SECTION("json + begin/end")
941             {
942                 json::iterator it = j.begin();
943                 CHECK(it != j.end());
944                 CHECK(*it == j);
945 
946                 it++;
947                 CHECK(it != j.begin());
948                 CHECK(it == j.end());
949 
950                 it--;
951                 CHECK(it == j.begin());
952                 CHECK(it != j.end());
953                 CHECK(*it == j);
954 
955                 ++it;
956                 CHECK(it != j.begin());
957                 CHECK(it == j.end());
958 
959                 --it;
960                 CHECK(it == j.begin());
961                 CHECK(it != j.end());
962                 CHECK(*it == j);
963             }
964 
965             SECTION("const json + begin/end")
966             {
967                 json::const_iterator it = j_const.begin();
968                 CHECK(it != j_const.end());
969                 CHECK(*it == j_const);
970 
971                 it++;
972                 CHECK(it != j_const.begin());
973                 CHECK(it == j_const.end());
974 
975                 it--;
976                 CHECK(it == j_const.begin());
977                 CHECK(it != j_const.end());
978                 CHECK(*it == j_const);
979 
980                 ++it;
981                 CHECK(it != j_const.begin());
982                 CHECK(it == j_const.end());
983 
984                 --it;
985                 CHECK(it == j_const.begin());
986                 CHECK(it != j_const.end());
987                 CHECK(*it == j_const);
988             }
989 
990             SECTION("json + cbegin/cend")
991             {
992                 json::const_iterator it = j.cbegin();
993                 CHECK(it != j.cend());
994                 CHECK(*it == j);
995 
996                 it++;
997                 CHECK(it != j.cbegin());
998                 CHECK(it == j.cend());
999 
1000                 it--;
1001                 CHECK(it == j.cbegin());
1002                 CHECK(it != j.cend());
1003                 CHECK(*it == j);
1004 
1005                 ++it;
1006                 CHECK(it != j.cbegin());
1007                 CHECK(it == j.cend());
1008 
1009                 --it;
1010                 CHECK(it == j.cbegin());
1011                 CHECK(it != j.cend());
1012                 CHECK(*it == j);
1013             }
1014 
1015             SECTION("const json + cbegin/cend")
1016             {
1017                 json::const_iterator it = j_const.cbegin();
1018                 CHECK(it != j_const.cend());
1019                 CHECK(*it == j_const);
1020 
1021                 it++;
1022                 CHECK(it != j_const.cbegin());
1023                 CHECK(it == j_const.cend());
1024 
1025                 it--;
1026                 CHECK(it == j_const.cbegin());
1027                 CHECK(it != j_const.cend());
1028                 CHECK(*it == j_const);
1029 
1030                 ++it;
1031                 CHECK(it != j_const.cbegin());
1032                 CHECK(it == j_const.cend());
1033 
1034                 --it;
1035                 CHECK(it == j_const.cbegin());
1036                 CHECK(it != j_const.cend());
1037                 CHECK(*it == j_const);
1038             }
1039 
1040             SECTION("json + rbegin/rend")
1041             {
1042                 json::reverse_iterator it = j.rbegin();
1043                 CHECK(it != j.rend());
1044                 CHECK(*it == j);
1045 
1046                 it++;
1047                 CHECK(it != j.rbegin());
1048                 CHECK(it == j.rend());
1049 
1050                 it--;
1051                 CHECK(it == j.rbegin());
1052                 CHECK(it != j.rend());
1053                 CHECK(*it == j);
1054 
1055                 ++it;
1056                 CHECK(it != j.rbegin());
1057                 CHECK(it == j.rend());
1058 
1059                 --it;
1060                 CHECK(it == j.rbegin());
1061                 CHECK(it != j.rend());
1062                 CHECK(*it == j);
1063             }
1064 
1065             SECTION("json + crbegin/crend")
1066             {
1067                 json::const_reverse_iterator it = j.crbegin();
1068                 CHECK(it != j.crend());
1069                 CHECK(*it == j);
1070 
1071                 it++;
1072                 CHECK(it != j.crbegin());
1073                 CHECK(it == j.crend());
1074 
1075                 it--;
1076                 CHECK(it == j.crbegin());
1077                 CHECK(it != j.crend());
1078                 CHECK(*it == j);
1079 
1080                 ++it;
1081                 CHECK(it != j.crbegin());
1082                 CHECK(it == j.crend());
1083 
1084                 --it;
1085                 CHECK(it == j.crbegin());
1086                 CHECK(it != j.crend());
1087                 CHECK(*it == j);
1088             }
1089 
1090             SECTION("const json + crbegin/crend")
1091             {
1092                 json::const_reverse_iterator it = j_const.crbegin();
1093                 CHECK(it != j_const.crend());
1094                 CHECK(*it == j_const);
1095 
1096                 it++;
1097                 CHECK(it != j_const.crbegin());
1098                 CHECK(it == j_const.crend());
1099 
1100                 it--;
1101                 CHECK(it == j_const.crbegin());
1102                 CHECK(it != j_const.crend());
1103                 CHECK(*it == j_const);
1104 
1105                 ++it;
1106                 CHECK(it != j_const.crbegin());
1107                 CHECK(it == j_const.crend());
1108 
1109                 --it;
1110                 CHECK(it == j_const.crbegin());
1111                 CHECK(it != j_const.crend());
1112                 CHECK(*it == j_const);
1113             }
1114 
1115             SECTION("key/value")
1116             {
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));
1125 
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");
1136             }
1137         }
1138 
1139         SECTION("number (unsigned)")
1140         {
1141             json j = 23u;
1142             json j_const(j);
1143 
1144             SECTION("json + begin/end")
1145             {
1146                 json::iterator it = j.begin();
1147                 CHECK(it != j.end());
1148                 CHECK(*it == j);
1149 
1150                 it++;
1151                 CHECK(it != j.begin());
1152                 CHECK(it == j.end());
1153 
1154                 it--;
1155                 CHECK(it == j.begin());
1156                 CHECK(it != j.end());
1157                 CHECK(*it == j);
1158 
1159                 ++it;
1160                 CHECK(it != j.begin());
1161                 CHECK(it == j.end());
1162 
1163                 --it;
1164                 CHECK(it == j.begin());
1165                 CHECK(it != j.end());
1166                 CHECK(*it == j);
1167             }
1168 
1169             SECTION("const json + begin/end")
1170             {
1171                 json::const_iterator it = j_const.begin();
1172                 CHECK(it != j_const.end());
1173                 CHECK(*it == j_const);
1174 
1175                 it++;
1176                 CHECK(it != j_const.begin());
1177                 CHECK(it == j_const.end());
1178 
1179                 it--;
1180                 CHECK(it == j_const.begin());
1181                 CHECK(it != j_const.end());
1182                 CHECK(*it == j_const);
1183 
1184                 ++it;
1185                 CHECK(it != j_const.begin());
1186                 CHECK(it == j_const.end());
1187 
1188                 --it;
1189                 CHECK(it == j_const.begin());
1190                 CHECK(it != j_const.end());
1191                 CHECK(*it == j_const);
1192             }
1193 
1194             SECTION("json + cbegin/cend")
1195             {
1196                 json::const_iterator it = j.cbegin();
1197                 CHECK(it != j.cend());
1198                 CHECK(*it == j);
1199 
1200                 it++;
1201                 CHECK(it != j.cbegin());
1202                 CHECK(it == j.cend());
1203 
1204                 it--;
1205                 CHECK(it == j.cbegin());
1206                 CHECK(it != j.cend());
1207                 CHECK(*it == j);
1208 
1209                 ++it;
1210                 CHECK(it != j.cbegin());
1211                 CHECK(it == j.cend());
1212 
1213                 --it;
1214                 CHECK(it == j.cbegin());
1215                 CHECK(it != j.cend());
1216                 CHECK(*it == j);
1217             }
1218 
1219             SECTION("const json + cbegin/cend")
1220             {
1221                 json::const_iterator it = j_const.cbegin();
1222                 CHECK(it != j_const.cend());
1223                 CHECK(*it == j_const);
1224 
1225                 it++;
1226                 CHECK(it != j_const.cbegin());
1227                 CHECK(it == j_const.cend());
1228 
1229                 it--;
1230                 CHECK(it == j_const.cbegin());
1231                 CHECK(it != j_const.cend());
1232                 CHECK(*it == j_const);
1233 
1234                 ++it;
1235                 CHECK(it != j_const.cbegin());
1236                 CHECK(it == j_const.cend());
1237 
1238                 --it;
1239                 CHECK(it == j_const.cbegin());
1240                 CHECK(it != j_const.cend());
1241                 CHECK(*it == j_const);
1242             }
1243 
1244             SECTION("json + rbegin/rend")
1245             {
1246                 json::reverse_iterator it = j.rbegin();
1247                 CHECK(it != j.rend());
1248                 CHECK(*it == j);
1249 
1250                 it++;
1251                 CHECK(it != j.rbegin());
1252                 CHECK(it == j.rend());
1253 
1254                 it--;
1255                 CHECK(it == j.rbegin());
1256                 CHECK(it != j.rend());
1257                 CHECK(*it == j);
1258 
1259                 ++it;
1260                 CHECK(it != j.rbegin());
1261                 CHECK(it == j.rend());
1262 
1263                 --it;
1264                 CHECK(it == j.rbegin());
1265                 CHECK(it != j.rend());
1266                 CHECK(*it == j);
1267             }
1268 
1269             SECTION("json + crbegin/crend")
1270             {
1271                 json::const_reverse_iterator it = j.crbegin();
1272                 CHECK(it != j.crend());
1273                 CHECK(*it == j);
1274 
1275                 it++;
1276                 CHECK(it != j.crbegin());
1277                 CHECK(it == j.crend());
1278 
1279                 it--;
1280                 CHECK(it == j.crbegin());
1281                 CHECK(it != j.crend());
1282                 CHECK(*it == j);
1283 
1284                 ++it;
1285                 CHECK(it != j.crbegin());
1286                 CHECK(it == j.crend());
1287 
1288                 --it;
1289                 CHECK(it == j.crbegin());
1290                 CHECK(it != j.crend());
1291                 CHECK(*it == j);
1292             }
1293 
1294             SECTION("const json + crbegin/crend")
1295             {
1296                 json::const_reverse_iterator it = j_const.crbegin();
1297                 CHECK(it != j_const.crend());
1298                 CHECK(*it == j_const);
1299 
1300                 it++;
1301                 CHECK(it != j_const.crbegin());
1302                 CHECK(it == j_const.crend());
1303 
1304                 it--;
1305                 CHECK(it == j_const.crbegin());
1306                 CHECK(it != j_const.crend());
1307                 CHECK(*it == j_const);
1308 
1309                 ++it;
1310                 CHECK(it != j_const.crbegin());
1311                 CHECK(it == j_const.crend());
1312 
1313                 --it;
1314                 CHECK(it == j_const.crbegin());
1315                 CHECK(it != j_const.crend());
1316                 CHECK(*it == j_const);
1317             }
1318 
1319             SECTION("key/value")
1320             {
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));
1329 
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");
1340             }
1341         }
1342 
1343         SECTION("number (float)")
1344         {
1345             json j = 23.42;
1346             json j_const(j);
1347 
1348             SECTION("json + begin/end")
1349             {
1350                 json::iterator it = j.begin();
1351                 CHECK(it != j.end());
1352                 CHECK(*it == j);
1353 
1354                 it++;
1355                 CHECK(it != j.begin());
1356                 CHECK(it == j.end());
1357 
1358                 it--;
1359                 CHECK(it == j.begin());
1360                 CHECK(it != j.end());
1361                 CHECK(*it == j);
1362 
1363                 ++it;
1364                 CHECK(it != j.begin());
1365                 CHECK(it == j.end());
1366 
1367                 --it;
1368                 CHECK(it == j.begin());
1369                 CHECK(it != j.end());
1370                 CHECK(*it == j);
1371             }
1372 
1373             SECTION("const json + begin/end")
1374             {
1375                 json::const_iterator it = j_const.begin();
1376                 CHECK(it != j_const.end());
1377                 CHECK(*it == j_const);
1378 
1379                 it++;
1380                 CHECK(it != j_const.begin());
1381                 CHECK(it == j_const.end());
1382 
1383                 it--;
1384                 CHECK(it == j_const.begin());
1385                 CHECK(it != j_const.end());
1386                 CHECK(*it == j_const);
1387 
1388                 ++it;
1389                 CHECK(it != j_const.begin());
1390                 CHECK(it == j_const.end());
1391 
1392                 --it;
1393                 CHECK(it == j_const.begin());
1394                 CHECK(it != j_const.end());
1395                 CHECK(*it == j_const);
1396             }
1397 
1398             SECTION("json + cbegin/cend")
1399             {
1400                 json::const_iterator it = j.cbegin();
1401                 CHECK(it != j.cend());
1402                 CHECK(*it == j);
1403 
1404                 it++;
1405                 CHECK(it != j.cbegin());
1406                 CHECK(it == j.cend());
1407 
1408                 it--;
1409                 CHECK(it == j.cbegin());
1410                 CHECK(it != j.cend());
1411                 CHECK(*it == j);
1412 
1413                 ++it;
1414                 CHECK(it != j.cbegin());
1415                 CHECK(it == j.cend());
1416 
1417                 --it;
1418                 CHECK(it == j.cbegin());
1419                 CHECK(it != j.cend());
1420                 CHECK(*it == j);
1421             }
1422 
1423             SECTION("const json + cbegin/cend")
1424             {
1425                 json::const_iterator it = j_const.cbegin();
1426                 CHECK(it != j_const.cend());
1427                 CHECK(*it == j_const);
1428 
1429                 it++;
1430                 CHECK(it != j_const.cbegin());
1431                 CHECK(it == j_const.cend());
1432 
1433                 it--;
1434                 CHECK(it == j_const.cbegin());
1435                 CHECK(it != j_const.cend());
1436                 CHECK(*it == j_const);
1437 
1438                 ++it;
1439                 CHECK(it != j_const.cbegin());
1440                 CHECK(it == j_const.cend());
1441 
1442                 --it;
1443                 CHECK(it == j_const.cbegin());
1444                 CHECK(it != j_const.cend());
1445                 CHECK(*it == j_const);
1446             }
1447 
1448             SECTION("json + rbegin/rend")
1449             {
1450                 json::reverse_iterator it = j.rbegin();
1451                 CHECK(it != j.rend());
1452                 CHECK(*it == j);
1453 
1454                 it++;
1455                 CHECK(it != j.rbegin());
1456                 CHECK(it == j.rend());
1457 
1458                 it--;
1459                 CHECK(it == j.rbegin());
1460                 CHECK(it != j.rend());
1461                 CHECK(*it == j);
1462 
1463                 ++it;
1464                 CHECK(it != j.rbegin());
1465                 CHECK(it == j.rend());
1466 
1467                 --it;
1468                 CHECK(it == j.rbegin());
1469                 CHECK(it != j.rend());
1470                 CHECK(*it == j);
1471             }
1472 
1473             SECTION("json + crbegin/crend")
1474             {
1475                 json::const_reverse_iterator it = j.crbegin();
1476                 CHECK(it != j.crend());
1477                 CHECK(*it == j);
1478 
1479                 it++;
1480                 CHECK(it != j.crbegin());
1481                 CHECK(it == j.crend());
1482 
1483                 it--;
1484                 CHECK(it == j.crbegin());
1485                 CHECK(it != j.crend());
1486                 CHECK(*it == j);
1487 
1488                 ++it;
1489                 CHECK(it != j.crbegin());
1490                 CHECK(it == j.crend());
1491 
1492                 --it;
1493                 CHECK(it == j.crbegin());
1494                 CHECK(it != j.crend());
1495                 CHECK(*it == j);
1496             }
1497 
1498             SECTION("const json + crbegin/crend")
1499             {
1500                 json::const_reverse_iterator it = j_const.crbegin();
1501                 CHECK(it != j_const.crend());
1502                 CHECK(*it == j_const);
1503 
1504                 it++;
1505                 CHECK(it != j_const.crbegin());
1506                 CHECK(it == j_const.crend());
1507 
1508                 it--;
1509                 CHECK(it == j_const.crbegin());
1510                 CHECK(it != j_const.crend());
1511                 CHECK(*it == j_const);
1512 
1513                 ++it;
1514                 CHECK(it != j_const.crbegin());
1515                 CHECK(it == j_const.crend());
1516 
1517                 --it;
1518                 CHECK(it == j_const.crbegin());
1519                 CHECK(it != j_const.crend());
1520                 CHECK(*it == j_const);
1521             }
1522 
1523             SECTION("key/value")
1524             {
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));
1533 
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");
1544             }
1545         }
1546 
1547         SECTION("null")
1548         {
1549             json j = nullptr;
1550             json j_const(j);
1551 
1552             SECTION("json + begin/end")
1553             {
1554                 json::iterator it = j.begin();
1555                 CHECK(it == j.end());
1556             }
1557 
1558             SECTION("const json + begin/end")
1559             {
1560                 json::const_iterator it_begin = j_const.begin();
1561                 json::const_iterator it_end = j_const.end();
1562                 CHECK(it_begin == it_end);
1563             }
1564 
1565             SECTION("json + cbegin/cend")
1566             {
1567                 json::const_iterator it_begin = j.cbegin();
1568                 json::const_iterator it_end = j.cend();
1569                 CHECK(it_begin == it_end);
1570             }
1571 
1572             SECTION("const json + cbegin/cend")
1573             {
1574                 json::const_iterator it_begin = j_const.cbegin();
1575                 json::const_iterator it_end = j_const.cend();
1576                 CHECK(it_begin == it_end);
1577             }
1578 
1579             SECTION("json + rbegin/rend")
1580             {
1581                 json::reverse_iterator it = j.rbegin();
1582                 CHECK(it == j.rend());
1583             }
1584 
1585             SECTION("json + crbegin/crend")
1586             {
1587                 json::const_reverse_iterator it = j.crbegin();
1588                 CHECK(it == j.crend());
1589             }
1590 
1591             SECTION("const json + crbegin/crend")
1592             {
1593                 json::const_reverse_iterator it = j_const.crbegin();
1594                 CHECK(it == j_const.crend());
1595             }
1596 
1597             SECTION("key/value")
1598             {
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");
1609 
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");
1620             }
1621         }
1622     }
1623 
1624     SECTION("conversion from iterator to const iterator")
1625     {
1626         SECTION("boolean")
1627         {
1628             json j = true;
1629             json::const_iterator it = j.begin();
1630             CHECK(it == j.cbegin());
1631             it = j.begin();
1632             CHECK(it == j.cbegin());
1633         }
1634         SECTION("string")
1635         {
1636             json j = "hello world";
1637             json::const_iterator it = j.begin();
1638             CHECK(it == j.cbegin());
1639             it = j.begin();
1640             CHECK(it == j.cbegin());
1641         }
1642         SECTION("array")
1643         {
1644             json j = {1, 2, 3};
1645             json::const_iterator it = j.begin();
1646             CHECK(it == j.cbegin());
1647             it = j.begin();
1648             CHECK(it == j.cbegin());
1649         }
1650         SECTION("object")
1651         {
1652             json j = {{"A", 1}, {"B", 2}, {"C", 3}};
1653             json::const_iterator it = j.begin();
1654             CHECK(it == j.cbegin());
1655             it = j.begin();
1656             CHECK(it == j.cbegin());
1657         }
1658         SECTION("number (integer)")
1659         {
1660             json j = 23;
1661             json::const_iterator it = j.begin();
1662             CHECK(it == j.cbegin());
1663             it = j.begin();
1664             CHECK(it == j.cbegin());
1665         }
1666         SECTION("number (unsigned)")
1667         {
1668             json j = 23u;
1669             json::const_iterator it = j.begin();
1670             CHECK(it == j.cbegin());
1671             it = j.begin();
1672             CHECK(it == j.cbegin());
1673         }
1674         SECTION("number (float)")
1675         {
1676             json j = 23.42;
1677             json::const_iterator it = j.begin();
1678             CHECK(it == j.cbegin());
1679             it = j.begin();
1680             CHECK(it == j.cbegin());
1681         }
1682         SECTION("null")
1683         {
1684             json j = nullptr;
1685             json::const_iterator it = j.begin();
1686             CHECK(it == j.cbegin());
1687             it = j.begin();
1688             CHECK(it == j.cbegin());
1689         }
1690     }
1691 }
1692