parselink-old/tests/msgpack/unpacker/maps.cpp

83 lines
2.6 KiB
C++

//-----------------------------------------------------------------------------
// ___ __ _ _
// / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __
// / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ /
// / ___/ (_| | | \__ \ __/ /__| | | | | <
// \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ .
//
//-----------------------------------------------------------------------------
// 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 <fmt/ranges.h>
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<int>"_test = [] {
bool expected = false;
auto key = msgpack::map::on_key<5>([&] { expected = true; });
expect(!expected);
key.handler();
expect(expected);
};
"on_key<string>"_test = [] {
bool expected = false;
auto key = msgpack::map::on_key<"hello">([&] { expected = true; });
expect(!expected);
key.handler();
expect(expected);
};
"key_group<int>"_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<string>"_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<S, 1>();
static_assert(parselink::ct::member_name<S, 1>() == "bar");
fmt::print("{}\n", namefn);
constexpr auto names = parselink::ct::member_names<S>();
fmt::print("{}\n", names);
};
};