summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-03-18 17:14:42 +0100
committerHampusM <hampus@hampusmat.com>2023-03-18 17:15:30 +0100
commitc48271aef7e6b0819c497f302127c161845a83d7 (patch)
treea18d7b5fc8e017b4b7e0917a55534b28a01fe57d /examples
parent2ca8017deebe7bfe5aac368aead777a2c4910ca2 (diff)
refactor: rewrite the mock macro as a procedural macro
Diffstat (limited to 'examples')
-rw-r--r--examples/simple.rs20
1 files changed, 15 insertions, 5 deletions
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<Baz>(self: (&Self), num: u128) -> Baz;
+ fn bar<Baz>(&self, num: u128) -> Baz;
- fn biz<Fiz: (Debug +), Bar>(self: (&Self), fiz: Fiz) -> &Bar;
+ fn biz<'a, Fiz: Debug, Bar>(&'a self, fiz: Fiz) -> &'a Bar;
- fn baz<Foobar>(self: (&Self), name: &str, foobar: Foobar)
+ fn baz<Foobar>(&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::<u128>().returning(|_me, num| {
+ println!("bar was called with {num}");
+
+ 136322
});
- mock_foo.bar::<()>(123);
+ assert_eq!(mock_foo.bar::<String>(123), "Hello".to_string());
+
+ assert_eq!(mock_foo.bar::<u128>(456), 136322);
}