From 90aa957ca9b7c217af7569009d1675e0f3ff8e9b Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Thu, 26 Jun 2025 20:47:45 +0100 Subject: ucl, config: use monadic error handling more --- nihil.ucl/tests/emit.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'nihil.ucl/tests/emit.cc') 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" -- cgit v1.2.3