From 9e99dbb543ab92762b8c92f1d0ada9c99d7167c9 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Mar 2023 20:17:37 +0100 Subject: add project & mock macro --- examples/simple.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/simple.rs (limited to 'examples/simple.rs') diff --git a/examples/simple.rs b/examples/simple.rs new file mode 100644 index 0000000..a0a5860 --- /dev/null +++ b/examples/simple.rs @@ -0,0 +1,45 @@ +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; +} + +mock! { + MockFoo; + + impl Foo for MockFoo { + fn bar(self: (&Self), num: u128) -> Baz; + + fn biz(self: (&Self), fiz: Fiz) -> &Bar; + + fn baz(self: (&Self), name: &str, foobar: Foobar) + where ( + Foobar: SomeFoobar + ); + } +} + +fn main() +{ + let mut mock_foo = MockFoo::new(); + + mock_foo.expect_bar().returning(|_me, num| { + println!("bar was called with {num}"); + }); + + mock_foo.bar::<()>(123); +} -- cgit v1.2.3-18-g5258