//----------------------------------------------------------------------------- // ___ __ _ _ // / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __ // / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ / // / ___/ (_| | | \__ \ __/ /__| | | | | < // \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ . // //----------------------------------------------------------------------------- // Author: Kurt Sassenrath // Module: msgpack // // Unpacker tests for maps. // // Copyright (c) 2023 Kurt Sassenrath. // // License TBD. //----------------------------------------------------------------------------- #include "parselink/msgpack/core/detail/unpack_map.h" #include "parselink/utility/ctstring.h" #include "test_unpacker.h" #include "parselink/utility/ctreflect.h" #include using namespace boost::ut; struct S { int abra; int bar; int cat; int dog; int lbue; int bue; int ue; }; suite test_on_key = [] { "on_key"_test = [] { bool expected = false; auto key = msgpack::map::on_key<5>([&] { expected = true; }); expect(!expected); key.handler(); expect(expected); }; "on_key"_test = [] { bool expected = false; auto key = msgpack::map::on_key<"hello">([&] { expected = true; }); expect(!expected); key.handler(); expect(expected); }; "key_group"_test = [] { auto keys = msgpack::map::key_group( msgpack::map::on_key<5>([] {}), msgpack::map::on_key<1>([] {})); constexpr auto size = decltype(keys)::size; constexpr auto first_key = get_key(std::get<0>(keys.keys_)); constexpr auto second_key = get_key(std::get<1>(keys.keys_)); static_assert(size == 2); expect(first_key == 5); expect(second_key == 1); }; "key_group"_test = [] { auto keys = msgpack::map::key_group(msgpack::map::on_key<"hello">([] {}), msgpack::map::on_key<"world">([] {})); constexpr auto size = decltype(keys)::size; constexpr auto first_key = get_key(std::get<0>(keys.keys_)); constexpr auto second_key = get_key(std::get<1>(keys.keys_)); static_assert(size == 2); expect(first_key == "hello"); expect(second_key == "world"); }; "key_group_from_struct_names"_test = [] { constexpr auto namefn = parselink::ct::member_name(); static_assert(parselink::ct::member_name() == "bar"); fmt::print("{}\n", namefn); constexpr auto names = parselink::ct::member_names(); fmt::print("{}\n", names); }; };