Echo Writes Code

test_utility.cpp

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
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "crucible/core.hpp"
#include "crucible/test.hpp"

namespace crucible
{
	// Preprocessor concatenation
	constexpr int CRUCIBLE_COMBINE4(PP_, A, B, C) = 5;
	static_assert(PP_ABC == 5);
	constexpr int CRUCIBLE_COMBINE3(PP_, A, B) = 15;
	static_assert(PP_AB == 15);
	constexpr int CRUCIBLE_COMBINE2(PP_, A) = 25;
	static_assert(PP_A == 25);

	// Preprocessor quoting
	constexpr string_view PP_QUOTE = CRUCIBLE_QUOTE(hello);
	static_assert(PP_QUOTE == "hello");

	// Plain types and pointer types are unqualified
	static_assert(unqualified<int>);
	static_assert(unqualified<int *>);

	// Reference types, const types, and volatile types are all qualified
	static_assert(!unqualified<int &>);
	static_assert(!unqualified<const int>);
	static_assert(!unqualified<volatile int>);

	// Just to say we did it
	struct something_that_has_elements { using element_type = int; };
	static_assert(std::same_as<element_type_of<something_that_has_elements>, int>);

	// `none` comparisons are statically known because all `none` instances are the same
	static_assert(make_none() == make_none());
	static_assert(!(make_none() != make_none()));
	static_assert(!(make_none() < make_none()));
	static_assert(!(make_none() > make_none()));
	static_assert(make_none() <= make_none());
	static_assert(make_none() >= make_none());

	CRUCIBLE_TEST_SCENARIO(default_construct_trivial_type)
	{
		int const x { construct<int>() };
		CRUCIBLE_ASSERT_EQ(x, 0);
	}

	CRUCIBLE_TEST_SCENARIO(default_construct_nontrivial_type)
	{
		string const s { construct<string>() };
		CRUCIBLE_ASSERT_EQ(s, "");
	}

	CRUCIBLE_TEST_SCENARIO(construct_trivial_type)
	{
		auto const x { construct<int>(5) };
		CRUCIBLE_ASSERT_EQ(x, 5);
	}

	CRUCIBLE_TEST_SCENARIO(construct_nontrivial_type)
	{
		auto const s { construct<string>("hello") };
		CRUCIBLE_ASSERT_EQ(s, "hello");
	}

	CRUCIBLE_TEST_SCENARIO(identity_trivial_type)
	{
		auto const x { identity(5) };
		CRUCIBLE_ASSERT_EQ(x, 5);
	}

	CRUCIBLE_TEST_SCENARIO(identity_nontrivial_type)
	{
		auto const s { identity<string>("hello") };
		CRUCIBLE_ASSERT_EQ(s, "hello");
	}
}

CRUCIBLE_TEST_MAIN