1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* This source code is released into the public domain.
*/
#include <concepts>
#include <string>
#include <catch2/catch_test_macros.hpp>
#include <ucl.h>
import nihil.ucl;
TEST_CASE("ucl: boolean: invariants", "[ucl]")
{
using namespace nihil::ucl;
static_assert(std::same_as<bool, boolean::contained_type>);
REQUIRE(boolean::ucl_type == object_type::boolean);
REQUIRE(static_cast<::ucl_type>(boolean::ucl_type) == UCL_BOOLEAN);
static_assert(std::destructible<boolean>);
static_assert(std::default_initializable<boolean>);
static_assert(std::move_constructible<boolean>);
static_assert(std::copy_constructible<boolean>);
static_assert(std::equality_comparable<boolean>);
static_assert(std::totally_ordered<boolean>);
static_assert(std::swappable<boolean>);
}
TEST_CASE("ucl: boolean: default construct", "[ucl]")
{
auto b = nihil::ucl::boolean();
REQUIRE(b == false);
}
TEST_CASE("ucl: boolean: construct from value", "[ucl]")
{
auto b = nihil::ucl::boolean(true);
REQUIRE(b == true);
}
TEST_CASE("ucl: boolean: swap", "[ucl]")
{
// do not add using namespace nihil::ucl
auto b1 = nihil::ucl::boolean(true);
auto b2 = nihil::ucl::boolean(false);
swap(b1, b2);
REQUIRE(b1 == false);
REQUIRE(b2 == true);
}
TEST_CASE("ucl: boolean: value()", "[ucl]")
{
auto b = nihil::ucl::boolean(true);
REQUIRE(b.value() == true);
}
TEST_CASE("ucl: boolean: key()", "[ucl]")
{
using namespace nihil::ucl;
auto obj = parse("a_bool = true");
REQUIRE(object_cast<boolean>(obj["a_bool"]).key() == "a_bool");
auto b = nihil::ucl::boolean(true);
REQUIRE(b.key() == "");
}
TEST_CASE("ucl: boolean: operator==", "[ucl]")
{
auto b = nihil::ucl::boolean(true);
REQUIRE(b == true);
REQUIRE(b == nihil::ucl::boolean(true));
REQUIRE(b != false);
REQUIRE(b != nihil::ucl::boolean(false));
}
TEST_CASE("ucl: boolean: operator<=>", "[ucl]")
{
auto b = nihil::ucl::boolean(false);
REQUIRE(b < true);
REQUIRE(b < nihil::ucl::boolean(true));
REQUIRE(b >= false);
REQUIRE(b >= nihil::ucl::boolean(false));
}
TEST_CASE("ucl: boolean: parse", "[ucl]")
{
using namespace std::literals;
auto obj = nihil::ucl::parse("value = true"sv);
auto v = obj["value"];
REQUIRE(v.key() == "value");
REQUIRE(object_cast<nihil::ucl::boolean>(v) == true);
}
TEST_CASE("ucl: boolean: emit", "[ucl]")
{
auto b = nihil::ucl::boolean(true);
auto str = std::format("{}", b);
REQUIRE(str == "true");
}
TEST_CASE("ucl: boolean: parse and emit", "[ucl]")
{
auto ucl = nihil::ucl::parse("bool = true;");
auto output = std::string();
emit(ucl, nihil::ucl::emitter::configuration,
std::back_inserter(output));
REQUIRE(output == "bool = true;\n");
}
|