aboutsummaryrefslogtreecommitdiff
path: root/test/src/test_invoke.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test/src/test_invoke.rs')
-rw-r--r--test/src/test_invoke.rs50
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);
+}