From 7dbc605d0bcdfeb550a1dd2b184c258d365d5981 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 30 Aug 2022 13:56:25 +0800 Subject: [PATCH] Macro test for enums. --- tests/plugins.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/plugins.rs b/tests/plugins.rs index a5355d07..9186f59c 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -75,12 +75,35 @@ fn make_greeting(n: impl std::fmt::Display) -> String { gen_unary_functions!(greet = make_greeting(INT, bool, char) -> String); +macro_rules! expand_enum { + ($module:ident : $typ:ty => $($variant:ident),+) => { + #[export_module] + pub mod $module { + $( + pub const $variant: $typ = <$typ>::$variant; + )* + } + }; +} + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum MyEnum { + Foo, + Bar, + Baz, + Hello, + World, +} + +expand_enum! { my_enum_module: MyEnum => Foo, Bar, Baz, Hello, World } + #[test] fn test_plugins_package() -> Result<(), Box> { let mut engine = Engine::new(); let mut m = Module::new(); combine_with_exported_module!(&mut m, "test", test::special_array_package); + combine_with_exported_module!(&mut m, "enum", my_enum_module); engine.register_global_module(m.into()); reg_functions!(engine += greet::single(INT, bool, char));