blob: 4262ee21ab23b8fb01d8e19dd40cb4299f4348d8 (
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
42
43
44
45
46
47
48
49
50
|
use std::fmt::Display;
use ridicule::mock;
trait Foo
{
fn bar<Baz: Display>(&self, num: u128) -> Baz;
fn abc<Baz: Display>(&mut self, baz: Baz);
}
mock! {
MockFoo {}
impl Foo for MockFoo
{
fn bar<Baz: Display>(&self, num: u128) -> Baz;
fn abc<Baz: Display>(&mut self, baz_baz: 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()
})
.times(3);
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::<String>(123), "Hello".to_string());
assert_eq!(mock_foo.bar::<String>(123), "Hello".to_string());
// Would panic
// mock_foo.bar::<String>(123);
assert_eq!(mock_foo.bar::<u8>(456), 128);
}
|