aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.match/test.cc
blob: 974a58a7f670b3480204791822a4c5392497082b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// This source code is released into the public domain.

#include <catch2/catch_test_macros.hpp>

import nihil.std;
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");
}