-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfunction.rs
More file actions
51 lines (43 loc) · 1.14 KB
/
function.rs
File metadata and controls
51 lines (43 loc) · 1.14 KB
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
#[macro_use]
extern crate double;
fn generate_sequence(func: &dyn Fn(i32) -> i32, min: i32, max: i32) -> Vec<i32> {
// exclusive range
(min..max).map(func).collect()
}
fn test_function_used_correctly() {
// GIVEN:
mock_func!(
mock,
mock_fn,
i32, // return value type
i32); // argument1 type
mock.use_closure(Box::new(|x| x * 2));
// WHEN:
let sequence = generate_sequence(&mock_fn, 1, 5);
// THEN:
assert_eq!(vec!(2, 4, 6, 8), sequence);
assert!(mock.has_calls_exactly_in_order(vec!(
1, 2, 3, 4
)));
}
fn test_function_with_custom_defaults() {
// GIVEN:
mock_func_no_default!(
mock,
mock_fn,
i32, // return value type
42, // default return value
i32); // argument1 type
mock.use_closure_for(3, Box::new(|x| x * 2));
// WHEN:
let sequence = generate_sequence(&mock_fn, 1, 5);
// THEN:
assert_eq!(vec!(42, 42, 6, 42), sequence);
assert!(mock.has_calls_exactly_in_order(vec!(
1, 2, 3, 4
)));
}
fn main() {
test_function_used_correctly();
test_function_with_custom_defaults();
}