libcruft-util/test/types/description.cpp

66 lines
1.8 KiB
C++

#include "tap.hpp"
#include "types/description.hpp"
#include "types/dispatch.hpp"
#include "types.hpp"
///////////////////////////////////////////////////////////////////////////////
enum an_enum_type { AN_ENUM_VALUE };
//-----------------------------------------------------------------------------
struct does_enum_match {
template <typename TagT>
bool operator() (cruft::type_tag<TagT> const&)
{
return false;
}
template <typename UnderlyingT>
bool operator() (cruft::type_tag<cruft::unknown_enum_tag<UnderlyingT>> const &tag)
{
auto const expected = cruft::types::make_description<an_enum_type> ();
return expected == tag.desc;
}
};
///////////////////////////////////////////////////////////////////////////////
int main ()
{
cruft::TAP::logger tap;
tap.expect_eq (
cruft::types::make_description<int> (),
cruft::types::description {
.category = cruft::types::category::INTEGER,
.signedness = true,
.width = sizeof (int),
.arity = 1,
.alignment = alignof (int),
.index = cruft::typeidx<int> (),
},
"description: int"
);
tap.expect_neq (
cruft::types::make_description<i16> (),
cruft::types::make_description<u16> (),
"different signedness is unequal"
);
tap.expect_eq (
cruft::types::make_description<an_enum_type> ().category,
cruft::types::category::ENUM,
"enums are described as such"
);
auto const enum_type_descriptor = cruft::types::make_description<an_enum_type> ();
tap.expect (
cruft::types::visit (enum_type_descriptor, does_enum_match {}),
"enum type descriptor dispatches correctly"
);
return tap.status ();
}