summaryrefslogtreecommitdiff
path: root/modules/core/tests/core.cpp
blob: f418a07366055db519d23ae27193f3b1b4ed12f9 (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "../c++/test/suite.hpp"
#include "../c++/id.hpp"
#include "../c++/string_literal.hpp"
#include "../c++/reduce_templates.hpp"

namespace {
SAW_TEST("ID functionality") {
		using namespace saw;
		struct foo {};

		id<foo> a{1};
		id<foo> b{1};
		id<foo> c{2};

		/** 
		 * The following doesn't compile, so it's commented out as an example
		 */
		/**
		 * struct bar {};
		 *
		 * id<bar> d{1};
		 *
		 * SAW_EXPECT(a == d, "Shouldn't compile");
		 */

		SAW_EXPECT(a == b, "Should be equal");
		SAW_EXPECT(a != c, "Shouldn't be equal");
		SAW_EXPECT(b != c, "Shouldn't be equal");
		SAW_EXPECT(a.get_value() == 1, "Lost original value");
}

SAW_TEST("String Literal Append"){
		using namespace saw;

		constexpr string_literal a = "foo";
		constexpr string_literal b = "bar";
		constexpr string_literal c = a+b;

		SAW_EXPECT(c == "foobar", "CT String sum is not \"foobar\"");
}
	
SAW_TEST("Template Group Reduction"){
	using namespace saw;

	struct foo {
		std::string name = "foo";
	};
	struct bar {
		std::string name = "bar";
	};
	struct baz {
		std::string name = "baz";
	};

	using grp = tmpl_group<foo, bar, baz, foo, bar, foo>;
	using red_grp = tmpl_group<baz, bar, foo>;

	using alg_red_grp = tmpl_reduce<grp>::type;
	
	static_assert(std::is_same_v<alg_red_grp, red_grp>, "Should be same type");
	SAW_EXPECT((std::is_same_v<alg_red_grp, red_grp>), "Should be same type");
}
}