From a4607e29540a9352c35afff17193ceeab137cc9d Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Wed, 2 Jul 2025 03:25:28 +0100 Subject: move monad to util --- nihil.monad/test.cc | 64 ----------------------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 nihil.monad/test.cc (limited to 'nihil.monad/test.cc') diff --git a/nihil.monad/test.cc b/nihil.monad/test.cc deleted file mode 100644 index 2cc743c..0000000 --- a/nihil.monad/test.cc +++ /dev/null @@ -1,64 +0,0 @@ -// This source code is released into the public domain. - -#include - -import nihil.std; -import nihil.error; -import nihil.monad; - -TEST_CASE("monad: co_await std::optional<> with value", "[nihil]") -{ - auto get_value = [] -> std::optional { - return 42; - }; - - auto try_get_value = [&get_value] -> std::optional { - co_return co_await get_value(); - }; - - auto o = try_get_value(); - REQUIRE(o == 42); -} - -TEST_CASE("monad: co_await std::optional<> without value", "[nihil]") -{ - auto get_value = [] -> std::optional { - return {}; - }; - - auto try_get_value = [&get_value] -> std::optional { - co_return co_await get_value(); - }; - - auto o = try_get_value(); - REQUIRE(!o.has_value()); -} - -TEST_CASE("monad: co_await std::expected<> with value", "[nihil]") -{ - auto get_value = [] -> std::expected { - return 42; - }; - - auto try_get_value = [&get_value] -> std::expected { - co_return co_await get_value(); - }; - - auto o = try_get_value(); - REQUIRE(o == 42); -} - -TEST_CASE("monad: co_await std::expected<> with error", "[nihil]") -{ - auto get_value = [] -> std::expected { - return std::unexpected("error"); - }; - - auto try_get_value = [&get_value] -> std::expected { - co_return co_await get_value(); - }; - - auto o = try_get_value(); - REQUIRE(!o); - REQUIRE(o.error() == "error"); -} -- cgit v1.2.3