2022-04-01 14:46:13 +11:00
|
|
|
#include <cruft/util/introspection/enum_simple.hpp>
|
|
|
|
#include <cruft/util/tap.hpp>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
2022-04-07 15:47:39 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
namespace foo::bar {
|
|
|
|
enum qux_t {
|
|
|
|
qux0,
|
|
|
|
qux1,
|
|
|
|
};
|
|
|
|
}
|
2022-04-01 14:46:13 +11:00
|
|
|
|
|
|
|
|
2022-04-07 15:47:39 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
test_local (cruft::TAP::logger &tap)
|
|
|
|
{
|
|
|
|
enum enum_t { value0 = 0, value1 = 1, value3 = 3, };
|
2022-04-01 14:46:13 +11:00
|
|
|
|
|
|
|
tap.expect_eq (cruft::introspection::from_string<enum_t> ("value1"), value1, "from_string, dynamic");
|
|
|
|
tap.expect_eq (cruft::introspection::to_string<enum_t, value1> (), "value1", "to_string, static");
|
|
|
|
tap.expect_eq (cruft::introspection::to_string (value1), "value1", "to_string, dynamic");
|
2022-04-07 15:47:39 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
test_namespaced (cruft::TAP::logger &tap)
|
|
|
|
{
|
|
|
|
auto const val = cruft::introspection::to_string<foo::bar::qux_t, foo::bar::qux1> ();
|
|
|
|
(void)val;
|
|
|
|
|
|
|
|
tap.expect_eq (
|
|
|
|
cruft::introspection::from_string<foo::bar::qux_t> ("qux1"),
|
|
|
|
foo::bar::qux1,
|
|
|
|
"namespaced: from_string, dynamic"
|
|
|
|
);
|
|
|
|
tap.expect_eq (
|
|
|
|
cruft::introspection::to_string<
|
|
|
|
foo::bar::qux_t,
|
|
|
|
foo::bar::qux1
|
|
|
|
> (),
|
|
|
|
"qux1",
|
|
|
|
"namespaced: to_string, static"
|
|
|
|
);
|
|
|
|
tap.expect_eq (
|
|
|
|
cruft::introspection::to_string(foo::bar::qux1),
|
|
|
|
"qux1",
|
|
|
|
"namespaced: to-string, dynamic"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int
|
|
|
|
main ()
|
|
|
|
{
|
|
|
|
cruft::TAP::logger tap;
|
|
|
|
|
|
|
|
test_local (tap);
|
|
|
|
test_namespaced (tap);
|
2022-04-01 14:46:13 +11:00
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|