• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     __ _____ _____ _____
3  __|  |   __|     |   | |  JSON for Modern C++ (test suite)
4 |  |  |__   |  |  | | | |  version 3.7.3
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 DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
32 
33 #define private public
34 #include <nlohmann/json.hpp>
35 using nlohmann::json;
36 #undef private
37 
38 #include <deque>
39 #include <forward_list>
40 #include <fstream>
41 #include <list>
42 #include <set>
43 #include <unordered_map>
44 #include <unordered_set>
45 #include <valarray>
46 
47 TEST_CASE("constructors")
48 {
49     SECTION("create an empty value with a given type")
50     {
51         SECTION("null")
52         {
53             auto t = json::value_t::null;
54             json j(t);
55             CHECK(j.type() == t);
56         }
57 
58         SECTION("discarded")
59         {
60             auto t = json::value_t::discarded;
61             json j(t);
62             CHECK(j.type() == t);
63         }
64 
65         SECTION("object")
66         {
67             auto t = json::value_t::object;
68             json j(t);
69             CHECK(j.type() == t);
70         }
71 
72         SECTION("array")
73         {
74             auto t = json::value_t::array;
75             json j(t);
76             CHECK(j.type() == t);
77         }
78 
79         SECTION("boolean")
80         {
81             auto t = json::value_t::boolean;
82             json j(t);
83             CHECK(j.type() == t);
84             CHECK(j == false);
85         }
86 
87         SECTION("string")
88         {
89             auto t = json::value_t::string;
90             json j(t);
91             CHECK(j.type() == t);
92             CHECK(j == "");
93         }
94 
95         SECTION("number_integer")
96         {
97             auto t = json::value_t::number_integer;
98             json j(t);
99             CHECK(j.type() == t);
100             CHECK(j == 0);
101         }
102 
103         SECTION("number_unsigned")
104         {
105             auto t = json::value_t::number_unsigned;
106             json j(t);
107             CHECK(j.type() == t);
108             CHECK(j == 0);
109         }
110 
111         SECTION("number_float")
112         {
113             auto t = json::value_t::number_float;
114             json j(t);
115             CHECK(j.type() == t);
116             CHECK(j == 0.0);
117         }
118     }
119 
120     SECTION("create a null object (implicitly)")
121     {
122         SECTION("no parameter")
123         {
124             json j{};
125             CHECK(j.type() == json::value_t::null);
126         }
127     }
128 
129     SECTION("create a null object (explicitly)")
130     {
131         SECTION("parameter")
132         {
133             json j(nullptr);
134             CHECK(j.type() == json::value_t::null);
135         }
136     }
137 
138     SECTION("create an object (explicit)")
139     {
140         SECTION("empty object")
141         {
142             json::object_t o;
143             json j(o);
144             CHECK(j.type() == json::value_t::object);
145         }
146 
147         SECTION("filled object")
148         {
149             json::object_t o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
150             json j(o);
151             CHECK(j.type() == json::value_t::object);
152         }
153     }
154 
155     SECTION("create an object (implicit)")
156     {
157         // reference object
158         json::object_t o_reference {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
159         json j_reference(o_reference);
160 
161         SECTION("std::map<json::string_t, json>")
162         {
163             std::map<json::string_t, json> o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
164             json j(o);
165             CHECK(j.type() == json::value_t::object);
166             CHECK(j == j_reference);
167         }
168 
169         SECTION("std::map<std::string, std::string> #600")
170         {
171             std::map<std::string, std::string> m;
172             m["a"] = "b";
173             m["c"] = "d";
174             m["e"] = "f";
175 
176             json j(m);
177             CHECK((j.get<decltype(m)>() == m));
178         }
179 
180         SECTION("std::map<const char*, json>")
181         {
182             std::map<const char*, json> o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
183             json j(o);
184             CHECK(j.type() == json::value_t::object);
185             CHECK(j == j_reference);
186         }
187 
188 
189         SECTION("std::multimap<json::string_t, json>")
190         {
191             std::multimap<json::string_t, json> o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
192             json j(o);
193             CHECK(j.type() == json::value_t::object);
194             CHECK(j == j_reference);
195         }
196 
197         SECTION("std::unordered_map<json::string_t, json>")
198         {
199             std::unordered_map<json::string_t, json> o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
200             json j(o);
201             CHECK(j.type() == json::value_t::object);
202             CHECK(j == j_reference);
203         }
204 
205         SECTION("std::unordered_multimap<json::string_t, json>")
206         {
207             std::unordered_multimap<json::string_t, json> o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
208             json j(o);
209             CHECK(j.type() == json::value_t::object);
210             CHECK(j == j_reference);
211         }
212 
213         SECTION("associative container literal")
214         {
215             json j({{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}});
216             CHECK(j.type() == json::value_t::object);
217             CHECK(j == j_reference);
218         }
219     }
220 
221     SECTION("create an array (explicit)")
222     {
223         SECTION("empty array")
224         {
225             json::array_t a;
226             json j(a);
227             CHECK(j.type() == json::value_t::array);
228         }
229 
230         SECTION("filled array")
231         {
232             json::array_t a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
233             json j(a);
234             CHECK(j.type() == json::value_t::array);
235         }
236     }
237 
238     SECTION("create an array (implicit)")
239     {
240         // reference array
241         json::array_t a_reference {json(1), json(1u), json(2.2), json(false), json("string"), json()};
242         json j_reference(a_reference);
243 
244         SECTION("std::list<json>")
245         {
246             std::list<json> a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
247             json j(a);
248             CHECK(j.type() == json::value_t::array);
249             CHECK(j == j_reference);
250         }
251 
252         SECTION("std::pair")
253         {
254             std::pair<float, std::string> p{1.0f, "string"};
255             json j(p);
256 
257             CHECK(j.type() == json::value_t::array);
258             CHECK(j.get<decltype(p)>() == p);
259             REQUIRE(j.size() == 2);
260             CHECK(j[0] == std::get<0>(p));
261             CHECK(j[1] == std::get<1>(p));
262         }
263 
264         SECTION("std::pair with discarded values")
265         {
266             json j{1, 2.0, "string"};
267 
268             const auto p = j.get<std::pair<int, float>>();
269             CHECK(p.first == j[0]);
270             CHECK(p.second == j[1]);
271         }
272 
273         SECTION("std::tuple")
274         {
275             const auto t = std::make_tuple(1.0, std::string{"string"}, 42, std::vector<int> {0, 1});
276             json j(t);
277 
278             CHECK(j.type() == json::value_t::array);
279             REQUIRE(j.size() == 4);
280             CHECK(j.get<decltype(t)>() == t);
281             CHECK(j[0] == std::get<0>(t));
282             CHECK(j[1] == std::get<1>(t));
283             CHECK(j[2] == std::get<2>(t));
284             CHECK(j[3][0] == 0);
285             CHECK(j[3][1] == 1);
286         }
287 
288         SECTION("std::tuple with discarded values")
289         {
290             json j{1, 2.0, "string", 42};
291 
292             const auto t = j.get<std::tuple<int, float, std::string>>();
293             CHECK(std::get<0>(t) == j[0]);
294             CHECK(std::get<1>(t) == j[1]);
295             CHECK(std::get<2>(t) == j[2]);
296         }
297 
298         SECTION("std::pair/tuple/array failures")
299         {
300             json j{1};
301 
302             CHECK_THROWS_AS((j.get<std::pair<int, int>>()), json::out_of_range&);
303             CHECK_THROWS_WITH((j.get<std::pair<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range");
304             CHECK_THROWS_AS((j.get<std::tuple<int, int>>()), json::out_of_range&);
305             CHECK_THROWS_WITH((j.get<std::tuple<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range");
306             CHECK_THROWS_AS((j.get<std::array<int, 3>>()), json::out_of_range&);
307             CHECK_THROWS_WITH((j.get<std::array<int, 3>>()), "[json.exception.out_of_range.401] array index 1 is out of range");
308         }
309 
310         SECTION("std::forward_list<json>")
311         {
312             std::forward_list<json> a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
313             json j(a);
314             CHECK(j.type() == json::value_t::array);
315             CHECK(j == j_reference);
316         }
317 
318         SECTION("std::array<json, 6>")
319         {
320             std::array<json, 6> a {{json(1), json(1u), json(2.2), json(false), json("string"), json()}};
321             json j(a);
322             CHECK(j.type() == json::value_t::array);
323             CHECK(j == j_reference);
324 
325             const auto a2 = j.get<std::array<json, 6>>();
326             CHECK(a2 == a);
327         }
328 
329         SECTION("std::valarray<int>")
330         {
331             std::valarray<int> va = {1, 2, 3, 4, 5};
332             json j(va);
333             CHECK(j.type() == json::value_t::array);
334             CHECK(j == json({1, 2, 3, 4, 5}));
335 
336             std::valarray<int> jva = j;
337             CHECK(jva.size() == va.size());
338             for (size_t i = 0; i < jva.size(); ++i)
339             {
340                 CHECK(va[i] == jva[i]);
341             }
342         }
343 
344         SECTION("std::valarray<double>")
345         {
346             std::valarray<double> va = {1.2, 2.3, 3.4, 4.5, 5.6};
347             json j(va);
348             CHECK(j.type() == json::value_t::array);
349             CHECK(j == json({1.2, 2.3, 3.4, 4.5, 5.6}));
350 
351             std::valarray<double> jva = j;
352             CHECK(jva.size() == va.size());
353             for (size_t i = 0; i < jva.size(); ++i)
354             {
355                 CHECK(va[i] == jva[i]);
356             }
357         }
358 
359         SECTION("std::vector<json>")
360         {
361             std::vector<json> a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
362             json j(a);
363             CHECK(j.type() == json::value_t::array);
364             CHECK(j == j_reference);
365         }
366 
367         SECTION("std::deque<json>")
368         {
369             std::deque<json> a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
370             json j(a);
371             CHECK(j.type() == json::value_t::array);
372             CHECK(j == j_reference);
373         }
374 
375         SECTION("std::set<json>")
376         {
377             std::set<json> a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
378             json j(a);
379             CHECK(j.type() == json::value_t::array);
380             // we cannot really check for equality here
381         }
382 
383         SECTION("std::unordered_set<json>")
384         {
385             std::unordered_set<json> a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
386             json j(a);
387             CHECK(j.type() == json::value_t::array);
388             // we cannot really check for equality here
389         }
390 
391         SECTION("sequence container literal")
392         {
393             json j({json(1), json(1u), json(2.2), json(false), json("string"), json()});
394             CHECK(j.type() == json::value_t::array);
395             CHECK(j == j_reference);
396         }
397     }
398 
399     SECTION("create a string (explicit)")
400     {
401         SECTION("empty string")
402         {
403             json::string_t s;
404             json j(s);
405             CHECK(j.type() == json::value_t::string);
406         }
407 
408         SECTION("filled string")
409         {
410             json::string_t s {"Hello world"};
411             json j(s);
412             CHECK(j.type() == json::value_t::string);
413         }
414     }
415 
416     SECTION("create a string (implicit)")
417     {
418         // reference string
419         json::string_t s_reference {"Hello world"};
420         json j_reference(s_reference);
421 
422         SECTION("std::string")
423         {
424             std::string s {"Hello world"};
425             json j(s);
426             CHECK(j.type() == json::value_t::string);
427             CHECK(j == j_reference);
428         }
429 
430         SECTION("char[]")
431         {
432             char s[] {"Hello world"};
433             json j(s);
434             CHECK(j.type() == json::value_t::string);
435             CHECK(j == j_reference);
436         }
437 
438         SECTION("const char*")
439         {
440             const char* s {"Hello world"};
441             json j(s);
442             CHECK(j.type() == json::value_t::string);
443             CHECK(j == j_reference);
444         }
445 
446         SECTION("string literal")
447         {
448             json j("Hello world");
449             CHECK(j.type() == json::value_t::string);
450             CHECK(j == j_reference);
451         }
452     }
453 
454     SECTION("create a boolean (explicit)")
455     {
456         SECTION("empty boolean")
457         {
458             json::boolean_t b{};
459             json j(b);
460             CHECK(j.type() == json::value_t::boolean);
461         }
462 
463         SECTION("filled boolean (true)")
464         {
465             json j(true);
466             CHECK(j.type() == json::value_t::boolean);
467         }
468 
469         SECTION("filled boolean (false)")
470         {
471             json j(false);
472             CHECK(j.type() == json::value_t::boolean);
473         }
474     }
475 
476     SECTION("create an integer number (explicit)")
477     {
478         SECTION("uninitialized value")
479         {
480             json::number_integer_t n{};
481             json j(n);
482             CHECK(j.type() == json::value_t::number_integer);
483         }
484 
485         SECTION("initialized value")
486         {
487             json::number_integer_t n(42);
488             json j(n);
489             CHECK(j.type() == json::value_t::number_integer);
490         }
491     }
492 
493     SECTION("create an integer number (implicit)")
494     {
495         // reference objects
496         json::number_integer_t n_reference = 42;
497         json j_reference(n_reference);
498         json::number_unsigned_t n_unsigned_reference = 42;
499         json j_unsigned_reference(n_unsigned_reference);
500 
501         SECTION("short")
502         {
503             short n = 42;
504             json j(n);
505             CHECK(j.type() == json::value_t::number_integer);
506             CHECK(j == j_reference);
507         }
508 
509         SECTION("unsigned short")
510         {
511             unsigned short n = 42;
512             json j(n);
513             CHECK(j.type() == json::value_t::number_unsigned);
514             CHECK(j == j_unsigned_reference);
515         }
516 
517         SECTION("int")
518         {
519             int n = 42;
520             json j(n);
521             CHECK(j.type() == json::value_t::number_integer);
522             CHECK(j == j_reference);
523         }
524 
525         SECTION("unsigned int")
526         {
527             unsigned int n = 42;
528             json j(n);
529             CHECK(j.type() == json::value_t::number_unsigned);
530             CHECK(j == j_unsigned_reference);
531         }
532 
533         SECTION("long")
534         {
535             long n = 42;
536             json j(n);
537             CHECK(j.type() == json::value_t::number_integer);
538             CHECK(j == j_reference);
539         }
540 
541         SECTION("unsigned long")
542         {
543             unsigned long n = 42;
544             json j(n);
545             CHECK(j.type() == json::value_t::number_unsigned);
546             CHECK(j == j_unsigned_reference);
547         }
548 
549         SECTION("long long")
550         {
551             long long n = 42;
552             json j(n);
553             CHECK(j.type() == json::value_t::number_integer);
554             CHECK(j == j_reference);
555         }
556 
557         SECTION("unsigned long long")
558         {
559             unsigned long long n = 42;
560             json j(n);
561             CHECK(j.type() == json::value_t::number_unsigned);
562             CHECK(j == j_unsigned_reference);
563         }
564 
565         SECTION("int8_t")
566         {
567             int8_t n = 42;
568             json j(n);
569             CHECK(j.type() == json::value_t::number_integer);
570             CHECK(j == j_reference);
571         }
572 
573         SECTION("int16_t")
574         {
575             int16_t n = 42;
576             json j(n);
577             CHECK(j.type() == json::value_t::number_integer);
578             CHECK(j == j_reference);
579         }
580 
581         SECTION("int32_t")
582         {
583             int32_t n = 42;
584             json j(n);
585             CHECK(j.type() == json::value_t::number_integer);
586             CHECK(j == j_reference);
587         }
588 
589         SECTION("int64_t")
590         {
591             int64_t n = 42;
592             json j(n);
593             CHECK(j.type() == json::value_t::number_integer);
594             CHECK(j == j_reference);
595         }
596 
597         SECTION("int_fast8_t")
598         {
599             int_fast8_t n = 42;
600             json j(n);
601             CHECK(j.type() == json::value_t::number_integer);
602             CHECK(j == j_reference);
603         }
604 
605         SECTION("int_fast16_t")
606         {
607             int_fast16_t n = 42;
608             json j(n);
609             CHECK(j.type() == json::value_t::number_integer);
610             CHECK(j == j_reference);
611         }
612 
613         SECTION("int_fast32_t")
614         {
615             int_fast32_t n = 42;
616             json j(n);
617             CHECK(j.type() == json::value_t::number_integer);
618             CHECK(j == j_reference);
619         }
620 
621         SECTION("int_fast64_t")
622         {
623             int_fast64_t n = 42;
624             json j(n);
625             CHECK(j.type() == json::value_t::number_integer);
626             CHECK(j == j_reference);
627         }
628 
629         SECTION("int_least8_t")
630         {
631             int_least8_t n = 42;
632             json j(n);
633             CHECK(j.type() == json::value_t::number_integer);
634             CHECK(j == j_reference);
635         }
636 
637         SECTION("int_least16_t")
638         {
639             int_least16_t n = 42;
640             json j(n);
641             CHECK(j.type() == json::value_t::number_integer);
642             CHECK(j == j_reference);
643         }
644 
645         SECTION("int_least32_t")
646         {
647             int_least32_t n = 42;
648             json j(n);
649             CHECK(j.type() == json::value_t::number_integer);
650             CHECK(j == j_reference);
651         }
652 
653         SECTION("int_least64_t")
654         {
655             int_least64_t n = 42;
656             json j(n);
657             CHECK(j.type() == json::value_t::number_integer);
658             CHECK(j == j_reference);
659         }
660 
661         SECTION("uint8_t")
662         {
663             uint8_t n = 42;
664             json j(n);
665             CHECK(j.type() == json::value_t::number_unsigned);
666             CHECK(j == j_unsigned_reference);
667         }
668 
669         SECTION("uint16_t")
670         {
671             uint16_t n = 42;
672             json j(n);
673             CHECK(j.type() == json::value_t::number_unsigned);
674             CHECK(j == j_unsigned_reference);
675         }
676 
677         SECTION("uint32_t")
678         {
679             uint32_t n = 42;
680             json j(n);
681             CHECK(j.type() == json::value_t::number_unsigned);
682             CHECK(j == j_unsigned_reference);
683         }
684 
685         SECTION("uint64_t")
686         {
687             uint64_t n = 42;
688             json j(n);
689             CHECK(j.type() == json::value_t::number_unsigned);
690             CHECK(j == j_unsigned_reference);
691         }
692 
693         SECTION("uint_fast8_t")
694         {
695             uint_fast8_t n = 42;
696             json j(n);
697             CHECK(j.type() == json::value_t::number_unsigned);
698             CHECK(j == j_unsigned_reference);
699         }
700 
701         SECTION("uint_fast16_t")
702         {
703             uint_fast16_t n = 42;
704             json j(n);
705             CHECK(j.type() == json::value_t::number_unsigned);
706             CHECK(j == j_unsigned_reference);
707         }
708 
709         SECTION("uint_fast32_t")
710         {
711             uint_fast32_t n = 42;
712             json j(n);
713             CHECK(j.type() == json::value_t::number_unsigned);
714             CHECK(j == j_unsigned_reference);
715         }
716 
717         SECTION("uint_fast64_t")
718         {
719             uint_fast64_t n = 42;
720             json j(n);
721             CHECK(j.type() == json::value_t::number_unsigned);
722             CHECK(j == j_unsigned_reference);
723         }
724 
725         SECTION("uint_least8_t")
726         {
727             uint_least8_t n = 42;
728             json j(n);
729             CHECK(j.type() == json::value_t::number_unsigned);
730             CHECK(j == j_unsigned_reference);
731         }
732 
733         SECTION("uint_least16_t")
734         {
735             uint_least16_t n = 42;
736             json j(n);
737             CHECK(j.type() == json::value_t::number_unsigned);
738             CHECK(j == j_unsigned_reference);
739         }
740 
741         SECTION("uint_least32_t")
742         {
743             uint_least32_t n = 42;
744             json j(n);
745             CHECK(j.type() == json::value_t::number_unsigned);
746             CHECK(j == j_unsigned_reference);
747         }
748 
749         SECTION("uint_least64_t")
750         {
751             uint_least64_t n = 42;
752             json j(n);
753             CHECK(j.type() == json::value_t::number_unsigned);
754             CHECK(j == j_unsigned_reference);
755         }
756 
757         SECTION("integer literal without suffix")
758         {
759             json j(42);
760             CHECK(j.type() == json::value_t::number_integer);
761             CHECK(j == j_reference);
762         }
763 
764         SECTION("integer literal with u suffix")
765         {
766             json j(42u);
767             CHECK(j.type() == json::value_t::number_unsigned);
768             CHECK(j == j_unsigned_reference);
769         }
770 
771         SECTION("integer literal with l suffix")
772         {
773             json j(42l);
774             CHECK(j.type() == json::value_t::number_integer);
775             CHECK(j == j_reference);
776         }
777 
778         SECTION("integer literal with ul suffix")
779         {
780             json j(42ul);
781             CHECK(j.type() == json::value_t::number_unsigned);
782             CHECK(j == j_unsigned_reference);
783         }
784 
785         SECTION("integer literal with ll suffix")
786         {
787             json j(42ll);
788             CHECK(j.type() == json::value_t::number_integer);
789             CHECK(j == j_reference);
790         }
791 
792         SECTION("integer literal with ull suffix")
793         {
794             json j(42ull);
795             CHECK(j.type() == json::value_t::number_unsigned);
796             CHECK(j == j_unsigned_reference);
797         }
798     }
799 
800     SECTION("create a floating-point number (explicit)")
801     {
802         SECTION("uninitialized value")
803         {
804             json::number_float_t n{};
805             json j(n);
806             CHECK(j.type() == json::value_t::number_float);
807         }
808 
809         SECTION("initialized value")
810         {
811             json::number_float_t n(42.23);
812             json j(n);
813             CHECK(j.type() == json::value_t::number_float);
814         }
815 
816         SECTION("infinity")
817         {
818             // infinity is stored properly, but serialized to null
819             json::number_float_t n(std::numeric_limits<json::number_float_t>::infinity());
820             json j(n);
821             CHECK(j.type() == json::value_t::number_float);
822 
823             // check round trip of infinity
824             json::number_float_t d = j;
825             CHECK(d == n);
826 
827             // check that inf is serialized to null
828             CHECK(j.dump() == "null");
829         }
830     }
831 
832     SECTION("create a floating-point number (implicit)")
833     {
834         // reference object
835         json::number_float_t n_reference = 42.23;
836         json j_reference(n_reference);
837 
838         SECTION("float")
839         {
840             float n = 42.23f;
841             json j(n);
842             CHECK(j.type() == json::value_t::number_float);
843             CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
844         }
845 
846         SECTION("double")
847         {
848             double n = 42.23;
849             json j(n);
850             CHECK(j.type() == json::value_t::number_float);
851             CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
852         }
853 
854         SECTION("long double")
855         {
856             long double n = 42.23l;
857             json j(n);
858             CHECK(j.type() == json::value_t::number_float);
859             CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
860         }
861 
862         SECTION("floating-point literal without suffix")
863         {
864             json j(42.23);
865             CHECK(j.type() == json::value_t::number_float);
866             CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
867         }
868 
869         SECTION("integer literal with f suffix")
870         {
871             json j(42.23f);
872             CHECK(j.type() == json::value_t::number_float);
873             CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
874         }
875 
876         SECTION("integer literal with l suffix")
877         {
878             json j(42.23l);
879             CHECK(j.type() == json::value_t::number_float);
880             CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
881         }
882     }
883 
884     SECTION("create a container (array or object) from an initializer list")
885     {
886         SECTION("empty initializer list")
887         {
888             SECTION("explicit")
889             {
890                 json j(json::initializer_list_t {});
891                 CHECK(j.type() == json::value_t::object);
892             }
893 
894             SECTION("implicit")
895             {
896                 json j {};
897                 CHECK(j.type() == json::value_t::null);
898             }
899         }
900 
901         SECTION("one element")
902         {
903             SECTION("array")
904             {
905                 SECTION("explicit")
906                 {
907                     json j(json::initializer_list_t {json(json::array_t())});
908                     CHECK(j.type() == json::value_t::array);
909                 }
910 
911                 SECTION("implicit")
912                 {
913                     json j {json::array_t()};
914                     CHECK(j.type() == json::value_t::array);
915                 }
916             }
917 
918             SECTION("object")
919             {
920                 SECTION("explicit")
921                 {
922                     json j(json::initializer_list_t {json(json::object_t())});
923                     CHECK(j.type() == json::value_t::array);
924                 }
925 
926                 SECTION("implicit")
927                 {
928                     json j {json::object_t()};
929                     CHECK(j.type() == json::value_t::array);
930                 }
931             }
932 
933             SECTION("string")
934             {
935                 SECTION("explicit")
936                 {
937                     json j(json::initializer_list_t {json("Hello world")});
938                     CHECK(j.type() == json::value_t::array);
939                 }
940 
941                 SECTION("implicit")
942                 {
943                     json j {"Hello world"};
944                     CHECK(j.type() == json::value_t::array);
945                 }
946             }
947 
948             SECTION("boolean")
949             {
950                 SECTION("explicit")
951                 {
952                     json j(json::initializer_list_t {json(true)});
953                     CHECK(j.type() == json::value_t::array);
954                 }
955 
956                 SECTION("implicit")
957                 {
958                     json j {true};
959                     CHECK(j.type() == json::value_t::array);
960                 }
961             }
962 
963             SECTION("number (integer)")
964             {
965                 SECTION("explicit")
966                 {
967                     json j(json::initializer_list_t {json(1)});
968                     CHECK(j.type() == json::value_t::array);
969                 }
970 
971                 SECTION("implicit")
972                 {
973                     json j {1};
974                     CHECK(j.type() == json::value_t::array);
975                 }
976             }
977 
978             SECTION("number (unsigned)")
979             {
980                 SECTION("explicit")
981                 {
982                     json j(json::initializer_list_t {json(1u)});
983                     CHECK(j.type() == json::value_t::array);
984                 }
985 
986                 SECTION("implicit")
987                 {
988                     json j {1u};
989                     CHECK(j.type() == json::value_t::array);
990                 }
991             }
992 
993             SECTION("number (floating-point)")
994             {
995                 SECTION("explicit")
996                 {
997                     json j(json::initializer_list_t {json(42.23)});
998                     CHECK(j.type() == json::value_t::array);
999                 }
1000 
1001                 SECTION("implicit")
1002                 {
1003                     json j {42.23};
1004                     CHECK(j.type() == json::value_t::array);
1005                 }
1006             }
1007         }
1008 
1009         SECTION("more elements")
1010         {
1011             SECTION("explicit")
1012             {
1013                 json j(json::initializer_list_t {1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()});
1014                 CHECK(j.type() == json::value_t::array);
1015             }
1016 
1017             SECTION("implicit")
1018             {
1019                 json j {1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()};
1020                 CHECK(j.type() == json::value_t::array);
1021             }
1022         }
1023 
1024         SECTION("implicit type deduction")
1025         {
1026             SECTION("object")
1027             {
1028                 json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} };
1029                 CHECK(j.type() == json::value_t::object);
1030             }
1031 
1032             SECTION("array")
1033             {
1034                 json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 };
1035                 CHECK(j.type() == json::value_t::array);
1036             }
1037         }
1038 
1039         SECTION("explicit type deduction")
1040         {
1041             SECTION("empty object")
1042             {
1043                 json j = json::object();
1044                 CHECK(j.type() == json::value_t::object);
1045             }
1046 
1047             SECTION("object")
1048             {
1049                 json j = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} });
1050                 CHECK(j.type() == json::value_t::object);
1051             }
1052 
1053             SECTION("object with error")
1054             {
1055                 json _;
1056                 CHECK_THROWS_AS(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
1057                 json::type_error&);
1058                 CHECK_THROWS_WITH(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
1059                 "[json.exception.type_error.301] cannot create object from initializer list");
1060             }
1061 
1062             SECTION("empty array")
1063             {
1064                 json j = json::array();
1065                 CHECK(j.type() == json::value_t::array);
1066             }
1067 
1068             SECTION("array")
1069             {
1070                 json j = json::array({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} });
1071                 CHECK(j.type() == json::value_t::array);
1072             }
1073         }
1074 
1075         SECTION("move from initializer_list")
1076         {
1077             SECTION("string")
1078             {
1079                 // This should break through any short string optimization in std::string
1080                 std::string source(1024, '!');
1081                 const char* source_addr = source.data();
1082 
1083                 SECTION("constructor with implicit types (array)")
1084                 {
1085                     json j = {std::move(source)};
1086                     CHECK(j[0].get_ref<std::string const&>().data() == source_addr);
1087                 }
1088 
1089                 SECTION("constructor with implicit types (object)")
1090                 {
1091                     json j = {{"key", std::move(source)}};
1092                     CHECK(j["key"].get_ref<std::string const&>().data() == source_addr);
1093                 }
1094 
1095                 SECTION("constructor with implicit types (object key)")
1096                 {
1097                     json j = {{std::move(source), 42}};
1098                     CHECK(j.get_ref<json::object_t&>().begin()->first.data() == source_addr);
1099                 }
1100             }
1101 
1102             SECTION("array")
1103             {
1104                 json::array_t source = {1, 2, 3};
1105                 const json* source_addr = source.data();
1106 
1107                 SECTION("constructor with implicit types (array)")
1108                 {
1109                     json j {std::move(source)};
1110                     CHECK(j[0].get_ref<json::array_t const&>().data() == source_addr);
1111                 }
1112 
1113                 SECTION("constructor with implicit types (object)")
1114                 {
1115                     json j {{"key", std::move(source)}};
1116                     CHECK(j["key"].get_ref<json::array_t const&>().data() == source_addr);
1117                 }
1118 
1119                 SECTION("assignment with implicit types (array)")
1120                 {
1121                     json j = {std::move(source)};
1122                     CHECK(j[0].get_ref<json::array_t const&>().data() == source_addr);
1123                 }
1124 
1125                 SECTION("assignment with implicit types (object)")
1126                 {
1127                     json j = {{"key", std::move(source)}};
1128                     CHECK(j["key"].get_ref<json::array_t const&>().data() == source_addr);
1129                 }
1130             }
1131 
1132             SECTION("object")
1133             {
1134                 json::object_t source = {{"hello", "world"}};
1135                 const json* source_addr = &source.at("hello");
1136 
1137                 SECTION("constructor with implicit types (array)")
1138                 {
1139                     json j {std::move(source)};
1140                     CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr);
1141                 }
1142 
1143                 SECTION("constructor with implicit types (object)")
1144                 {
1145                     json j {{"key", std::move(source)}};
1146                     CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr);
1147                 }
1148 
1149                 SECTION("assignment with implicit types (array)")
1150                 {
1151                     json j = {std::move(source)};
1152                     CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr);
1153                 }
1154 
1155                 SECTION("assignment with implicit types (object)")
1156                 {
1157                     json j = {{"key", std::move(source)}};
1158                     CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr);
1159                 }
1160             }
1161 
1162             SECTION("json")
1163             {
1164                 json source {1, 2, 3};
1165                 const json* source_addr = &source[0];
1166 
1167                 SECTION("constructor with implicit types (array)")
1168                 {
1169                     json j {std::move(source), {}};
1170                     CHECK(&j[0][0] == source_addr);
1171                 }
1172 
1173                 SECTION("constructor with implicit types (object)")
1174                 {
1175                     json j {{"key", std::move(source)}};
1176                     CHECK(&j["key"][0] == source_addr);
1177                 }
1178 
1179                 SECTION("assignment with implicit types (array)")
1180                 {
1181                     json j = {std::move(source), {}};
1182                     CHECK(&j[0][0] == source_addr);
1183                 }
1184 
1185                 SECTION("assignment with implicit types (object)")
1186                 {
1187                     json j = {{"key", std::move(source)}};
1188                     CHECK(&j["key"][0] == source_addr);
1189                 }
1190             }
1191 
1192         }
1193     }
1194 
1195     SECTION("create an array of n copies of a given value")
1196     {
1197         SECTION("cnt = 0")
1198         {
1199             json v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
1200             json arr(0, v);
1201             CHECK(arr.size() == 0);
1202         }
1203 
1204         SECTION("cnt = 1")
1205         {
1206             json v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
1207             json arr(1, v);
1208             CHECK(arr.size() == 1);
1209             for (auto& x : arr)
1210             {
1211                 CHECK(x == v);
1212             }
1213         }
1214 
1215         SECTION("cnt = 3")
1216         {
1217             json v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
1218             json arr(3, v);
1219             CHECK(arr.size() == 3);
1220             for (auto& x : arr)
1221             {
1222                 CHECK(x == v);
1223             }
1224         }
1225     }
1226 
1227     SECTION("create a JSON container from an iterator range")
1228     {
1229         SECTION("object")
1230         {
1231             SECTION("json(begin(), end())")
1232             {
1233                 {
1234                     json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
1235                     json j_new(jobject.begin(), jobject.end());
1236                     CHECK(j_new == jobject);
1237                 }
1238                 {
1239                     json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
1240                     json j_new(jobject.cbegin(), jobject.cend());
1241                     CHECK(j_new == jobject);
1242                 }
1243             }
1244 
1245             SECTION("json(begin(), begin())")
1246             {
1247                 {
1248                     json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
1249                     json j_new(jobject.begin(), jobject.begin());
1250                     CHECK(j_new == json::object());
1251                 }
1252                 {
1253                     json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
1254                     json j_new(jobject.cbegin(), jobject.cbegin());
1255                     CHECK(j_new == json::object());
1256                 }
1257             }
1258 
1259             SECTION("construct from subrange")
1260             {
1261                 json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
1262                 json j_new(jobject.find("b"), jobject.find("e"));
1263                 CHECK(j_new == json({{"b", 1}, {"c", 17u}, {"d", false}}));
1264             }
1265 
1266             SECTION("incompatible iterators")
1267             {
1268                 {
1269                     json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
1270                     json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
1271                     CHECK_THROWS_AS(json(jobject.begin(), jobject2.end()), json::invalid_iterator&);
1272                     CHECK_THROWS_AS(json(jobject2.begin(), jobject.end()), json::invalid_iterator&);
1273                     CHECK_THROWS_WITH(json(jobject.begin(), jobject2.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
1274                     CHECK_THROWS_WITH(json(jobject2.begin(), jobject.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
1275                 }
1276                 {
1277                     json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
1278                     json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
1279                     CHECK_THROWS_AS(json(jobject.cbegin(), jobject2.cend()), json::invalid_iterator&);
1280                     CHECK_THROWS_AS(json(jobject2.cbegin(), jobject.cend()), json::invalid_iterator&);
1281                     CHECK_THROWS_WITH(json(jobject.cbegin(), jobject2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible");
1282                     CHECK_THROWS_WITH(json(jobject2.cbegin(), jobject.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible");
1283                 }
1284             }
1285         }
1286 
1287         SECTION("array")
1288         {
1289             SECTION("json(begin(), end())")
1290             {
1291                 {
1292                     json jarray = {1, 2, 3, 4, 5};
1293                     json j_new(jarray.begin(), jarray.end());
1294                     CHECK(j_new == jarray);
1295                 }
1296                 {
1297                     json jarray = {1, 2, 3, 4, 5};
1298                     json j_new(jarray.cbegin(), jarray.cend());
1299                     CHECK(j_new == jarray);
1300                 }
1301             }
1302 
1303             SECTION("json(begin(), begin())")
1304             {
1305                 {
1306                     json jarray = {1, 2, 3, 4, 5};
1307                     json j_new(jarray.begin(), jarray.begin());
1308                     CHECK(j_new == json::array());
1309                 }
1310                 {
1311                     json jarray = {1, 2, 3, 4, 5};
1312                     json j_new(jarray.cbegin(), jarray.cbegin());
1313                     CHECK(j_new == json::array());
1314                 }
1315             }
1316 
1317             SECTION("construct from subrange")
1318             {
1319                 {
1320                     json jarray = {1, 2, 3, 4, 5};
1321                     json j_new(jarray.begin() + 1, jarray.begin() + 3);
1322                     CHECK(j_new == json({2, 3}));
1323                 }
1324                 {
1325                     json jarray = {1, 2, 3, 4, 5};
1326                     json j_new(jarray.cbegin() + 1, jarray.cbegin() + 3);
1327                     CHECK(j_new == json({2, 3}));
1328                 }
1329             }
1330 
1331             SECTION("incompatible iterators")
1332             {
1333                 {
1334                     json jarray = {1, 2, 3, 4};
1335                     json jarray2 = {2, 3, 4, 5};
1336                     CHECK_THROWS_AS(json(jarray.begin(), jarray2.end()), json::invalid_iterator&);
1337                     CHECK_THROWS_AS(json(jarray2.begin(), jarray.end()), json::invalid_iterator&);
1338                     CHECK_THROWS_WITH(json(jarray.begin(), jarray2.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
1339                     CHECK_THROWS_WITH(json(jarray2.begin(), jarray.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
1340                 }
1341                 {
1342                     json jarray = {1, 2, 3, 4};
1343                     json jarray2 = {2, 3, 4, 5};
1344                     CHECK_THROWS_AS(json(jarray.cbegin(), jarray2.cend()), json::invalid_iterator&);
1345                     CHECK_THROWS_AS(json(jarray2.cbegin(), jarray.cend()), json::invalid_iterator&);
1346                     CHECK_THROWS_WITH(json(jarray.cbegin(), jarray2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible");
1347                     CHECK_THROWS_WITH(json(jarray2.cbegin(), jarray.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible");
1348                 }
1349             }
1350         }
1351 
1352         SECTION("other values")
1353         {
1354             SECTION("construct with two valid iterators")
1355             {
1356                 SECTION("null")
1357                 {
1358                     {
1359                         json j;
1360                         CHECK_THROWS_AS(json(j.begin(), j.end()), json::invalid_iterator&);
1361                         CHECK_THROWS_WITH(json(j.begin(), j.end()),
1362                                           "[json.exception.invalid_iterator.206] cannot construct with iterators from null");
1363                     }
1364                     {
1365                         json j;
1366                         CHECK_THROWS_AS(json(j.cbegin(), j.cend()), json::invalid_iterator&);
1367                         CHECK_THROWS_WITH(json(j.cbegin(), j.cend()),
1368                                           "[json.exception.invalid_iterator.206] cannot construct with iterators from null");
1369                     }
1370                 }
1371 
1372                 SECTION("string")
1373                 {
1374                     {
1375                         json j = "foo";
1376                         json j_new(j.begin(), j.end());
1377                         CHECK(j == j_new);
1378                     }
1379                     {
1380                         json j = "bar";
1381                         json j_new(j.cbegin(), j.cend());
1382                         CHECK(j == j_new);
1383                     }
1384                 }
1385 
1386                 SECTION("number (boolean)")
1387                 {
1388                     {
1389                         json j = false;
1390                         json j_new(j.begin(), j.end());
1391                         CHECK(j == j_new);
1392                     }
1393                     {
1394                         json j = true;
1395                         json j_new(j.cbegin(), j.cend());
1396                         CHECK(j == j_new);
1397                     }
1398                 }
1399 
1400                 SECTION("number (integer)")
1401                 {
1402                     {
1403                         json j = 17;
1404                         json j_new(j.begin(), j.end());
1405                         CHECK(j == j_new);
1406                     }
1407                     {
1408                         json j = 17;
1409                         json j_new(j.cbegin(), j.cend());
1410                         CHECK(j == j_new);
1411                     }
1412                 }
1413 
1414                 SECTION("number (unsigned)")
1415                 {
1416                     {
1417                         json j = 17u;
1418                         json j_new(j.begin(), j.end());
1419                         CHECK(j == j_new);
1420                     }
1421                     {
1422                         json j = 17u;
1423                         json j_new(j.cbegin(), j.cend());
1424                         CHECK(j == j_new);
1425                     }
1426                 }
1427 
1428                 SECTION("number (floating point)")
1429                 {
1430                     {
1431                         json j = 23.42;
1432                         json j_new(j.begin(), j.end());
1433                         CHECK(j == j_new);
1434                     }
1435                     {
1436                         json j = 23.42;
1437                         json j_new(j.cbegin(), j.cend());
1438                         CHECK(j == j_new);
1439                     }
1440                 }
1441             }
1442 
1443             SECTION("construct with two invalid iterators")
1444             {
1445                 SECTION("string")
1446                 {
1447                     {
1448                         json j = "foo";
1449                         CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&);
1450                         CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&);
1451                         CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
1452                         CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
1453                     }
1454                     {
1455                         json j = "bar";
1456                         CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&);
1457                         CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&);
1458                         CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
1459                         CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
1460                     }
1461                 }
1462 
1463                 SECTION("number (boolean)")
1464                 {
1465                     {
1466                         json j = false;
1467                         CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&);
1468                         CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&);
1469                         CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
1470                         CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
1471                     }
1472                     {
1473                         json j = true;
1474                         CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&);
1475                         CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&);
1476                         CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
1477                         CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
1478                     }
1479                 }
1480 
1481                 SECTION("number (integer)")
1482                 {
1483                     {
1484                         json j = 17;
1485                         CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&);
1486                         CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&);
1487                         CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
1488                         CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
1489                     }
1490                     {
1491                         json j = 17;
1492                         CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&);
1493                         CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&);
1494                         CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
1495                         CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
1496                     }
1497                 }
1498 
1499                 SECTION("number (integer)")
1500                 {
1501                     {
1502                         json j = 17u;
1503                         CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&);
1504                         CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&);
1505                         CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
1506                         CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
1507                     }
1508                     {
1509                         json j = 17u;
1510                         CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&);
1511                         CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&);
1512                         CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
1513                         CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
1514                     }
1515                 }
1516 
1517                 SECTION("number (floating point)")
1518                 {
1519                     {
1520                         json j = 23.42;
1521                         CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&);
1522                         CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&);
1523                         CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
1524                         CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
1525                     }
1526                     {
1527                         json j = 23.42;
1528                         CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&);
1529                         CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&);
1530                         CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
1531                         CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
1532                     }
1533                 }
1534             }
1535         }
1536     }
1537 }
1538