Skip to content

Commit 60eecdf

Browse files
committed
test: Rework Result() matcher
1 parent d52f315 commit 60eecdf

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

Diff for: test/utils/asserts.hpp

+22-11
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ MATCHER_P(Result, value, "") // NOLINT(readability-redundant-string-init)
3030
{
3131
using namespace fizzy;
3232

33-
static_assert(is_any_of<value_type, uint32_t, int32_t, uint64_t, int64_t, float, double>);
34-
3533
// Require the arg to be TypedExecutionResult.
3634
// This can be a static_assert, but just returning false and failing a test provides better
3735
// location of the error.
@@ -44,24 +42,37 @@ MATCHER_P(Result, value, "") // NOLINT(readability-redundant-string-init)
4442

4543
if constexpr (std::is_same_v<result_type, test::TypedExecutionResult>)
4644
{
47-
// Type safe checks.
48-
if constexpr (is_any_of<value_type, uint32_t, int32_t>)
45+
if constexpr (std::is_same_v<value_type, float>)
4946
{
50-
return arg.type == ValType::i32 && arg.value.i64 == static_cast<uint32_t>(value);
47+
return arg.type == ValType::f32 && arg.value.f32 == test::FP{value};
5148
}
52-
else if constexpr (is_any_of<value_type, uint64_t, int64_t>)
49+
50+
if constexpr (std::is_same_v<value_type, double>)
5351
{
54-
return arg.type == ValType::i64 && arg.value.i64 == static_cast<uint64_t>(value);
52+
return arg.type == ValType::f64 && arg.value.f64 == test::FP{value};
5553
}
56-
else if constexpr (std::is_same_v<value_type, float>)
54+
55+
if constexpr (std::is_integral_v<value_type> && sizeof(value_type) == sizeof(uint64_t))
5756
{
58-
return arg.type == ValType::f32 && arg.value.f32 == test::FP{value};
57+
return arg.type == ValType::i64 && arg.value.i64 == static_cast<uint64_t>(value);
5958
}
60-
else
59+
60+
if constexpr (std::is_integral_v<value_type> && sizeof(value_type) == sizeof(uint32_t))
6161
{
62-
return arg.type == ValType::f64 && arg.value.f64 == test::FP{value};
62+
if (arg.type == ValType::i32)
63+
{
64+
return arg.value.i64 == static_cast<uint32_t>(value);
65+
}
66+
else if (arg.type == ValType::i64 && value >= 0)
67+
{
68+
// Here allow convenient zero-extension of the expected value u32 -> u64.
69+
return arg.value.i64 == static_cast<uint32_t>(value);
70+
}
71+
return false;
6372
}
6473
}
74+
75+
return false;
6576
}
6677

6778
MATCHER(CTraps, "") // NOLINT(readability-redundant-string-init)

0 commit comments

Comments
 (0)