]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/json/test/visit.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / json / test / visit.cpp
CommitLineData
20effc67
TL
1//
2// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3//
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)
6//
7// Official repository: https://github.com/boostorg/json
8//
9
10// Test that header file is self-contained.
11#include <boost/json/visit.hpp>
12
13#include "test_suite.hpp"
14
15BOOST_JSON_NS_BEGIN
16
17class visit_test
18{
19public:
20 template<class T>
21 void
22 check_const(kind k, T t)
23 {
24 struct f
25 {
26 kind k;
27 bool operator()(std::nullptr_t) { return k == kind::null; }
28 bool operator()(bool) { return k == kind::bool_; }
29 bool operator()(std::int64_t) { return k == kind::int64; }
30 bool operator()(std::uint64_t) { return k == kind::uint64; }
31 bool operator()(double) { return k == kind::double_; }
32 bool operator()(string const&) { return k == kind::string; }
33 bool operator()(array const&) { return k == kind::array; }
34 bool operator()(object const&) { return k == kind::object; }
35 bool operator()(...) { return false; }
36 };
37 value const v(t);
38 BOOST_TEST(visit(f{k}, v));
39 }
40
41 template<class T>
42 void
43 check_mutable(kind k, T t)
44 {
45 struct f
46 {
47 kind k;
48 bool operator()(std::nullptr_t) { return k == kind::null; }
49 bool operator()(bool&) { return k == kind::bool_; }
50 bool operator()(std::int64_t&) { return k == kind::int64; }
51 bool operator()(std::uint64_t&) { return k == kind::uint64; }
52 bool operator()(double&) { return k == kind::double_; }
53 bool operator()(string&) { return k == kind::string; }
54 bool operator()(array&) { return k == kind::array; }
55 bool operator()(object&) { return k == kind::object; }
56 bool operator()(...) { return false; }
57 };
58 value v(t);
59 BOOST_TEST(visit(f{k}, v));
60 }
61
62 void
63 testVisit()
64 {
65 check_const(kind::null, nullptr);
66 check_const(kind::bool_, true);
67 check_const(kind::int64, -1);
68 check_const(kind::uint64, 1U);
69 check_const(kind::double_, 3.14);
70 check_const(kind::string, string_kind);
71 check_const(kind::array, array_kind);
72 check_const(kind::object, object_kind);
73
74 check_mutable(kind::null, nullptr);
75 check_mutable(kind::bool_, true);
76 check_mutable(kind::int64, -1);
77 check_mutable(kind::uint64, 1U);
78 check_mutable(kind::double_, 3.14);
79 check_mutable(kind::string, string_kind);
80 check_mutable(kind::array, array_kind);
81 check_mutable(kind::object, object_kind);
82 }
83
84 void run()
85 {
86 testVisit();
87 }
88};
89
90TEST_SUITE(visit_test, "boost.json.visit");
91
92BOOST_JSON_NS_END