From 68a652ed2f51d366bb8033497e6dfe545895410e Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 23 Jul 2026 08:08:33 +0800 Subject: feat: scaffold crate structure and implement core macros Add the project skeleton, LICENSE files, README, Makefile, doc examples, and the initial implementation of `#[func]`, `invoke!`, and `select!` procedural macros. --- test/src/test_invoke.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/src/test_invoke.rs (limited to 'test/src/test_invoke.rs') diff --git a/test/src/test_invoke.rs b/test/src/test_invoke.rs new file mode 100644 index 0000000..b8506e9 --- /dev/null +++ b/test/src/test_invoke.rs @@ -0,0 +1,50 @@ +// ─── 测试 1: 默认 feature 名 ───────────────────────────────────────────────── +// +// 不指定 feature → 用 Cargo.toml 的 default_feature_name = "metadata_async" +// +// 展开(feature "metadata_async" 关闭时): +// { #[cfg(feature = "metadata_async")] { double(5).await } +// #[cfg(not(feature = "metadata_async"))] { double(5) } } + +#[cfg(not(feature = "metadata_async"))] +fn double(x: i32) -> i32 { + x * 2 +} + +#[cfg(feature = "metadata_async")] +async fn double(x: i32) -> i32 { + x * 2 +} + +#[cfg(not(feature = "metadata_async"))] +#[test] +fn test_invoke_default() { + assert_eq!(might_be_async::invoke!(double(5)), 10); +} + +#[cfg(feature = "metadata_async")] +#[test] +fn test_invoke_default() { + let result = futures::executor::block_on(async { might_be_async::invoke!(double(5)) }); + assert_eq!(result, 10); +} + +#[might_be_async::func] +fn square(x: i32) -> i32 { + x * x +} + +#[cfg(not(feature = "metadata_async"))] +#[test] +fn test_invoke_explicit() { + assert_eq!(might_be_async::invoke!("metadata_async" => square(6)), 36); +} + +#[cfg(feature = "metadata_async")] +#[test] +fn test_invoke_explicit() { + let result = futures::executor::block_on(async { + might_be_async::invoke!("metadata_async" => square(6)) + }); + assert_eq!(result, 36); +} -- cgit