blob: 1f729fb334ad99673403ba58ada7403e495bc1dd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#[might_be_async::func]
fn fallback_id(x: i32) -> i32 {
x
}
#[cfg(not(feature = "async"))]
#[test]
fn test_fallback_func_sync() {
assert_eq!(fallback_id(42), 42);
}
#[cfg(feature = "async")]
#[test]
fn test_fallback_func_async() {
let r = futures::executor::block_on(fallback_id(42));
assert_eq!(r, 42);
}
#[cfg(not(feature = "async"))]
#[test]
fn test_fallback_select_implicit_sync() {
let r = might_be_async::select! { { 1 } else { 2 } };
assert_eq!(r, 2);
}
#[cfg(feature = "async")]
#[test]
fn test_fallback_select_implicit_async() {
let r = might_be_async::select! { { 1 } else { 2 } };
assert_eq!(r, 1);
}
#[cfg(not(feature = "async"))]
fn fallback_double(x: i32) -> i32 {
x * 2
}
#[cfg(feature = "async")]
async fn fallback_double(x: i32) -> i32 {
x * 2
}
#[cfg(not(feature = "async"))]
#[test]
fn test_fallback_invoke_sync() {
assert_eq!(might_be_async::invoke!(fallback_double(5)), 10);
}
#[cfg(feature = "async")]
#[test]
fn test_fallback_invoke_async() {
let r = futures::executor::block_on(async { might_be_async::invoke!(fallback_double(5)) });
assert_eq!(r, 10);
}
|