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.config/tests/string.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'nihil.config/tests/string.cc') diff --git a/nihil.config/tests/string.cc b/nihil.config/tests/string.cc index 7e95190..aeb1ef8 100644 --- a/nihil.config/tests/string.cc +++ b/nihil.config/tests/string.cc @@ -12,23 +12,25 @@ TEST_CASE("nihil.config: string option", "[nihil][nihil.config]") { std::string storage; - REQUIRE_THROWS_AS(nihil::config::get_option("test_option"), - nihil::config::unknown_option); + auto opt = nihil::config::get_option("test_option"); + REQUIRE(!opt); { auto string_option = nihil::config::string( storage, "test_option", "This is a test option"); - auto &opt = nihil::config::get_option("test_option"); - REQUIRE(opt.name() == "test_option"); - REQUIRE(opt.description() == "This is a test option"); - REQUIRE(opt.is_default() == true); - REQUIRE(opt.string() == ""); + auto opt = nihil::config::get_option("test_option"); + REQUIRE(opt); - opt.string("testing"); + REQUIRE((*opt)->name() == "test_option"); + REQUIRE((*opt)->description() == "This is a test option"); + REQUIRE((*opt)->is_default() == true); + REQUIRE((*opt)->string() == ""); + + REQUIRE((*opt)->string("testing")); REQUIRE(storage == "testing"); } - REQUIRE_THROWS_AS(nihil::config::get_option("test_option"), - nihil::config::unknown_option); + opt = nihil::config::get_option("test_option"); + REQUIRE(!opt); } -- cgit v1.2.3