diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/generic/function_ut.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/generic/function_ut.cpp')
-rw-r--r-- | util/generic/function_ut.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/util/generic/function_ut.cpp b/util/generic/function_ut.cpp new file mode 100644 index 00000000000..3880295a9fc --- /dev/null +++ b/util/generic/function_ut.cpp @@ -0,0 +1,69 @@ +#include "function.h" +#include "typetraits.h" + +#include <library/cpp/testing/unittest/registar.h> + +Y_UNIT_TEST_SUITE(TestFunctionSignature) { + int FF(double x) { + return (int)x; + } + + int FFF(double x, char xx) { + return (int)x + (int)xx; + } + + struct A { + int F(double x) { + return FF(x); + } + }; + + Y_UNIT_TEST(TestPlainFunc) { + UNIT_ASSERT_TYPES_EQUAL(TFunctionSignature<decltype(FF)>, decltype(FF)); + } + + Y_UNIT_TEST(TestMethod) { + UNIT_ASSERT_TYPES_EQUAL(TFunctionSignature<decltype(&A::F)>, decltype(FF)); + } + + Y_UNIT_TEST(TestLambda) { + auto f = [](double x) -> int { + return FF(x); + }; + + UNIT_ASSERT_TYPES_EQUAL(TFunctionSignature<decltype(f)>, decltype(FF)); + } + + Y_UNIT_TEST(TestFunction) { + std::function<int(double)> f(FF); + + UNIT_ASSERT_TYPES_EQUAL(TFunctionSignature<decltype(f)>, decltype(FF)); + } + + template <class F> + void TestCT() { +#define FA(x) TFunctionArg<F, x> + + UNIT_ASSERT_TYPES_EQUAL(FA(0), double); + UNIT_ASSERT_TYPES_EQUAL(FA(1), char); + UNIT_ASSERT_TYPES_EQUAL(TFunctionResult<F>, int); + +#undef FA + } + + Y_UNIT_TEST(TestTypeErasureTraits) { + TestCT<std::function<int(double, char)>>(); + } + + Y_UNIT_TEST(TestPlainFunctionTraits) { + TestCT<decltype(FFF)>(); + } + + Y_UNIT_TEST(TestLambdaTraits) { + auto fff = [](double xx, char xxx) -> int { + return FFF(xx, xxx); + }; + + TestCT<decltype(fff)>(); + } +} |