2019-05-09 10:32:39 +10:00
|
|
|
#include "tap.hpp"
|
|
|
|
#include "types/description.hpp"
|
2019-05-30 10:43:28 +10:00
|
|
|
#include "types/dispatch.hpp"
|
|
|
|
#include "types.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2019-08-30 15:30:45 +10:00
|
|
|
enum an_enum_type : i16 { AN_ENUM_VALUE };
|
2019-05-30 10:43:28 +10:00
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
2019-05-09 10:32:39 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
cruft::TAP::logger tap;
|
|
|
|
|
|
|
|
tap.expect_eq (
|
|
|
|
cruft::types::make_description<int> (),
|
|
|
|
cruft::types::description {
|
2019-05-30 10:43:28 +10:00
|
|
|
.category = cruft::types::category::INTEGER,
|
|
|
|
.signedness = true,
|
|
|
|
.width = sizeof (int),
|
|
|
|
.arity = 1,
|
|
|
|
.alignment = alignof (int),
|
|
|
|
.index = cruft::typeidx<int> (),
|
2019-05-09 10:32:39 +10:00
|
|
|
},
|
|
|
|
"description: int"
|
|
|
|
);
|
|
|
|
|
2019-05-30 10:43:28 +10:00
|
|
|
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"
|
|
|
|
);
|
|
|
|
|
2019-08-30 15:30:45 +10:00
|
|
|
{
|
|
|
|
auto const a = cruft::types::make_description<an_enum_type> ();
|
|
|
|
auto const b = cruft::types::make_description<std::underlying_type_t<an_enum_type>> ();
|
|
|
|
|
|
|
|
tap.expect_neq (a, b, "enum and underlying_type_t raw equality");
|
|
|
|
|
|
|
|
cruft::types::underlying_comparator const cmp {};
|
|
|
|
tap.expect (cmp (a, b), "enum and underlying_type equality");
|
|
|
|
|
|
|
|
auto const c = cruft::types::make_description<u32> ();
|
|
|
|
static_assert (!std::is_same_v<u32, std::underlying_type_t<an_enum_type>>);
|
|
|
|
tap.expect (!cmp (a, c), "enum and underlying_type inequality");
|
|
|
|
}
|
2019-05-30 10:43:28 +10:00
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
|
2019-05-09 10:32:39 +10:00
|
|
|
return tap.status ();
|
|
|
|
}
|