43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
#include <kpn/traits.hpp>
|
|
#include <tuple>
|
|
|
|
using namespace kpn;
|
|
|
|
static int free_func(int a, float b) { return a; }
|
|
static void sink_func(int a) {}
|
|
static std::tuple<int, float> multi_func(int a) { return {a, 1.f}; }
|
|
|
|
TEST_CASE("arity of free function", "[traits]") {
|
|
STATIC_REQUIRE(arity_v<decltype(free_func)> == 2);
|
|
}
|
|
|
|
TEST_CASE("return type of free function", "[traits]") {
|
|
STATIC_REQUIRE(std::is_same_v<return_t<decltype(free_func)>, int>);
|
|
}
|
|
|
|
TEST_CASE("normalised return: single value", "[traits]") {
|
|
STATIC_REQUIRE(std::is_same_v<normalised_return_t<int>, std::tuple<int>>);
|
|
}
|
|
|
|
TEST_CASE("normalised return: void", "[traits]") {
|
|
STATIC_REQUIRE(std::is_same_v<normalised_return_t<void>, std::tuple<>>);
|
|
}
|
|
|
|
TEST_CASE("normalised return: tuple passthrough", "[traits]") {
|
|
using T = std::tuple<int, float>;
|
|
STATIC_REQUIRE(std::is_same_v<normalised_return_t<T>, T>);
|
|
}
|
|
|
|
TEST_CASE("output_count: single return", "[traits]") {
|
|
STATIC_REQUIRE(output_count_v<decltype(free_func)> == 1);
|
|
}
|
|
|
|
TEST_CASE("output_count: void return", "[traits]") {
|
|
STATIC_REQUIRE(output_count_v<decltype(sink_func)> == 0);
|
|
}
|
|
|
|
TEST_CASE("output_count: tuple return", "[traits]") {
|
|
STATIC_REQUIRE(output_count_v<decltype(multi_func)> == 2);
|
|
}
|