From a009c379bab0d8d57112d31293c7a89a09131542 Mon Sep 17 00:00:00 2001 From: Liam Murphy Date: Tue, 28 Nov 2023 11:12:27 +1100 Subject: [PATCH] Add test --- tests/wasm/classes.js | 7 +++++++ tests/wasm/classes.rs | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/tests/wasm/classes.js b/tests/wasm/classes.js index 8e503c658032..49bd44722101 100644 --- a/tests/wasm/classes.js +++ b/tests/wasm/classes.js @@ -241,3 +241,10 @@ exports.js_test_inspectable_classes_can_override_generated_methods = () => { assert.strictEqual(overridden_inspectable.toString(), 'string was overwritten'); overridden_inspectable.free(); }; + +exports.js_test_class_defined_in_macro = () => { + const macroClass = new wasm.InsideMacro(); + assert.strictEqual(macroClass.a, 3); + macroClass.a = 5; + assert.strictEqual(macroClass.a, 5); +}; diff --git a/tests/wasm/classes.rs b/tests/wasm/classes.rs index 9321ff92d7f6..6058c0a59da0 100644 --- a/tests/wasm/classes.rs +++ b/tests/wasm/classes.rs @@ -34,6 +34,7 @@ extern "C" { fn js_test_option_classes(); fn js_test_inspectable_classes(); fn js_test_inspectable_classes_can_override_generated_methods(); + fn js_test_class_defined_in_macro(); } #[wasm_bindgen_test] @@ -608,3 +609,27 @@ impl OverriddenInspectable { String::from("string was overwritten") } } + +macro_rules! make_struct { + ($field:ident) => { + #[wasm_bindgen] + pub struct InsideMacro { + pub $field: u32, + } + }; +} + +make_struct!(a); + +#[wasm_bindgen] +impl InsideMacro { + #[wasm_bindgen(constructor)] + pub fn new() -> Self { + Self { a: 3 } + } +} + +#[wasm_bindgen_test] +fn class_defined_in_macro() { + js_test_class_defined_in_macro(); +}