summaryrefslogtreecommitdiff
path: root/examples/automock.rs
blob: a0d638a06299bf67f6b53d5726c0f109e70aa895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use cool_trais::Foo;
use ridicule::predicate::{always, eq};

use crate::cool_trais::MockFoo;

pub trait DoStuff<Thing> {}

impl<TFoo: Foo> DoStuff<TFoo> for f32 {}

mod cool_trais
{
    use ridicule::automock;

    use crate::DoStuff;

    #[automock]
    pub trait Foo: Sized
    {
        fn bar<Something>(&self, num: u128, text: &str) -> Something
        where
            Something: DoStuff<Self>;
    }
}

fn main()
{
    let mut mock_foo = MockFoo::new();

    unsafe {
        mock_foo
            .expect_bar()
            .with(eq(1234), always())
            .returning(|_, num, text| {
                println!("bar was called with {num} and '{text}'");

                9.36f32
            });
    }

    mock_foo.bar::<f32>(1234, "Hello");
}