#include #include #include #include int main () { cruft::TAP::logger tap; { enum enumeration_t : u16 { FOO, BAR = 2, QUX = 257 }; auto const cookie = cruft::parse::enumeration::setup ({ { "FOO", FOO }, { "BAR", BAR }, { "QUX", QUX }, }); (void)cookie; tap.expect_eq (FOO, cruft::parse::from_string ("FOO"), "enumeration, FOO"); tap.expect_eq (BAR, cruft::parse::from_string ("BAR"), "enumeration, BAR"); tap.expect_eq (QUX, cruft::parse::from_string ("QUX"), "enumeration, QUX"); tap.expect_eq ( u16 {QUX}, cruft::parse::enumeration::from_string ( cruft::typeidx (), "QUX" ), "u16, QUX" ); } { enum class enum_class { VALUE }; auto const cookie = cruft::parse::enumeration::setup ({ { "VALUE", enum_class::VALUE }, }); (void)cookie; tap.expect_eq ( enum_class::VALUE, cruft::parse::from_string ("VALUE"), "enum class, VALUE" ); } { enum class func_enum { ASDF }; auto const cookie = cruft::parse::enumeration::setup ([] (auto &str) { if (equal (str, "ASDF")) { str = str.consume (4); return func_enum::ASDF; } throw std::runtime_error ("Invalid enum value"); }); (void)cookie; tap.expect_eq ( func_enum::ASDF, cruft::parse::from_string ("ASDF"), "function enum lookup" ); } return tap.status (); }