| 1 |
use std::io::prelude::*; |
| 2 |
|
| 3 |
use rstest::*; |
| 4 |
|
| 5 |
#[fixture] |
| 6 |
async fn async_u32() -> u32 { |
| 7 |
42 |
| 8 |
} |
| 9 |
|
| 10 |
#[fixture] |
| 11 |
async fn nest_fixture(#[future] async_u32: u32) -> u32 { |
| 12 |
async_u32.await |
| 13 |
} |
| 14 |
|
| 15 |
#[fixture(fortytwo = async { 42 })] |
| 16 |
async fn nest_fixture_with_default(#[future] fortytwo: u32) -> u32 { |
| 17 |
fortytwo.await |
| 18 |
} |
| 19 |
|
| 20 |
#[rstest] |
| 21 |
#[async_std::test] |
| 22 |
async fn default_is_async() { |
| 23 |
assert_eq!(42, async_u32::default().await); |
| 24 |
} |
| 25 |
|
| 26 |
#[rstest] |
| 27 |
#[async_std::test] |
| 28 |
async fn use_async_nest_fixture_default(#[future] nest_fixture: u32) { |
| 29 |
assert_eq!(42, nest_fixture.await); |
| 30 |
} |
| 31 |
|
| 32 |
#[rstest(nest_fixture(async { 24 }))] |
| 33 |
#[async_std::test] |
| 34 |
async fn use_async_nest_fixture_injected(#[future] nest_fixture: u32) { |
| 35 |
assert_eq!(24, nest_fixture.await); |
| 36 |
} |
| 37 |
|
| 38 |
#[rstest] |
| 39 |
#[async_std::test] |
| 40 |
async fn use_async_nest_fixture_with_default(#[future] nest_fixture_with_default: u32) { |
| 41 |
assert_eq!(42, nest_fixture_with_default.await); |
| 42 |
} |
| 43 |
|
| 44 |
#[rstest] |
| 45 |
#[async_std::test] |
| 46 |
async fn use_async_fixture(#[future] async_u32: u32) { |
| 47 |
assert_eq!(42, async_u32.await); |
| 48 |
} |
| 49 |
|
| 50 |
#[fixture] |
| 51 |
async fn async_impl_output() -> impl Read { |
| 52 |
std::io::Cursor::new(vec![1, 2, 3, 4, 5]) |
| 53 |
} |
| 54 |
|
| 55 |
#[rstest] |
| 56 |
#[async_std::test] |
| 57 |
async fn use_async_impl_output<T: Read>(#[future] async_impl_output: T) { |
| 58 |
let reader = async_impl_output.await; |
| 59 |
} |
| 60 |
|
| 61 |
#[fixture(four = async { 4 }, two = 2)] |
| 62 |
async fn two_args_mix_fixture(#[future] four: u32, two: u32) -> u32 { |
| 63 |
four.await * 10 + two |
| 64 |
} |
| 65 |
|
| 66 |
#[rstest] |
| 67 |
#[async_std::test] |
| 68 |
async fn use_two_args_mix_fixture(#[future] two_args_mix_fixture: u32) { |
| 69 |
assert_eq!(42, two_args_mix_fixture.await); |
| 70 |
} |
| 71 |
|
| 72 |
#[rstest(two_args_mix_fixture(async { 5 }))] |
| 73 |
#[async_std::test] |
| 74 |
async fn use_two_args_mix_fixture_inject_first(#[future] two_args_mix_fixture: u32) { |
| 75 |
assert_eq!(52, two_args_mix_fixture.await); |
| 76 |
} |
| 77 |
|
| 78 |
#[rstest(two_args_mix_fixture(async { 3 }, 1))] |
| 79 |
#[async_std::test] |
| 80 |
async fn use_two_args_mix_fixture_inject_both(#[future] two_args_mix_fixture: u32) { |
| 81 |
assert_eq!(31, two_args_mix_fixture.await); |
| 82 |
} |