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 #373 from asomers/deselfify_args
Fix mocking methods that use `Self` in their arguments.
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 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,39 @@ | ||
// vim: tw=80 | ||
//! Mockall should deselfify `Self` types, even if they aren't named `self`. | ||
use mockall::*; | ||
|
||
mock! { | ||
#[derive(Debug)] | ||
pub Foo { | ||
fn compare(&self, other: &Self) -> bool; | ||
} | ||
impl PartialEq for Foo { | ||
fn eq(&self, other: &Self) -> bool; | ||
} | ||
} | ||
|
||
#[test] | ||
fn inherent_method() { | ||
let mut x = MockFoo::default(); | ||
let mut y = MockFoo::default(); | ||
x.expect_compare() | ||
.return_const(true); | ||
y.expect_compare() | ||
.return_const(false); | ||
|
||
assert!(x.compare(&y)); | ||
assert!(!y.compare(&x)); | ||
} | ||
|
||
#[test] | ||
fn trait_method() { | ||
let mut x = MockFoo::default(); | ||
let mut y = MockFoo::default(); | ||
x.expect_eq() | ||
.return_const(true); | ||
y.expect_eq() | ||
.return_const(false); | ||
|
||
assert_eq!(x, y); | ||
assert!(y != x); | ||
} |
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