aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/src/test_func.rs32
-rw-r--r--test/src/test_select.rs25
2 files changed, 57 insertions, 0 deletions
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");
+}