1c5f01b2fSopenharmony_ci// __ _____ _____ _____ 2c5f01b2fSopenharmony_ci// __| | __| | | | JSON for Modern C++ (supporting code) 3c5f01b2fSopenharmony_ci// | | |__ | | | | | | version 3.11.2 4c5f01b2fSopenharmony_ci// |_____|_____|_____|_|___| https://github.com/nlohmann/json 5c5f01b2fSopenharmony_ci// 6c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> 7c5f01b2fSopenharmony_ci// SPDX-License-Identifier: MIT 8c5f01b2fSopenharmony_ci 9c5f01b2fSopenharmony_ci#include "doctest_compatibility.h" 10c5f01b2fSopenharmony_ci 11c5f01b2fSopenharmony_ci#define JSON_TESTS_PRIVATE 12c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp> 13c5f01b2fSopenharmony_ciusing nlohmann::json; 14c5f01b2fSopenharmony_ci 15c5f01b2fSopenharmony_citemplate<typename Iter> 16c5f01b2fSopenharmony_ciusing can_post_increment_temporary = decltype((std::declval<Iter>()++)++); 17c5f01b2fSopenharmony_ci 18c5f01b2fSopenharmony_citemplate<typename Iter> 19c5f01b2fSopenharmony_ciusing can_post_decrement_temporary = decltype((std::declval<Iter>()--)--); 20c5f01b2fSopenharmony_ci 21c5f01b2fSopenharmony_ciTEST_CASE("iterator class") 22c5f01b2fSopenharmony_ci{ 23c5f01b2fSopenharmony_ci SECTION("construction") 24c5f01b2fSopenharmony_ci { 25c5f01b2fSopenharmony_ci SECTION("constructor") 26c5f01b2fSopenharmony_ci { 27c5f01b2fSopenharmony_ci SECTION("null") 28c5f01b2fSopenharmony_ci { 29c5f01b2fSopenharmony_ci json j(json::value_t::null); 30c5f01b2fSopenharmony_ci json::iterator it(&j); 31c5f01b2fSopenharmony_ci } 32c5f01b2fSopenharmony_ci 33c5f01b2fSopenharmony_ci SECTION("object") 34c5f01b2fSopenharmony_ci { 35c5f01b2fSopenharmony_ci json j(json::value_t::object); 36c5f01b2fSopenharmony_ci json::iterator it(&j); 37c5f01b2fSopenharmony_ci } 38c5f01b2fSopenharmony_ci 39c5f01b2fSopenharmony_ci SECTION("array") 40c5f01b2fSopenharmony_ci { 41c5f01b2fSopenharmony_ci json j(json::value_t::array); 42c5f01b2fSopenharmony_ci json::iterator it(&j); 43c5f01b2fSopenharmony_ci } 44c5f01b2fSopenharmony_ci } 45c5f01b2fSopenharmony_ci 46c5f01b2fSopenharmony_ci SECTION("copy assignment") 47c5f01b2fSopenharmony_ci { 48c5f01b2fSopenharmony_ci json j(json::value_t::null); 49c5f01b2fSopenharmony_ci json::iterator it(&j); 50c5f01b2fSopenharmony_ci json::iterator it2(&j); 51c5f01b2fSopenharmony_ci it2 = it; 52c5f01b2fSopenharmony_ci } 53c5f01b2fSopenharmony_ci } 54c5f01b2fSopenharmony_ci 55c5f01b2fSopenharmony_ci SECTION("initialization") 56c5f01b2fSopenharmony_ci { 57c5f01b2fSopenharmony_ci SECTION("set_begin") 58c5f01b2fSopenharmony_ci { 59c5f01b2fSopenharmony_ci SECTION("null") 60c5f01b2fSopenharmony_ci { 61c5f01b2fSopenharmony_ci json j(json::value_t::null); 62c5f01b2fSopenharmony_ci json::iterator it(&j); 63c5f01b2fSopenharmony_ci it.set_begin(); 64c5f01b2fSopenharmony_ci CHECK((it == j.begin())); 65c5f01b2fSopenharmony_ci } 66c5f01b2fSopenharmony_ci 67c5f01b2fSopenharmony_ci SECTION("object") 68c5f01b2fSopenharmony_ci { 69c5f01b2fSopenharmony_ci json j(json::value_t::object); 70c5f01b2fSopenharmony_ci json::iterator it(&j); 71c5f01b2fSopenharmony_ci it.set_begin(); 72c5f01b2fSopenharmony_ci CHECK((it == j.begin())); 73c5f01b2fSopenharmony_ci } 74c5f01b2fSopenharmony_ci 75c5f01b2fSopenharmony_ci SECTION("array") 76c5f01b2fSopenharmony_ci { 77c5f01b2fSopenharmony_ci json j(json::value_t::array); 78c5f01b2fSopenharmony_ci json::iterator it(&j); 79c5f01b2fSopenharmony_ci it.set_begin(); 80c5f01b2fSopenharmony_ci CHECK((it == j.begin())); 81c5f01b2fSopenharmony_ci } 82c5f01b2fSopenharmony_ci } 83c5f01b2fSopenharmony_ci 84c5f01b2fSopenharmony_ci SECTION("set_end") 85c5f01b2fSopenharmony_ci { 86c5f01b2fSopenharmony_ci SECTION("null") 87c5f01b2fSopenharmony_ci { 88c5f01b2fSopenharmony_ci json j(json::value_t::null); 89c5f01b2fSopenharmony_ci json::iterator it(&j); 90c5f01b2fSopenharmony_ci it.set_end(); 91c5f01b2fSopenharmony_ci CHECK((it == j.end())); 92c5f01b2fSopenharmony_ci } 93c5f01b2fSopenharmony_ci 94c5f01b2fSopenharmony_ci SECTION("object") 95c5f01b2fSopenharmony_ci { 96c5f01b2fSopenharmony_ci json j(json::value_t::object); 97c5f01b2fSopenharmony_ci json::iterator it(&j); 98c5f01b2fSopenharmony_ci it.set_end(); 99c5f01b2fSopenharmony_ci CHECK((it == j.end())); 100c5f01b2fSopenharmony_ci } 101c5f01b2fSopenharmony_ci 102c5f01b2fSopenharmony_ci SECTION("array") 103c5f01b2fSopenharmony_ci { 104c5f01b2fSopenharmony_ci json j(json::value_t::array); 105c5f01b2fSopenharmony_ci json::iterator it(&j); 106c5f01b2fSopenharmony_ci it.set_end(); 107c5f01b2fSopenharmony_ci CHECK((it == j.end())); 108c5f01b2fSopenharmony_ci } 109c5f01b2fSopenharmony_ci } 110c5f01b2fSopenharmony_ci } 111c5f01b2fSopenharmony_ci 112c5f01b2fSopenharmony_ci SECTION("element access") 113c5f01b2fSopenharmony_ci { 114c5f01b2fSopenharmony_ci SECTION("operator*") 115c5f01b2fSopenharmony_ci { 116c5f01b2fSopenharmony_ci SECTION("null") 117c5f01b2fSopenharmony_ci { 118c5f01b2fSopenharmony_ci json j(json::value_t::null); 119c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 120c5f01b2fSopenharmony_ci CHECK_THROWS_WITH_AS(*it, "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&); 121c5f01b2fSopenharmony_ci } 122c5f01b2fSopenharmony_ci 123c5f01b2fSopenharmony_ci SECTION("number") 124c5f01b2fSopenharmony_ci { 125c5f01b2fSopenharmony_ci json j(17); 126c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 127c5f01b2fSopenharmony_ci CHECK(*it == json(17)); 128c5f01b2fSopenharmony_ci it = j.end(); 129c5f01b2fSopenharmony_ci CHECK_THROWS_WITH_AS(*it, "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&); 130c5f01b2fSopenharmony_ci } 131c5f01b2fSopenharmony_ci 132c5f01b2fSopenharmony_ci SECTION("object") 133c5f01b2fSopenharmony_ci { 134c5f01b2fSopenharmony_ci json j({{"foo", "bar"}}); 135c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 136c5f01b2fSopenharmony_ci CHECK(*it == json("bar")); 137c5f01b2fSopenharmony_ci } 138c5f01b2fSopenharmony_ci 139c5f01b2fSopenharmony_ci SECTION("array") 140c5f01b2fSopenharmony_ci { 141c5f01b2fSopenharmony_ci json j({1, 2, 3, 4}); 142c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 143c5f01b2fSopenharmony_ci CHECK(*it == json(1)); 144c5f01b2fSopenharmony_ci } 145c5f01b2fSopenharmony_ci } 146c5f01b2fSopenharmony_ci 147c5f01b2fSopenharmony_ci SECTION("operator->") 148c5f01b2fSopenharmony_ci { 149c5f01b2fSopenharmony_ci SECTION("null") 150c5f01b2fSopenharmony_ci { 151c5f01b2fSopenharmony_ci json j(json::value_t::null); 152c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 153c5f01b2fSopenharmony_ci CHECK_THROWS_WITH_AS(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&); 154c5f01b2fSopenharmony_ci } 155c5f01b2fSopenharmony_ci 156c5f01b2fSopenharmony_ci SECTION("number") 157c5f01b2fSopenharmony_ci { 158c5f01b2fSopenharmony_ci json j(17); 159c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 160c5f01b2fSopenharmony_ci CHECK(std::string(it->type_name()) == "number"); 161c5f01b2fSopenharmony_ci it = j.end(); 162c5f01b2fSopenharmony_ci CHECK_THROWS_WITH_AS(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&); 163c5f01b2fSopenharmony_ci } 164c5f01b2fSopenharmony_ci 165c5f01b2fSopenharmony_ci SECTION("object") 166c5f01b2fSopenharmony_ci { 167c5f01b2fSopenharmony_ci json j({{"foo", "bar"}}); 168c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 169c5f01b2fSopenharmony_ci CHECK(std::string(it->type_name()) == "string"); 170c5f01b2fSopenharmony_ci } 171c5f01b2fSopenharmony_ci 172c5f01b2fSopenharmony_ci SECTION("array") 173c5f01b2fSopenharmony_ci { 174c5f01b2fSopenharmony_ci json j({1, 2, 3, 4}); 175c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 176c5f01b2fSopenharmony_ci CHECK(std::string(it->type_name()) == "number"); 177c5f01b2fSopenharmony_ci } 178c5f01b2fSopenharmony_ci } 179c5f01b2fSopenharmony_ci } 180c5f01b2fSopenharmony_ci 181c5f01b2fSopenharmony_ci SECTION("increment/decrement") 182c5f01b2fSopenharmony_ci { 183c5f01b2fSopenharmony_ci SECTION("post-increment") 184c5f01b2fSopenharmony_ci { 185c5f01b2fSopenharmony_ci SECTION("null") 186c5f01b2fSopenharmony_ci { 187c5f01b2fSopenharmony_ci json j(json::value_t::null); 188c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 189c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 1)); 190c5f01b2fSopenharmony_ci it++; 191c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); 192c5f01b2fSopenharmony_ci } 193c5f01b2fSopenharmony_ci 194c5f01b2fSopenharmony_ci SECTION("number") 195c5f01b2fSopenharmony_ci { 196c5f01b2fSopenharmony_ci json j(17); 197c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 198c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 0)); 199c5f01b2fSopenharmony_ci it++; 200c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 1)); 201c5f01b2fSopenharmony_ci it++; 202c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); 203c5f01b2fSopenharmony_ci } 204c5f01b2fSopenharmony_ci 205c5f01b2fSopenharmony_ci SECTION("object") 206c5f01b2fSopenharmony_ci { 207c5f01b2fSopenharmony_ci json j({{"foo", "bar"}}); 208c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 209c5f01b2fSopenharmony_ci CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin())); 210c5f01b2fSopenharmony_ci it++; 211c5f01b2fSopenharmony_ci CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end())); 212c5f01b2fSopenharmony_ci } 213c5f01b2fSopenharmony_ci 214c5f01b2fSopenharmony_ci SECTION("array") 215c5f01b2fSopenharmony_ci { 216c5f01b2fSopenharmony_ci json j({1, 2, 3, 4}); 217c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 218c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin())); 219c5f01b2fSopenharmony_ci it++; 220c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 221c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 222c5f01b2fSopenharmony_ci it++; 223c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 224c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 225c5f01b2fSopenharmony_ci it++; 226c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 227c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 228c5f01b2fSopenharmony_ci it++; 229c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 230c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end())); 231c5f01b2fSopenharmony_ci } 232c5f01b2fSopenharmony_ci } 233c5f01b2fSopenharmony_ci 234c5f01b2fSopenharmony_ci SECTION("pre-increment") 235c5f01b2fSopenharmony_ci { 236c5f01b2fSopenharmony_ci SECTION("null") 237c5f01b2fSopenharmony_ci { 238c5f01b2fSopenharmony_ci json j(json::value_t::null); 239c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 240c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 1)); 241c5f01b2fSopenharmony_ci ++it; 242c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); 243c5f01b2fSopenharmony_ci } 244c5f01b2fSopenharmony_ci 245c5f01b2fSopenharmony_ci SECTION("number") 246c5f01b2fSopenharmony_ci { 247c5f01b2fSopenharmony_ci json j(17); 248c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 249c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 0)); 250c5f01b2fSopenharmony_ci ++it; 251c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 1)); 252c5f01b2fSopenharmony_ci ++it; 253c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); 254c5f01b2fSopenharmony_ci } 255c5f01b2fSopenharmony_ci 256c5f01b2fSopenharmony_ci SECTION("object") 257c5f01b2fSopenharmony_ci { 258c5f01b2fSopenharmony_ci json j({{"foo", "bar"}}); 259c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 260c5f01b2fSopenharmony_ci CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin())); 261c5f01b2fSopenharmony_ci ++it; 262c5f01b2fSopenharmony_ci CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end())); 263c5f01b2fSopenharmony_ci } 264c5f01b2fSopenharmony_ci 265c5f01b2fSopenharmony_ci SECTION("array") 266c5f01b2fSopenharmony_ci { 267c5f01b2fSopenharmony_ci json j({1, 2, 3, 4}); 268c5f01b2fSopenharmony_ci json::iterator it = j.begin(); 269c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin())); 270c5f01b2fSopenharmony_ci ++it; 271c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 272c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 273c5f01b2fSopenharmony_ci ++it; 274c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 275c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 276c5f01b2fSopenharmony_ci ++it; 277c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 278c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 279c5f01b2fSopenharmony_ci ++it; 280c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 281c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end())); 282c5f01b2fSopenharmony_ci } 283c5f01b2fSopenharmony_ci } 284c5f01b2fSopenharmony_ci 285c5f01b2fSopenharmony_ci SECTION("post-decrement") 286c5f01b2fSopenharmony_ci { 287c5f01b2fSopenharmony_ci SECTION("null") 288c5f01b2fSopenharmony_ci { 289c5f01b2fSopenharmony_ci json j(json::value_t::null); 290c5f01b2fSopenharmony_ci json::iterator it = j.end(); 291c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 1)); 292c5f01b2fSopenharmony_ci } 293c5f01b2fSopenharmony_ci 294c5f01b2fSopenharmony_ci SECTION("number") 295c5f01b2fSopenharmony_ci { 296c5f01b2fSopenharmony_ci json j(17); 297c5f01b2fSopenharmony_ci json::iterator it = j.end(); 298c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 1)); 299c5f01b2fSopenharmony_ci it--; 300c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 0)); 301c5f01b2fSopenharmony_ci it--; 302c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); 303c5f01b2fSopenharmony_ci } 304c5f01b2fSopenharmony_ci 305c5f01b2fSopenharmony_ci SECTION("object") 306c5f01b2fSopenharmony_ci { 307c5f01b2fSopenharmony_ci json j({{"foo", "bar"}}); 308c5f01b2fSopenharmony_ci json::iterator it = j.end(); 309c5f01b2fSopenharmony_ci CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end())); 310c5f01b2fSopenharmony_ci it--; 311c5f01b2fSopenharmony_ci CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin())); 312c5f01b2fSopenharmony_ci } 313c5f01b2fSopenharmony_ci 314c5f01b2fSopenharmony_ci SECTION("array") 315c5f01b2fSopenharmony_ci { 316c5f01b2fSopenharmony_ci json j({1, 2, 3, 4}); 317c5f01b2fSopenharmony_ci json::iterator it = j.end(); 318c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end())); 319c5f01b2fSopenharmony_ci it--; 320c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 321c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 322c5f01b2fSopenharmony_ci it--; 323c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 324c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 325c5f01b2fSopenharmony_ci it--; 326c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 327c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 328c5f01b2fSopenharmony_ci it--; 329c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin())); 330c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 331c5f01b2fSopenharmony_ci } 332c5f01b2fSopenharmony_ci } 333c5f01b2fSopenharmony_ci 334c5f01b2fSopenharmony_ci SECTION("pre-decrement") 335c5f01b2fSopenharmony_ci { 336c5f01b2fSopenharmony_ci SECTION("null") 337c5f01b2fSopenharmony_ci { 338c5f01b2fSopenharmony_ci json j(json::value_t::null); 339c5f01b2fSopenharmony_ci json::iterator it = j.end(); 340c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 1)); 341c5f01b2fSopenharmony_ci } 342c5f01b2fSopenharmony_ci 343c5f01b2fSopenharmony_ci SECTION("number") 344c5f01b2fSopenharmony_ci { 345c5f01b2fSopenharmony_ci json j(17); 346c5f01b2fSopenharmony_ci json::iterator it = j.end(); 347c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 1)); 348c5f01b2fSopenharmony_ci --it; 349c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it == 0)); 350c5f01b2fSopenharmony_ci --it; 351c5f01b2fSopenharmony_ci CHECK((it.m_it.primitive_iterator.m_it != 0 && it.m_it.primitive_iterator.m_it != 1)); 352c5f01b2fSopenharmony_ci } 353c5f01b2fSopenharmony_ci 354c5f01b2fSopenharmony_ci SECTION("object") 355c5f01b2fSopenharmony_ci { 356c5f01b2fSopenharmony_ci json j({{"foo", "bar"}}); 357c5f01b2fSopenharmony_ci json::iterator it = j.end(); 358c5f01b2fSopenharmony_ci CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end())); 359c5f01b2fSopenharmony_ci --it; 360c5f01b2fSopenharmony_ci CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin())); 361c5f01b2fSopenharmony_ci } 362c5f01b2fSopenharmony_ci 363c5f01b2fSopenharmony_ci SECTION("array") 364c5f01b2fSopenharmony_ci { 365c5f01b2fSopenharmony_ci json j({1, 2, 3, 4}); 366c5f01b2fSopenharmony_ci json::iterator it = j.end(); 367c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end())); 368c5f01b2fSopenharmony_ci --it; 369c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 370c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 371c5f01b2fSopenharmony_ci --it; 372c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 373c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 374c5f01b2fSopenharmony_ci --it; 375c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin())); 376c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 377c5f01b2fSopenharmony_ci --it; 378c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin())); 379c5f01b2fSopenharmony_ci CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end())); 380c5f01b2fSopenharmony_ci } 381c5f01b2fSopenharmony_ci } 382c5f01b2fSopenharmony_ci } 383c5f01b2fSopenharmony_ci SECTION("equality-preserving") 384c5f01b2fSopenharmony_ci { 385c5f01b2fSopenharmony_ci SECTION("post-increment") 386c5f01b2fSopenharmony_ci { 387c5f01b2fSopenharmony_ci SECTION("primitive_iterator_t") 388c5f01b2fSopenharmony_ci { 389c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::primitive_iterator_t; 390c5f01b2fSopenharmony_ci CHECK(std::is_same < decltype(std::declval<Iter&>()++), Iter >::value); 391c5f01b2fSopenharmony_ci } 392c5f01b2fSopenharmony_ci SECTION("iter_impl") 393c5f01b2fSopenharmony_ci { 394c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::iter_impl<json>; 395c5f01b2fSopenharmony_ci CHECK(std::is_same < decltype(std::declval<Iter&>()++), Iter >::value); 396c5f01b2fSopenharmony_ci } 397c5f01b2fSopenharmony_ci SECTION("json_reverse_iterator") 398c5f01b2fSopenharmony_ci { 399c5f01b2fSopenharmony_ci using Base = nlohmann::detail::iter_impl<json>; 400c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::json_reverse_iterator<Base>; 401c5f01b2fSopenharmony_ci CHECK(std::is_same < decltype(std::declval<Iter&>()++), Iter >::value); 402c5f01b2fSopenharmony_ci } 403c5f01b2fSopenharmony_ci } 404c5f01b2fSopenharmony_ci SECTION("post-decrement") 405c5f01b2fSopenharmony_ci { 406c5f01b2fSopenharmony_ci SECTION("primitive_iterator_t") 407c5f01b2fSopenharmony_ci { 408c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::primitive_iterator_t; 409c5f01b2fSopenharmony_ci CHECK(std::is_same < decltype(std::declval<Iter&>()--), Iter >::value); 410c5f01b2fSopenharmony_ci } 411c5f01b2fSopenharmony_ci SECTION("iter_impl") 412c5f01b2fSopenharmony_ci { 413c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::iter_impl<json>; 414c5f01b2fSopenharmony_ci CHECK(std::is_same < decltype(std::declval<Iter&>()--), Iter >::value ); 415c5f01b2fSopenharmony_ci } 416c5f01b2fSopenharmony_ci SECTION("json_reverse_iterator") 417c5f01b2fSopenharmony_ci { 418c5f01b2fSopenharmony_ci using Base = nlohmann::detail::iter_impl<json>; 419c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::json_reverse_iterator<Base>; 420c5f01b2fSopenharmony_ci CHECK(std::is_same < decltype(std::declval<Iter&>()--), Iter >::value ); 421c5f01b2fSopenharmony_ci } 422c5f01b2fSopenharmony_ci } 423c5f01b2fSopenharmony_ci } 424c5f01b2fSopenharmony_ci // prevent "accidental mutation of a temporary object" 425c5f01b2fSopenharmony_ci SECTION("cert-dcl21-cpp") 426c5f01b2fSopenharmony_ci { 427c5f01b2fSopenharmony_ci using nlohmann::detail::is_detected; 428c5f01b2fSopenharmony_ci SECTION("post-increment") 429c5f01b2fSopenharmony_ci { 430c5f01b2fSopenharmony_ci SECTION("primitive_iterator_t") 431c5f01b2fSopenharmony_ci { 432c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::primitive_iterator_t; 433c5f01b2fSopenharmony_ci CHECK_FALSE(is_detected<can_post_increment_temporary, Iter&>::value); 434c5f01b2fSopenharmony_ci } 435c5f01b2fSopenharmony_ci SECTION("iter_impl") 436c5f01b2fSopenharmony_ci { 437c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::iter_impl<json>; 438c5f01b2fSopenharmony_ci CHECK_FALSE(is_detected<can_post_increment_temporary, Iter&>::value); 439c5f01b2fSopenharmony_ci } 440c5f01b2fSopenharmony_ci SECTION("json_reverse_iterator") 441c5f01b2fSopenharmony_ci { 442c5f01b2fSopenharmony_ci using Base = nlohmann::detail::iter_impl<json>; 443c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::json_reverse_iterator<Base>; 444c5f01b2fSopenharmony_ci CHECK_FALSE(is_detected<can_post_increment_temporary, Iter&>::value); 445c5f01b2fSopenharmony_ci } 446c5f01b2fSopenharmony_ci } 447c5f01b2fSopenharmony_ci SECTION("post-decrement") 448c5f01b2fSopenharmony_ci { 449c5f01b2fSopenharmony_ci SECTION("primitive_iterator_t") 450c5f01b2fSopenharmony_ci { 451c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::primitive_iterator_t; 452c5f01b2fSopenharmony_ci CHECK_FALSE(is_detected<can_post_decrement_temporary, Iter&>::value); 453c5f01b2fSopenharmony_ci } 454c5f01b2fSopenharmony_ci SECTION("iter_impl") 455c5f01b2fSopenharmony_ci { 456c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::iter_impl<json>; 457c5f01b2fSopenharmony_ci CHECK_FALSE(is_detected<can_post_decrement_temporary, Iter&>::value); 458c5f01b2fSopenharmony_ci } 459c5f01b2fSopenharmony_ci SECTION("json_reverse_iterator") 460c5f01b2fSopenharmony_ci { 461c5f01b2fSopenharmony_ci using Base = nlohmann::detail::iter_impl<json>; 462c5f01b2fSopenharmony_ci using Iter = nlohmann::detail::json_reverse_iterator<Base>; 463c5f01b2fSopenharmony_ci CHECK_FALSE(is_detected<can_post_decrement_temporary, Iter&>::value); 464c5f01b2fSopenharmony_ci } 465c5f01b2fSopenharmony_ci 466c5f01b2fSopenharmony_ci } 467c5f01b2fSopenharmony_ci } 468c5f01b2fSopenharmony_ci} 469