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 #include <nlohmann/json.hpp> 33 using nlohmann::json; 34 35 TEST_CASE("concepts") 36 { 37 SECTION("container requirements for json") 38 { 39 // X: container class: json 40 // T: type of objects: json 41 // a, b: values of type X: json 42 43 // TABLE 96 - Container Requirements 44 45 // X::value_type must return T 46 CHECK((std::is_same<json::value_type, json>::value)); 47 48 // X::reference must return lvalue of T 49 CHECK((std::is_same<json::reference, json&>::value)); 50 51 // X::const_reference must return const lvalue of T 52 CHECK((std::is_same<json::const_reference, const json&>::value)); 53 54 // X::iterator must return iterator whose value_type is T 55 CHECK((std::is_same<json::iterator::value_type, json>::value)); 56 // X::iterator must meet the forward iterator requirements 57 CHECK((std::is_base_of<std::forward_iterator_tag, typename std::iterator_traits<json::iterator>::iterator_category>::value)); 58 // X::iterator must be convertible to X::const_iterator 59 CHECK((std::is_convertible<json::iterator, json::const_iterator>::value)); 60 61 // X::const_iterator must return iterator whose value_type is T 62 CHECK((std::is_same<json::const_iterator::value_type, json>::value)); 63 // X::const_iterator must meet the forward iterator requirements 64 CHECK((std::is_base_of<std::forward_iterator_tag, typename std::iterator_traits<json::const_iterator>::iterator_category>::value)); 65 66 // X::difference_type must return a signed integer 67 CHECK((std::is_signed<json::difference_type>::value)); 68 // X::difference_type must be identical to X::iterator::difference_type 69 CHECK((std::is_same<json::difference_type, json::iterator::difference_type>::value)); 70 // X::difference_type must be identical to X::const_iterator::difference_type 71 CHECK((std::is_same<json::difference_type, json::const_iterator::difference_type>::value)); 72 73 // X::size_type must return an unsigned integer 74 CHECK((std::is_unsigned<json::size_type>::value)); 75 // X::size_type can represent any non-negative value of X::difference_type 76 CHECK(static_cast<json::size_type>((std::numeric_limits<json::difference_type>::max)()) <= 77 (std::numeric_limits<json::size_type>::max)()); 78 79 // the expression "X u" has the post-condition "u.empty()" 80 { 81 json u; 82 CHECK(u.empty()); 83 } 84 85 // the expression "X()" has the post-condition "X().empty()" 86 CHECK(json().empty()); 87 } 88 89 SECTION("class json") 90 { 91 SECTION("DefaultConstructible") 92 { 93 CHECK(std::is_nothrow_default_constructible<json>::value); 94 } 95 96 SECTION("MoveConstructible") 97 { 98 CHECK(std::is_move_constructible<json>::value); 99 CHECK(std::is_nothrow_move_constructible<json>::value); 100 } 101 102 SECTION("CopyConstructible") 103 { 104 CHECK(std::is_copy_constructible<json>::value); 105 } 106 107 SECTION("MoveAssignable") 108 { 109 CHECK(std::is_nothrow_move_assignable<json>::value); 110 } 111 112 SECTION("CopyAssignable") 113 { 114 CHECK(std::is_copy_assignable<json>::value); 115 } 116 117 SECTION("Destructible") 118 { 119 CHECK(std::is_nothrow_destructible<json>::value); 120 } 121 122 SECTION("StandardLayoutType") 123 { 124 CHECK(std::is_standard_layout<json>::value); 125 } 126 } 127 128 SECTION("class iterator") 129 { 130 SECTION("CopyConstructible") 131 { 132 CHECK(std::is_nothrow_copy_constructible<json::iterator>::value); 133 CHECK(std::is_nothrow_copy_constructible<json::const_iterator>::value); 134 } 135 136 SECTION("CopyAssignable") 137 { 138 // STL iterators used by json::iterator don't pass this test in Debug mode 139 #if !defined(_MSC_VER) || (_ITERATOR_DEBUG_LEVEL == 0) 140 CHECK(std::is_nothrow_copy_assignable<json::iterator>::value); 141 CHECK(std::is_nothrow_copy_assignable<json::const_iterator>::value); 142 #endif 143 } 144 145 SECTION("Destructible") 146 { 147 CHECK(std::is_nothrow_destructible<json::iterator>::value); 148 CHECK(std::is_nothrow_destructible<json::const_iterator>::value); 149 } 150 151 SECTION("Swappable") 152 { 153 { 154 json j {1, 2, 3}; 155 json::iterator it1 = j.begin(); 156 json::iterator it2 = j.end(); 157 swap(it1, it2); 158 CHECK(it1 == j.end()); 159 CHECK(it2 == j.begin()); 160 } 161 { 162 json j {1, 2, 3}; 163 json::const_iterator it1 = j.cbegin(); 164 json::const_iterator it2 = j.cend(); 165 swap(it1, it2); 166 CHECK(it1 == j.end()); 167 CHECK(it2 == j.begin()); 168 } 169 } 170 } 171 } 172