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