aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.match/test.cc
blob: 7dd1c34d2689f88831be88e64085ada2ee4fefff (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
31
32
33
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");
}