Skip to content

Commit 8224f84

Browse files
authored
Merge pull request #228 from elbeno/add-to-underlying-tests
✅ Add tests for `to_underlying` with arithmetic types
2 parents 0ca8c0f + ffef4b8 commit 8224f84

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/to_underlying.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdx/type_traits.hpp>
22

3+
#include <catch2/catch_template_test_macros.hpp>
34
#include <catch2/catch_test_macros.hpp>
45

56
#include <type_traits>
@@ -25,8 +26,18 @@ TEST_CASE("to_underlying values", "[type_traits]") {
2526
CHECK(stdx::to_underlying(ScopedEnum::Value5) == 5);
2627
}
2728

28-
TEST_CASE("to_underlying works on integral types", "[type_traits]") {
29-
constexpr int x = 0;
30-
CHECK(std::is_same_v<decltype(stdx::to_underlying(x)), int>);
31-
CHECK(stdx::to_underlying(x) == 0);
29+
TEMPLATE_TEST_CASE("to_underlying works on integral types", "[type_traits]",
30+
bool, char, signed char, unsigned char, short int,
31+
unsigned short int, int, unsigned int, long int,
32+
unsigned long int) {
33+
constexpr TestType x{};
34+
CHECK(std::is_same_v<decltype(stdx::to_underlying(x)), TestType>);
35+
CHECK(stdx::to_underlying(x) == TestType{});
36+
}
37+
38+
TEMPLATE_TEST_CASE("to_underlying works on floating point types",
39+
"[type_traits]", float, double) {
40+
constexpr TestType x{};
41+
CHECK(std::is_same_v<decltype(stdx::to_underlying(x)), TestType>);
42+
CHECK(stdx::to_underlying(x) == TestType{});
3243
}

0 commit comments

Comments
 (0)