From c48271aef7e6b0819c497f302127c161845a83d7 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 18 Mar 2023 17:14:42 +0100 Subject: refactor: rewrite the mock macro as a procedural macro --- examples/simple.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'examples/simple.rs') diff --git a/examples/simple.rs b/examples/simple.rs index a5b7203..cb6feb9 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -19,14 +19,14 @@ trait Foo } mock! { - MockFoo; + MockFoo {} impl Foo for MockFoo { - fn bar(self: (&Self), num: u128) -> Baz; + fn bar(&self, num: u128) -> Baz; - fn biz(self: (&Self), fiz: Fiz) -> &Bar; + fn biz<'a, Fiz: Debug, Bar>(&'a self, fiz: Fiz) -> &'a Bar; - fn baz(self: (&Self), name: &str, foobar: Foobar) + fn baz(&self, name: &str, foobar: Foobar) where Foobar: SomeFoobar + Debug; } @@ -38,7 +38,17 @@ fn main() 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}"); + + 136322 }); - mock_foo.bar::<()>(123); + assert_eq!(mock_foo.bar::(123), "Hello".to_string()); + + assert_eq!(mock_foo.bar::(456), 136322); } -- cgit v1.2.3-18-g5258