-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update documentation and tests for async functions in traits
- Loading branch information
1 parent
f43111b
commit 9a4b967
Showing
11 changed files
with
145 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#[rustversion::since(1.75)] | ||
mod r#async { | ||
use unimock::*; | ||
|
||
#[unimock(api = TraitMock)] | ||
trait Trait { | ||
async fn a(&self, arg: i32) -> i32; | ||
async fn b(&self) -> &i32; | ||
async fn c(&self) -> Option<&i32>; | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_it() { | ||
let deps = Unimock::new(( | ||
TraitMock::a.next_call(matching!(_)).returns(42), | ||
TraitMock::b.next_call(matching!()).returns(42), | ||
TraitMock::c.next_call(matching!()).returns(Some(42)), | ||
)); | ||
|
||
assert_eq!(42, deps.a(5).await); | ||
assert_eq!(&42, deps.b().await); | ||
assert_eq!(Some(&42), deps.c().await); | ||
} | ||
} | ||
|
||
#[rustversion::since(1.75)] | ||
mod rpit_future { | ||
use std::future::Future; | ||
|
||
use unimock::*; | ||
|
||
#[unimock(api = RpitFutureMock)] | ||
trait RpitFuture { | ||
fn m1(&self) -> impl Future<Output = i32>; | ||
fn m2(&self, arg: i32) -> impl Send + Future<Output = i32>; | ||
fn m3(&self) -> impl Future<Output = i32> + Send; | ||
fn m4(&self) -> impl core::future::Future<Output = i32> + Send; | ||
} | ||
|
||
#[tokio::test] | ||
async fn rpit() { | ||
let u = Unimock::new(( | ||
RpitFutureMock::m1.next_call(matching!()).returns(1337), | ||
RpitFutureMock::m2.next_call(matching!(42)).returns(1338), | ||
)); | ||
|
||
assert_eq!(u.m1().await, 1337); | ||
assert_eq!(u.m2(42).await, 1338); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
#![allow(clippy::disallowed_names)] | ||
|
||
mod associated_future; | ||
mod async_fn_in_trait; | ||
mod rpit_future; | ||
|
||
fn main() {} |
This file was deleted.
Oops, something went wrong.