-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow mocking methods with complicated receivers like self: Box<Self>
- Loading branch information
Showing
4 changed files
with
88 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// vim: tw=80 | ||
//! Methods that take receivers like Box<Self> instead of &self | ||
#![deny(warnings)] | ||
|
||
use mockall::*; | ||
use std::sync::Arc; | ||
use std::pin::Pin; | ||
use std::rc::Rc; | ||
|
||
mock! { | ||
Foo { | ||
fn foo(self: &Box<Self>); | ||
fn baz(mut self: Box<Self>); | ||
fn bar(self: Box<Self>); | ||
fn bean(self: Arc<Self>); | ||
fn booz(self: Pin<Box<Self>>); | ||
fn blez(self: Rc<Self>); | ||
} | ||
} | ||
|
||
#[test] | ||
fn arc() { | ||
let mut mock = MockFoo::new(); | ||
mock.expect_bean() | ||
.returning(|| ()); | ||
Arc::new(mock).bean(); | ||
} | ||
|
||
#[test] | ||
fn pin() { | ||
let mut mock = MockFoo::new(); | ||
mock.expect_booz() | ||
.returning(|| ()); | ||
Pin::new(Box::new(mock)).booz(); | ||
} | ||
|
||
#[test] | ||
fn rc() { | ||
let mut mock = MockFoo::new(); | ||
mock.expect_blez() | ||
.returning(|| ()); | ||
Rc::new(mock).blez(); | ||
} | ||
|
||
#[test] | ||
fn ref_box() { | ||
let mut mock = Box::new(MockFoo::new()); | ||
mock.expect_foo() | ||
.returning(|| ()); | ||
mock.foo(); | ||
} | ||
|
||
#[test] | ||
fn mutable() { | ||
let mut mock = Box::new(MockFoo::new()); | ||
mock.expect_baz() | ||
.returning(|| ()); | ||
mock.baz(); | ||
} | ||
|
||
#[test] | ||
fn owned() { | ||
let mut mock = Box::new(MockFoo::new()); | ||
mock.expect_bar() | ||
.returning(|| ()); | ||
mock.bar(); | ||
} |
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