]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/json/test/value_to.cpp
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/json
10 // Test that header file is self-contained.
11 #include <boost/json/value_to.hpp>
13 #include "test_suite.hpp"
17 #include <unordered_map>
23 template <class T
, class = void>
24 struct can_apply_value_to
30 struct can_apply_value_to
<T
, detail::void_t
<decltype(
31 value_to
<int>(std::declval
<T
>()))
37 BOOST_STATIC_ASSERT(!can_apply_value_to
<int>::value
);
48 BOOST_TEST(value_to
<T
>(value_from(t
)) == t
);
58 check((unsigned short)1);
59 check((unsigned int)2);
60 check((unsigned long)3);
61 check((unsigned long long)4);
70 value_to
<object
>(value(object_kind
));
71 value_to
<array
>(value(array_kind
));
72 value_to
<string
>(value(string_kind
));
78 check(std::string("test"));
79 check(std::map
<std::string
, int>
81 {"a", 1}, {"b", 2}, {"c", 3}
83 check(std::unordered_map
<std::string
, int>
85 { "a", 1 }, {"b", 2}, {"c", 3}
87 check(std::vector
<int>{1, 2, 3, 4});
88 check(std::make_pair(std::string("test"), 5));
89 check(std::make_tuple(std::string("outer"),
90 std::make_pair(std::string("test"), 5)));
91 check(std::map
<int, int>
93 {2, 4}, {3, 9}, {5, 25}
97 std::array
<int, 1000> arr
;
103 (value_to
<std::tuple
<int, int>>(value
{1, 2, 3})),
104 std::invalid_argument
);
106 (value_to
<std::tuple
<int, int, int, int>>(value
{1, 2, 3})),
107 std::invalid_argument
);
110 (value_to
<std::array
<int, 4>>(value
{1, 2, 3})),
111 std::invalid_argument
);
113 (value_to
<std::array
<int, 4>>(value
{1, 2, 3, 4, 5})),
114 std::invalid_argument
);
126 TEST_SUITE(value_to_test
, "boost.json.value_to");