aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.ucl/tests/emit.cc
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-26 20:47:45 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-26 20:47:45 +0100
commit90aa957ca9b7c217af7569009d1675e0f3ff8e9b (patch)
treee6a61ca2b6928e6414372b9b1484ce80fa2fb0b3 /nihil.ucl/tests/emit.cc
parent1db86c401df11423c945634d8b2a483e97afa878 (diff)
downloadnihil-90aa957ca9b7c217af7569009d1675e0f3ff8e9b.tar.gz
nihil-90aa957ca9b7c217af7569009d1675e0f3ff8e9b.tar.bz2
ucl, config: use monadic error handling more
Diffstat (limited to 'nihil.ucl/tests/emit.cc')
-rw-r--r--nihil.ucl/tests/emit.cc24
1 files changed, 17 insertions, 7 deletions
diff --git a/nihil.ucl/tests/emit.cc b/nihil.ucl/tests/emit.cc
index a8487c6..d75255b 100644
--- a/nihil.ucl/tests/emit.cc
+++ b/nihil.ucl/tests/emit.cc
@@ -15,11 +15,13 @@ TEST_CASE("ucl: emit to std::ostream", "[ucl]")
using namespace std::literals;
auto obj = nihil::ucl::parse("int = [1, 42, 666]"sv);
+ REQUIRE(obj);
+
auto strm = std::ostringstream();
- strm << obj;
+ strm << *obj;
// The ostream emitter produces JSON.
- REQUIRE(strm.str() == std::format("{:j}", obj));
+ REQUIRE(strm.str() == std::format("{:j}", *obj));
}
TEST_CASE("ucl: emit JSON with std::format", "[ucl]")
@@ -27,7 +29,9 @@ TEST_CASE("ucl: emit JSON with std::format", "[ucl]")
using namespace std::literals;
auto obj = nihil::ucl::parse("int = [1, 42, 666]"sv);
- auto str = std::format("{:j}", obj);
+ REQUIRE(obj);
+
+ auto str = std::format("{:j}", *obj);
REQUIRE(str ==
"{\n"
@@ -39,7 +43,7 @@ TEST_CASE("ucl: emit JSON with std::format", "[ucl]")
"}");
// Make sure JSON is the default format.
- auto str2 = std::format("{}", obj);
+ auto str2 = std::format("{}", *obj);
REQUIRE(str == str2);
}
@@ -48,7 +52,9 @@ TEST_CASE("ucl: emit compact JSON with std::format", "[ucl]")
using namespace std::literals;
auto obj = nihil::ucl::parse("int = [1, 42, 666]"sv);
- auto str = std::format("{:J}", obj);
+ REQUIRE(obj);
+
+ auto str = std::format("{:J}", *obj);
REQUIRE(str == "{\"int\":[1,42,666]}");
}
@@ -58,7 +64,9 @@ TEST_CASE("ucl: emit configuration with std::format", "[ucl]")
using namespace std::literals;
auto obj = nihil::ucl::parse("int = [1, 42, 666]"sv);
- auto str = std::format("{:c}", obj);
+ REQUIRE(obj);
+
+ auto str = std::format("{:c}", *obj);
REQUIRE(str ==
"int [\n"
@@ -73,7 +81,9 @@ TEST_CASE("ucl: emit YAML with std::format", "[ucl]")
using namespace std::literals;
auto obj = nihil::ucl::parse("int = [1, 42, 666]"sv);
- auto str = std::format("{:y}", obj);
+ REQUIRE(obj);
+
+ auto str = std::format("{:y}", *obj);
REQUIRE(str ==
"int: [\n"