diff options
author | tender-bum <tender-bum@yandex-team.ru> | 2022-02-10 16:50:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:01 +0300 |
commit | c78b06a63de7beec995c1007bc5332bdf3d75b69 (patch) | |
tree | 729de992758f40b85278d4abaad655be5dd68dbc /util/generic/overloaded_ut.cpp | |
parent | 95ab23a39b5482a434361566cabdd5b0a433cb43 (diff) | |
download | ydb-c78b06a63de7beec995c1007bc5332bdf3d75b69.tar.gz |
Restoring authorship annotation for <tender-bum@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/overloaded_ut.cpp')
-rw-r--r-- | util/generic/overloaded_ut.cpp | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/util/generic/overloaded_ut.cpp b/util/generic/overloaded_ut.cpp index f3d73895ad9..43893808e56 100644 --- a/util/generic/overloaded_ut.cpp +++ b/util/generic/overloaded_ut.cpp @@ -1,55 +1,55 @@ #include <util/generic/overloaded.h> - + #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/variant.h> -#include <util/generic/algorithm.h> - -#include <tuple> - -namespace { - struct TType1 {}; - struct TType2 {}; - struct TType3 {}; -} - -Y_UNIT_TEST_SUITE(TOverloadedTest) { - Y_UNIT_TEST(StaticTest) { - auto f = TOverloaded{ - [](const TType1&) {}, - [](const TType2&) {}, + +#include <util/generic/variant.h> +#include <util/generic/algorithm.h> + +#include <tuple> + +namespace { + struct TType1 {}; + struct TType2 {}; + struct TType3 {}; +} + +Y_UNIT_TEST_SUITE(TOverloadedTest) { + Y_UNIT_TEST(StaticTest) { + auto f = TOverloaded{ + [](const TType1&) {}, + [](const TType2&) {}, [](const TType3&) {}}; - using F = decltype(f); - static_assert(std::is_invocable_v<F, TType1>); - static_assert(std::is_invocable_v<F, TType2>); - static_assert(std::is_invocable_v<F, TType3>); - static_assert(!std::is_invocable_v<F, int>); - static_assert(!std::is_invocable_v<F, double>); - } - - Y_UNIT_TEST(VariantTest) { + using F = decltype(f); + static_assert(std::is_invocable_v<F, TType1>); + static_assert(std::is_invocable_v<F, TType2>); + static_assert(std::is_invocable_v<F, TType3>); + static_assert(!std::is_invocable_v<F, int>); + static_assert(!std::is_invocable_v<F, double>); + } + + Y_UNIT_TEST(VariantTest) { std::variant<int, double, TType1> v = 5; - int res = 0; + int res = 0; std::visit(TOverloaded{ [&](int val) { res = val; }, [&](double) { res = -1; }, [&](TType1) { res = -1; }}, v); UNIT_ASSERT_VALUES_EQUAL(res, 5); - } - - Y_UNIT_TEST(TupleTest) { + } + + Y_UNIT_TEST(TupleTest) { std::tuple<int, double, bool, int> t{5, 3.14, true, 20}; - TString res; - - ForEach(t, TOverloaded{ + TString res; + + ForEach(t, TOverloaded{ [&](int val) { res += "(int) " + ToString(val) + ' '; }, [&](double val) { res += "(double) " + ToString(val) + ' '; }, [&](bool val) { res += "(bool) " + ToString(val) + ' '; }, }); - + UNIT_ASSERT_VALUES_EQUAL(res, "(int) 5 (double) 3.14 (bool) 1 (int) 20 "); - } + } Y_UNIT_TEST(ImplicitConversionsTest) { using TTestVariant = std::variant<int, double, char>; @@ -79,4 +79,4 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) { UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{12345}), 12345.0); UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{'X'}), 88.0); } -} +} |