-
Notifications
You must be signed in to change notification settings - Fork 14
/
multi_mock.rs
58 lines (51 loc) · 987 Bytes
/
multi_mock.rs
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
51
52
53
54
55
56
57
58
#![allow(clippy::disallowed_names)]
#[faux::create]
struct Foo {
a: i32,
}
#[faux::methods]
impl Foo {
pub fn get(&self) -> i32 {
self.a
}
}
#[test]
fn always() {
let mut foo = Foo::faux();
faux::when!(foo.get).then(|_| 3);
for _ in 0..20 {
assert_eq!(foo.get(), 3);
}
}
#[test]
fn limited() {
let mut foo = Foo::faux();
faux::when!(foo.get).times(3).then(|_| 3);
for _ in 0..3 {
assert_eq!(foo.get(), 3);
}
}
#[test]
#[should_panic]
fn limited_past_limit() {
let mut foo = Foo::faux();
faux::when!(foo.get).times(3).then(|_| 3);
for _ in 0..3 {
foo.get();
}
foo.get(); // panics here
}
#[test]
fn once() {
let mut foo = Foo::faux();
faux::when!(foo.get).once().then(|_| 3);
assert_eq!(foo.get(), 3);
}
#[test]
#[should_panic]
fn once_past_limit() {
let mut foo = Foo::faux();
faux::when!(foo.get).once().then(|_| 3);
foo.get();
foo.get(); //panics here
}