-
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.
Eliminate the generic static methods hack
It is no longer necessary to duplicate the struct's generic parameters in the mock method's definition.
- Loading branch information
Showing
9 changed files
with
77 additions
and
49 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
18 changes: 18 additions & 0 deletions
18
mockall/tests/automock_generic_struct_with_static_method.rs
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,18 @@ | ||
// vim: tw=80 | ||
//! static non-generic methods of generic structs shouldn't require any special | ||
//! treatment when mocking. Prior to version 0.3.0, the struct's generic | ||
//! parameters had to be duplicated as generic parameters of the method. | ||
use mockall::*; | ||
|
||
#[automock] | ||
trait Foo<T: 'static> { | ||
fn foo(t: T); | ||
} | ||
|
||
#[test] | ||
fn returning() { | ||
MockFoo::<u32>::expect_foo() | ||
.returning(|_| ()); | ||
MockFoo::foo(42u32); | ||
} |
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
18 changes: 18 additions & 0 deletions
18
mockall/tests/mock_generic_struct_with_generic_static_method.rs
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,18 @@ | ||
// vim: ts=80 | ||
//! A generic struct with a generic method on a different parameter | ||
use mockall::*; | ||
|
||
mock! { | ||
Foo<T: 'static> { | ||
fn foo<Q: 'static>(t: T, q: Q); | ||
} | ||
} | ||
|
||
#[test] | ||
fn with() { | ||
MockFoo::<u32>::expect_foo::<i16>() | ||
.with(predicate::eq(42u32), predicate::eq(99i16)) | ||
.returning(|_, _| ()); | ||
MockFoo::foo(42u32, 99i16); | ||
} |
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 |
---|---|---|
@@ -1,25 +1,19 @@ | ||
// vim: ts=80 | ||
// vim: tw=80 | ||
//! static non-generic methods of generic structs shouldn't require any special | ||
//! treatment when mocking. Prior to version 0.3.0, the struct's generic | ||
//! parameters had to be duplicated as generic parameters of the method. | ||
use mockall::*; | ||
|
||
// Static methods parameterized on the struct's generic parameter need to be | ||
// turned into generic methods for mocking. A struct like this: | ||
// | ||
// struct Foo<T> {} | ||
// impl<T> Foo<T> { | ||
// fn foo(t: T) {...} | ||
// } | ||
// | ||
// Can be mocked like this: | ||
mock! { | ||
Foo<T: 'static> { | ||
fn foo<T2: 'static>(t: T2); | ||
fn foo(t: T); | ||
} | ||
} | ||
|
||
#[test] | ||
fn returning() { | ||
MockFoo::<u32>::expect_foo::<u32>() | ||
MockFoo::<u32>::expect_foo() | ||
.returning(|_| ()); | ||
MockFoo::<u32>::foo(42u32); | ||
MockFoo::foo(42u32); | ||
} |
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