aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.match/test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'nihil.match/test.cc')
-rw-r--r--nihil.match/test.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/nihil.match/test.cc b/nihil.match/test.cc
new file mode 100644
index 0000000..7dd1c34
--- /dev/null
+++ b/nihil.match/test.cc
@@ -0,0 +1,34 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+#include <string>
+#include <variant>
+
+#include <catch2/catch_test_macros.hpp>
+
+import nihil.match;
+
+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");
+}