From 657673f4a25a2a7299d3751d54d9597635bc529d Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 19 Mar 2023 13:45:07 +0100 Subject: docs: add examples --- examples/generic_method.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/generic_method.rs (limited to 'examples/generic_method.rs') diff --git a/examples/generic_method.rs b/examples/generic_method.rs new file mode 100644 index 0000000..8dc4650 --- /dev/null +++ b/examples/generic_method.rs @@ -0,0 +1,36 @@ +use ridicule::mock; + +trait Foo +{ + fn bar(&self, num: u128) -> Baz; +} + +mock! { + MockFoo {} + + impl Foo for MockFoo + { + fn bar(&self, num: u128) -> Baz; + } +} + +fn main() +{ + let mut mock_foo = MockFoo::new(); + + mock_foo.expect_bar().returning(|_me, num| { + println!("bar was called with {num}"); + + "Hello".to_string() + }); + + mock_foo.expect_bar().returning(|_me, num| { + println!("bar was called with {num}"); + + 128u8 + }); + + assert_eq!(mock_foo.bar::(123), "Hello".to_string()); + + assert_eq!(mock_foo.bar::(456), 128); +} -- cgit v1.2.3-18-g5258