macros_high/
macros_high.rs1extern crate simulacrum;
11
12use simulacrum::*;
13
14trait CoolTrait {
15 fn foo(&self);
17
18 fn bar(&mut self);
20
21 fn goop(&mut self, flag: bool) -> u32;
23
24 fn zing(&self, first: i32, second: bool);
26
27 fn boop(&self, name: &'static str);
29
30 fn store(&self, val: &i64);
32
33 fn toggle(&self, bit: &mut bool);
35
36 unsafe fn ohno(&self);
38}
39
40create_mock! {
41 impl CoolTrait for CoolTraitMock (self) {
42 expect_foo("foo"):
43 fn foo(&self);
44
45 expect_bar("bar"):
46 fn bar(&mut self);
47
48 expect_goop("goop"):
49 fn goop(&mut self, flag: bool) -> u32;
50
51 expect_zing("zing"):
52 fn zing(&self, first: i32, second: bool);
53
54 expect_boop("boop"):
56 fn boop(&self, name: &'static str);
57
58 expect_store("store"):
60 fn store(&self, val: &i64);
61
62 expect_toggle("toggle"):
63 fn toggle(&self, bit: &mut bool);
64
65 expect_ohno("ohno"):
66 unsafe fn ohno(&self);
67 }
68}
69
70fn main() {
71 let mut m = CoolTraitMock::new();
73
74 m.expect_bar().called_never();
76 m.expect_foo().called_once();
77 m.then().expect_goop().called_once().with(true).returning(|_| 5);
78 m.then().expect_zing().called_once().with(params!(13, false));
79 m.expect_boop().called_times(2);
80 m.expect_store().called_once().with(deref(777));
81 m.expect_toggle().called_once().with(deref(true))
82 .modifying(|&mut arg| { unsafe { *arg = false } });
83 m.expect_ohno().called_once();
84
85 m.foo();
87 assert_eq!(m.goop(true), 5);
88 m.zing(13, false);
89 m.boop("hey");
90 m.boop("yo");
91 m.store(&777);
92 let mut b = true;
93 m.toggle(&mut b);
94 assert_eq!(b, false);
95 unsafe {
96 m.ohno();
97 }
98
99 }