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