extern crate simulacrum_macros;
use simulacrum_macros::*;
trait CoolTrait {
fn foo(&self);
fn bar(&mut self);
fn goop(&mut self, flag: bool) -> u32;
fn zing(&self, first: i32, second: bool);
fn boop(&self, name: &'static str);
fn store(&self, val: &i64);
fn toggle(&self, bit: &mut bool);
unsafe fn ohno(&self);
}
create_mock! {
impl CoolTrait for CoolTraitMock (self) {
expect_foo("foo"):
fn foo(&self);
expect_bar("bar"):
fn bar(&mut self);
expect_goop("goop"):
fn goop(&mut self, flag: bool) -> u32;
expect_zing("zing"):
fn zing(&self, first: i32, second: bool);
expect_boop("boop"):
fn boop(&self, name: &'static str);
expect_store("store"):
fn store(&self, val: &i64);
expect_toggle("toggle"):
fn toggle(&self, bit: &mut bool);
expect_ohno("ohno"):
unsafe fn ohno(&self);
}
}
fn main() {
let mut m = CoolTraitMock::new();
m.expect_bar().called_never();
m.expect_foo().called_once();
m.then().expect_goop().called_once().with(true).returning(|_| 5);
m.then().expect_zing().called_once().with(params!(13, false));
m.expect_boop().called_times(2);
m.expect_store().called_once().with(deref(777));
m.expect_toggle().called_once().with(deref(true))
.modifying(|&mut arg| { unsafe { *arg = false } });
m.expect_ohno().called_once();
m.foo();
assert_eq!(m.goop(true), 5);
m.zing(13, false);
m.boop("hey");
m.boop("yo");
m.store(&777);
let mut b = true;
m.toggle(&mut b);
assert_eq!(b, false);
unsafe {
m.ohno();
}
}