diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-23 08:08:33 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-23 14:01:45 +0800 |
| commit | 68a652ed2f51d366bb8033497e6dfe545895410e (patch) | |
| tree | d463833846248410733e196a0939c59cd67ca8a2 /test/src/test_invoke.rs | |
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.
Diffstat (limited to 'test/src/test_invoke.rs')
| -rw-r--r-- | test/src/test_invoke.rs | 50 |
1 files changed, 50 insertions, 0 deletions
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); +} |
