diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/generic_method.rs | 22 | 
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);  }  | 
