diff options
author | HampusM <hampus@hampusmat.com> | 2023-03-12 20:17:37 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-03-12 20:17:37 +0100 |
commit | 9e99dbb543ab92762b8c92f1d0ada9c99d7167c9 (patch) | |
tree | 7c6cd4899615acdfa27fcea86f217cba52b100cf /examples | |
parent | 9d3694c18d141d1ddffec4fc49a7d340bfdb5d3f (diff) |
add project & mock macro
Diffstat (limited to 'examples')
-rw-r--r-- | examples/simple.rs | 45 |
1 files changed, 45 insertions, 0 deletions
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<Baz>(&self, num: u128) -> Baz; + + fn biz<Fiz: Debug, Bar>(&self, fiz: Fiz) -> &Bar; + + fn baz<Foobar>(&self, name: &str, foobar: Foobar) + where + Foobar: SomeFoobar; +} + +mock! { + MockFoo; + + impl Foo for MockFoo { + fn bar<Baz>(self: (&Self), num: u128) -> Baz; + + fn biz<Fiz: (Debug +), Bar>(self: (&Self), fiz: Fiz) -> &Bar; + + fn baz<Foobar>(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); +} |