-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_make_primitive.cpp
More file actions
74 lines (57 loc) · 2.57 KB
/
test_make_primitive.cpp
File metadata and controls
74 lines (57 loc) · 2.57 KB
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
#include <gtest/gtest.h>
#include <type_traits>
import mcpplibs.primitives;
#include "../../support/underlying_custom_types.hpp"
using namespace mcpplibs::primitives;
using namespace mcpplibs::primitives::literals;
using namespace mcpplibs::primitives::test_support::underlying;
TEST(PrimitiveFactoryTest, MakesPrimitiveFromDeducedStdUnderlying) {
using expected_t =
types::I32<policy::value::checked, policy::error::expected>;
auto value = with<policy::value::checked, policy::error::expected>(42_i32);
static_assert(std::same_as<decltype(value), expected_t>);
EXPECT_EQ(value.load(), 42);
}
TEST(PrimitiveFactoryTest, UsesDefaultPoliciesWhenNoPolicyIsSpecified) {
using expected_t = types::I32<>;
using meta_t = meta::traits<expected_t>;
auto value = with(42_i32);
static_assert(std::same_as<decltype(value), expected_t>);
static_assert(std::same_as<meta_t::value_policy,
policy::defaults::value>);
static_assert(
std::same_as<meta_t::type_policy, policy::defaults::type>);
static_assert(
std::same_as<meta_t::error_policy, policy::defaults::error>);
static_assert(std::same_as<meta_t::concurrency_policy,
policy::defaults::concurrency>);
EXPECT_EQ(value.load(), 42);
}
TEST(PrimitiveFactoryTest, DeducesSizeAndDiffPrimitiveAliases) {
auto sizeValue = with(42_size);
auto diffValue = with(42_diff);
static_assert(std::same_as<decltype(sizeValue), types::Size<>>);
static_assert(std::same_as<decltype(diffValue), types::Diff<>>);
EXPECT_EQ(sizeValue.load(), static_cast<std::size_t>(42));
EXPECT_EQ(diffValue.load(), static_cast<std::ptrdiff_t>(42));
}
TEST(PrimitiveFactoryTest, AcceptsPoliciesTupleInput) {
using policies_t =
meta::traits<types::I32<policy::value::checked,
policy::error::expected>>::policies;
using expected_t = meta::make_primitive_t<std::int32_t, policies_t>;
auto value1 = with(policies_t{}, 42_i32);
auto value2 = with(meta::traits<decltype(value1)>::policies{}, 42_i32);
static_assert(std::same_as<decltype(value1), expected_t>);
static_assert(std::same_as<decltype(value2), expected_t>);
EXPECT_EQ(value1.load(), 42);
EXPECT_EQ(value2.load(), 42_i32);
}
TEST(PrimitiveFactoryTest, MakesPrimitiveFromDeducedCustomUnderlying) {
using expected_t =
primitive<UserInteger, policy::value::checked, policy::type::compatible>;
auto value =
with<policy::value::checked, policy::type::compatible>(UserInteger{7});
static_assert(std::same_as<decltype(value), expected_t>);
EXPECT_EQ(value.load().value, 7);
}