summaryrefslogtreecommitdiff
path: root/examples/generic_method.rs
blob: 8dc465005431373bf2a46c220612a7e9a103809a (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
use ridicule::mock;

trait Foo
{
    fn bar<Baz>(&self, num: u128) -> Baz;
}

mock! {
    MockFoo {}

    impl Foo for MockFoo
    {
        fn bar<Baz>(&self, num: u128) -> Baz;
    }
}

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

    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}");

        128u8
    });

    assert_eq!(mock_foo.bar::<String>(123), "Hello".to_string());

    assert_eq!(mock_foo.bar::<u8>(456), 128);
}