summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-03-19 16:29:23 +0100
committerHampusM <hampus@hampusmat.com>2023-03-19 16:54:57 +0100
commitad2a6d1dc517407939ed022bba9f3352efc678ce (patch)
tree8bf7acc6cd79f2d686865832a3b44adb22c01d60 /examples
parent657673f4a25a2a7299d3751d54d9597635bc529d (diff)
feat: add call count expectations to expectations
Diffstat (limited to 'examples')
-rw-r--r--examples/generic_method.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/examples/generic_method.rs b/examples/generic_method.rs
index 8dc4650..995c67d 100644
--- a/examples/generic_method.rs
+++ b/examples/generic_method.rs
@@ -1,8 +1,10 @@
+use std::fmt::Display;
+
use ridicule::mock;
trait Foo
{
- fn bar<Baz>(&self, num: u128) -> Baz;
+ fn bar<Baz: Display>(&self, num: u128) -> Baz;
}
mock! {
@@ -10,7 +12,7 @@ mock! {
impl Foo for MockFoo
{
- fn bar<Baz>(&self, num: u128) -> Baz;
+ fn bar<Baz: Display>(&self, num: u128) -> Baz;
}
}
@@ -18,11 +20,14 @@ fn main()
{
let mut mock_foo = MockFoo::new();
- mock_foo.expect_bar().returning(|_me, num| {
- println!("bar was called with {num}");
+ mock_foo
+ .expect_bar()
+ .returning(|_me, num| {
+ println!("bar was called with {num}");
- "Hello".to_string()
- });
+ "Hello".to_string()
+ })
+ .times(3);
mock_foo.expect_bar().returning(|_me, num| {
println!("bar was called with {num}");
@@ -31,6 +36,11 @@ fn main()
});
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());
+
+ // Would panic
+ // mock_foo.bar::<String>(123);
assert_eq!(mock_foo.bar::<u8>(456), 128);
}