Commit f8995818 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

DRY the applicability traits tests a little

Summary: [Folly] DRY the applicability traits tests a little by extracting a type alias.

Reviewed By: markisaa

Differential Revision: D18748005

fbshipit-source-id: 15d0ceec078a925e7205e7d9398b55cd03004a07
parent b6a14167
......@@ -451,9 +451,9 @@ TEST(MakeIndexSequenceFromTuple, Basic) {
TEST(ApplyResult, Basic) {
{
auto f = [](auto) -> int { return {}; };
EXPECT_TRUE((std::is_same<
folly::apply_result_t<decltype(f), std::tuple<int>>,
int>{}));
using F = decltype(f);
EXPECT_TRUE(
(std::is_same<folly::apply_result_t<F, std::tuple<int>>, int>{}));
}
{
......@@ -461,71 +461,70 @@ TEST(ApplyResult, Basic) {
[](int) {},
[](double) -> double { return {}; },
[](int, int) -> int { return {}; });
using F = decltype(f);
EXPECT_TRUE((std::is_same<
folly::apply_result_t<decltype(f), std::tuple<int>>,
void>::value));
EXPECT_TRUE((std::is_same<
folly::apply_result_t<decltype(f), std::tuple<double>>,
double>::value));
EXPECT_TRUE((std::is_same<
folly::apply_result_t<decltype(f), std::tuple<int, int>>,
int>::value));
EXPECT_TRUE(
(std::is_same<folly::apply_result_t<F, std::tuple<int>>, void>::value));
EXPECT_TRUE(
(std::is_same<folly::apply_result_t<F, std::tuple<double>>, double>::
value));
EXPECT_TRUE(
(std::is_same<folly::apply_result_t<F, std::tuple<int, int>>, int>::
value));
}
}
TEST(IsApplicable, Basic) {
{
auto f = [] {};
EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE((folly::is_applicable_v<decltype(f), std::tuple<int>>));
using F = decltype(f);
EXPECT_TRUE((folly::is_applicable_v<F, std::tuple<>>));
EXPECT_FALSE((folly::is_applicable_v<F, std::tuple<int>>));
}
{
auto f = folly::overload([](int) {}, [](double) -> double { return {}; });
EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<double>>));
EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<int>>));
EXPECT_FALSE((folly::is_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE(
(folly::is_applicable_v<decltype(f), std::tuple<int, double>>));
using F = decltype(f);
EXPECT_TRUE((folly::is_applicable_v<F, std::tuple<double>>));
EXPECT_TRUE((folly::is_applicable_v<F, std::tuple<int>>));
EXPECT_FALSE((folly::is_applicable_v<F, std::tuple<>>));
EXPECT_FALSE((folly::is_applicable_v<F, std::tuple<int, double>>));
}
}
TEST(IsNothrowApplicable, Basic) {
{
auto f = []() noexcept {};
EXPECT_TRUE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE(
(folly::is_nothrow_applicable_v<decltype(f), std::tuple<int>>));
using F = decltype(f);
EXPECT_TRUE((folly::is_nothrow_applicable_v<F, std::tuple<>>));
EXPECT_FALSE((folly::is_nothrow_applicable_v<F, std::tuple<int>>));
}
{
auto f = folly::overload(
[](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_FALSE(
(folly::is_nothrow_applicable_v<decltype(f), std::tuple<double>>));
EXPECT_TRUE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<int>>));
EXPECT_FALSE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE(
(folly::is_nothrow_applicable_v<decltype(f), std::tuple<int, double>>));
using F = decltype(f);
EXPECT_FALSE((folly::is_nothrow_applicable_v<F, std::tuple<double>>));
EXPECT_TRUE((folly::is_nothrow_applicable_v<F, std::tuple<int>>));
EXPECT_FALSE((folly::is_nothrow_applicable_v<F, std::tuple<>>));
EXPECT_FALSE((folly::is_nothrow_applicable_v<F, std::tuple<int, double>>));
}
}
TEST(IsApplicableR, Basic) {
{
auto f = []() -> int { return {}; };
EXPECT_TRUE((folly::is_applicable_r_v<double, decltype(f), std::tuple<>>));
EXPECT_FALSE(
(folly::is_applicable_r_v<double, decltype(f), std::tuple<int>>));
using F = decltype(f);
EXPECT_TRUE((folly::is_applicable_r_v<double, F, std::tuple<>>));
EXPECT_FALSE((folly::is_applicable_r_v<double, F, std::tuple<int>>));
}
{
auto f = folly::overload(
[](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_TRUE(
(folly::is_applicable_r_v<float, decltype(f), std::tuple<double>>));
EXPECT_TRUE((folly::is_applicable_r_v<void, decltype(f), std::tuple<int>>));
EXPECT_FALSE((folly::is_applicable_r_v<void, decltype(f), std::tuple<>>));
using F = decltype(f);
EXPECT_TRUE((folly::is_applicable_r_v<float, F, std::tuple<double>>));
EXPECT_TRUE((folly::is_applicable_r_v<void, F, std::tuple<int>>));
EXPECT_FALSE((folly::is_applicable_r_v<void, F, std::tuple<>>));
EXPECT_FALSE(
(folly::
is_applicable_r_v<double, decltype(f), std::tuple<int, double>>));
(folly::is_applicable_r_v<double, F, std::tuple<int, double>>));
}
}
......@@ -534,26 +533,21 @@ TEST(IsNothrowApplicableR, Basic) {
auto f = []() noexcept->int {
return {};
};
EXPECT_TRUE(
(folly::is_nothrow_applicable_r_v<double, decltype(f), std::tuple<>>));
using F = decltype(f);
EXPECT_TRUE((folly::is_nothrow_applicable_r_v<double, F, std::tuple<>>));
EXPECT_FALSE(
(folly::
is_nothrow_applicable_r_v<double, decltype(f), std::tuple<int>>));
(folly::is_nothrow_applicable_r_v<double, F, std::tuple<int>>));
}
{
auto f = folly::overload(
[](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_FALSE((
folly::
is_nothrow_applicable_r_v<float, decltype(f), std::tuple<double>>));
EXPECT_TRUE(
(folly::is_nothrow_applicable_r_v<void, decltype(f), std::tuple<int>>));
using F = decltype(f);
EXPECT_FALSE(
(folly::is_nothrow_applicable_r_v<float, F, std::tuple<double>>));
EXPECT_TRUE((folly::is_nothrow_applicable_r_v<void, F, std::tuple<int>>));
EXPECT_FALSE((folly::is_nothrow_applicable_r_v<void, F, std::tuple<>>));
EXPECT_FALSE(
(folly::is_nothrow_applicable_r_v<void, decltype(f), std::tuple<>>));
EXPECT_FALSE((folly::is_nothrow_applicable_r_v<
double,
decltype(f),
std::tuple<int, double>>));
(folly::is_nothrow_applicable_r_v<double, F, std::tuple<int, double>>));
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment