libcruft-util/test/introspection/enum_simple.cpp

66 lines
1.7 KiB
C++

#include <cruft/util/introspection/enum_simple.hpp>
#include <cruft/util/tap.hpp>
#include <iostream>
///////////////////////////////////////////////////////////////////////////////
namespace foo::bar {
enum qux_t {
qux0,
qux1,
};
}
//-----------------------------------------------------------------------------
static void
test_local (cruft::TAP::logger &tap)
{
enum enum_t { value0 = 0, value1 = 1, value3 = 3, };
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");
}
//-----------------------------------------------------------------------------
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);
return tap.status ();
}