aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.ucl/tests/boolean.cc
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-23 00:32:38 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-23 00:32:38 +0100
commit0fa623093366351ad47583f47add6e51f56a56d8 (patch)
tree3eaaa64f5c9b88798d2b971d2810f85cc3e06cd6 /nihil.ucl/tests/boolean.cc
parent8cbb82a1f6eb6605a4615d30922b777e7bf1e4d8 (diff)
downloadnihil-0fa623093366351ad47583f47add6e51f56a56d8.tar.gz
nihil-0fa623093366351ad47583f47add6e51f56a56d8.tar.bz2
nihil.ucl: improve tests
Diffstat (limited to 'nihil.ucl/tests/boolean.cc')
-rw-r--r--nihil.ucl/tests/boolean.cc62
1 files changed, 59 insertions, 3 deletions
diff --git a/nihil.ucl/tests/boolean.cc b/nihil.ucl/tests/boolean.cc
index ed5e1d7..49dc408 100644
--- a/nihil.ucl/tests/boolean.cc
+++ b/nihil.ucl/tests/boolean.cc
@@ -2,16 +2,29 @@
* 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: construct", "[ucl]")
+TEST_CASE("ucl: boolean: invariants", "[ucl]")
{
- auto b = nihil::ucl::boolean(true);
- REQUIRE(b == true);
+ 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]")
@@ -20,6 +33,42 @@ TEST_CASE("ucl: boolean: default construct", "[ucl]")
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);
@@ -54,6 +103,13 @@ TEST_CASE("ucl: boolean: parse", "[ucl]")
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();