-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #590 from asomers/auto_enum
Add compatibility with auto_enums
- Loading branch information
Showing
5 changed files
with
46 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// vim: tw=80 | ||
//! A method that uses `#[auto_enum]`, from the auto_enums crate. | ||
#![deny(warnings)] | ||
|
||
use auto_enums::auto_enum; | ||
use futures::{Future, FutureExt, future}; | ||
use mockall::*; | ||
|
||
pub struct Foo{} | ||
|
||
#[automock] | ||
impl Foo { | ||
#[auto_enum(Future)] | ||
pub fn sign(&self, x: i32) -> impl Future<Output=i32> | ||
{ | ||
if x > 0 { | ||
future::ready(1) | ||
} else { | ||
future::ready(1).then(|_| future::ready(-1)) | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn rpit() { | ||
let mut mock = MockFoo::new(); | ||
mock.expect_sign() | ||
.returning(|_| { | ||
Box::pin(future::ready(42)) | ||
}); | ||
let r = mock.sign(101) | ||
.now_or_never() | ||
.unwrap(); | ||
assert_eq!(42, r); | ||
} |
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