From f9f879e488a62eba9c54c8e713cc94cc9f20e96e Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 23 Jul 2026 23:23:56 +0800 Subject: feat(config): refactor default feature name parsing --- test/src/test_func.rs | 32 ++++++++++++++++++++++++++++++++ test/src/test_select.rs | 25 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+) (limited to 'test') diff --git a/test/src/test_func.rs b/test/src/test_func.rs index 71fe365..666a99f 100644 --- a/test/src/test_func.rs +++ b/test/src/test_func.rs @@ -34,3 +34,35 @@ fn triple(x: i32) -> i32 { fn test_func_custom_feature() { assert_eq!(triple(3), 9); } + +#[cfg(feature = "metadata_async")] +#[test] +fn test_func_async_identity() { + let result = futures::executor::block_on(async { identity(42).await }); + assert_eq!(result, 42); +} + +#[cfg(feature = "metadata_async")] +#[test] +fn test_func_async_generic() { + let r = futures::executor::block_on(async { first(10, 20).await }); + assert_eq!(r, 10); +} + +#[might_be_async::func] +fn greet_async(name: &str) -> String { + format!("Hello, {name}!") +} + +#[cfg(not(feature = "metadata_async"))] +#[test] +fn test_func_sync_greet() { + assert_eq!(greet_async("world"), "Hello, world!"); +} + +#[cfg(feature = "metadata_async")] +#[test] +fn test_func_async_greet() { + let r = futures::executor::block_on(greet_async("world")); + assert_eq!(r, "Hello, world!"); +} diff --git a/test/src/test_select.rs b/test/src/test_select.rs index 2cf3bfe..901ee35 100644 --- a/test/src/test_select.rs +++ b/test/src/test_select.rs @@ -90,3 +90,28 @@ fn test_select_metadata_two_not() { let r = might_be_async::select! { ! => { 70 } else ! => { 80 } }; assert_eq!(r, 80); } + +#[might_be_async::func] +fn pick(toggle: bool) -> &'static str { + might_be_async::select! { "metadata_async" => { + if toggle { "async_on_a" } else { "async_on_b" } + } else ! => { + if toggle { "sync_a" } else { "sync_b" } + }} +} + +#[cfg(not(feature = "metadata_async"))] +#[test] +fn test_select_inside_func_sync() { + assert_eq!(pick(true), "sync_a"); + assert_eq!(pick(false), "sync_b"); +} + +#[cfg(feature = "metadata_async")] +#[test] +fn test_select_inside_func_async() { + let r = futures::executor::block_on(async { pick(true).await }); + assert_eq!(r, "async_on_a"); + let r = futures::executor::block_on(async { pick(false).await }); + assert_eq!(r, "async_on_b"); +} -- cgit