aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.core/match.test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'nihil.core/match.test.cc')
-rw-r--r--nihil.core/match.test.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/nihil.core/match.test.cc b/nihil.core/match.test.cc
new file mode 100644
index 0000000..2394651
--- /dev/null
+++ b/nihil.core/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.core;
+
+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