diff options
author | HampusM <hampus@hampusmat.com> | 2023-03-25 11:58:16 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-03-25 11:58:16 +0100 |
commit | aef63bfecb7731c0307cc65eab0b9a06b8a7363d (patch) | |
tree | 8455d54be4fd4008ac593fae5e9e9608198a61b5 /examples/generic_method.rs | |
parent | 96a13690f8552386bb183ebc01418774047ebbfc (diff) |
feat: add argument matching
Diffstat (limited to 'examples/generic_method.rs')
-rw-r--r-- | examples/generic_method.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/examples/generic_method.rs b/examples/generic_method.rs index 4262ee2..7283810 100644 --- a/examples/generic_method.rs +++ b/examples/generic_method.rs @@ -1,12 +1,14 @@ use std::fmt::Display; +use predicates::float::is_close; use ridicule::mock; +use ridicule::predicate::function; trait Foo { fn bar<Baz: Display>(&self, num: u128) -> Baz; - fn abc<Baz: Display>(&mut self, baz: Baz); + fn abc<ThingA, ThingB>(&mut self, thing_a: ThingA, thing_b: ThingB); } mock! { @@ -16,7 +18,7 @@ mock! { { fn bar<Baz: Display>(&self, num: u128) -> Baz; - fn abc<Baz: Display>(&mut self, baz_baz: Baz); + fn abc<ThingA, ThingB>(&mut self, thing_a: ThingA, thing_b: ThingB); } } @@ -39,6 +41,17 @@ fn main() 128u8 }); + mock_foo + .expect_abc::<&str, f64>() + .with( + function(|thing_a: &&str| thing_a.starts_with("Good morning")), + is_close(7.13081), + ) + .returning(|_me, _thing_a, _thing_b| { + println!("abc was called"); + }) + .times(1); + assert_eq!(mock_foo.bar::<String>(123), "Hello".to_string()); assert_eq!(mock_foo.bar::<String>(123), "Hello".to_string()); assert_eq!(mock_foo.bar::<String>(123), "Hello".to_string()); @@ -47,4 +60,12 @@ fn main() // mock_foo.bar::<String>(123); assert_eq!(mock_foo.bar::<u8>(456), 128); + + mock_foo.abc( + concat!( + "Good morning, and in case I don't see ya, good afternoon,", + " good evening, and good night!" + ), + 7.13081f64, + ); } |