diff options
Diffstat (limited to 'nihil.util/match.test.cc')
| -rw-r--r-- | nihil.util/match.test.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/nihil.util/match.test.cc b/nihil.util/match.test.cc new file mode 100644 index 0000000..6cc0e27 --- /dev/null +++ b/nihil.util/match.test.cc @@ -0,0 +1,32 @@ +// This source code is released into the public domain. + +#include <catch2/catch_test_macros.hpp> + +import nihil.std; +import nihil.util; + +namespace { +TEST_CASE("match", "[nihil]") +{ + using namespace nihil; + using namespace std::literals; + + auto v = std::variant<int, std::string>(42); + + auto s = v | match { + [](int) { return "int"s; }, + [](std::string const &) { return "string"s; } + }; + + REQUIRE(s == "int"); + + v = "test"s; + + s = v | match { + [](int) { return "int"s; }, + [](std::string const &) { return "string"s; } + }; + + REQUIRE(s == "string"); +} +} // anonymous namespace |
