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/simple.rs | 77 ------------------------------------------------------ 1 file changed, 77 deletions(-) delete mode 100644 examples/simple.rs (limited to 'examples/simple.rs') diff --git a/examples/simple.rs b/examples/simple.rs deleted file mode 100644 index c5494da..0000000 --- a/examples/simple.rs +++ /dev/null @@ -1,77 +0,0 @@ -use std::fmt::Debug; - -use ridicule::mock; - -trait SomeFoobar -{ - fn do_something(&self) -> bool; -} - -trait Foo -{ - fn bar(&self, num: u128) -> Baz; - - fn biz(&self, fiz: Fiz) -> &Bar; - - fn baz(&self, name: &str, foobar: Foobar) - where - Foobar: SomeFoobar + Debug; - - fn hello(&self, xyz: Xyz); -} - -mock! { - MockFoo {} - - impl Foo for MockFoo { - fn bar(&self, num: u128) -> Baz; - - fn biz<'a, Fiz: Debug, Bar>(&'a self, fiz: Fiz) -> &'a Bar; - - fn baz(&self, name: &str, foobar: Foobar) - where - Foobar: SomeFoobar + Debug; - - fn hello(&self, xyz: Xyz); - } -} - -fn main() -{ - let mut mock_foo = MockFoo::new(); - - mock_foo.expect_bar::<_, Vec>().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}"); - - 136322 - }); - - mock_foo.expect_bar::<_, String>().returning(|_me, num| { - println!("bar was called with {num}"); - - "Greetings".to_string() - }); - - assert_eq!( - >>::bar::(&mock_foo, 123), - "Hello".to_string() - ); - - assert_eq!( - >>::bar::(&mock_foo, 456), - 136322 - ); - - assert_eq!( - >::bar::(&mock_foo, 789), - "Greetings".to_string() - ); -} -- cgit v1.2.3-18-g5258