-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A specific impl is an implementation of a trait on a generic struct with specific generic parameters, like `impl Foo for Bar<i32> {}` Issue #271
- Loading branch information
Showing
7 changed files
with
186 additions
and
28 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,49 @@ | ||
// vim: ts=80 | ||
#![deny(warnings)] | ||
|
||
use mockall::*; | ||
|
||
trait Bar { | ||
fn bar(&self); | ||
} | ||
//trait Baz { | ||
//fn baz<Y: 'static>(&self, y: Y); | ||
//} | ||
|
||
mock! { | ||
pub Foo<T: 'static> { | ||
} | ||
impl Bar for Foo<u32> { | ||
fn bar(&self); | ||
} | ||
impl Bar for Foo<i32> { | ||
fn bar(&self); | ||
} | ||
// TODO: support specific impls with generic methods, like this | ||
//impl Baz for Foo<u32> { | ||
//fn baz<Y: 'static>(&self, y: Y); | ||
//} | ||
} | ||
|
||
#[test] | ||
fn return_const() { | ||
let mut mocku = MockFoo::<u32>::new(); | ||
mocku.expect_bar() | ||
.return_const(()); | ||
let mut mocki = MockFoo::<i32>::new(); | ||
mocki.expect_bar() | ||
.return_const(()); | ||
|
||
mocku.bar(); | ||
mocki.bar(); | ||
} | ||
|
||
///// Make sure generic methods work with specific impls, too | ||
//#[test] | ||
//fn withf() { | ||
//let mut mocku = MockFoo::<u32>::new(); | ||
//mocku.expect_baz::<f32>() | ||
//.withf(|y| y == 3.14159) | ||
//.return_const(()); | ||
//mocku.baz::<f32>(3.14159); | ||
//} |
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 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