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::core { // Preprocessor concatenation constexpr int CRUCIBLE_CORE_COMBINE4(PP_, A, B, C) = 5; static_assert(PP_ABC == 5); constexpr int CRUCIBLE_CORE_COMBINE3(PP_, A, B) = 15; static_assert(PP_AB == 15); constexpr int CRUCIBLE_CORE_COMBINE2(PP_, A) = 25; static_assert(PP_A == 25); // Preprocessor quoting constexpr String_View PP_QUOTE = CRUCIBLE_CORE_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_CORE_ASSERT_EQ(x, 0); } CRUCIBLE_TEST_SCENARIO(default_construct_nontrivial_type) { String const s { construct<String>() }; CRUCIBLE_CORE_ASSERT_EQ(s, ""); } CRUCIBLE_TEST_SCENARIO(construct_trivial_type) { auto const x { construct<int>(5) }; CRUCIBLE_CORE_ASSERT_EQ(x, 5); } CRUCIBLE_TEST_SCENARIO(construct_nontrivial_type) { auto const s { construct<String>("hello") }; CRUCIBLE_CORE_ASSERT_EQ(s, "hello"); } CRUCIBLE_TEST_SCENARIO(identity_trivial_type) { auto const x { identity(5) }; CRUCIBLE_CORE_ASSERT_EQ(x, 5); } CRUCIBLE_TEST_SCENARIO(identity_nontrivial_type) { auto const s { identity<String>("hello") }; CRUCIBLE_CORE_ASSERT_EQ(s, "hello"); } } CRUCIBLE_TEST_MAIN