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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Write more compact unit tests with a small macro.
/// This macro takes a test name, a closure and its expected value, and translates them into a unit test.
/// # Examples
/// ```
/// unit_test!(test1, || some_function_in_scope("test").unwrap(), "expected output")
/// ```
/// automatically gets translated in compile time to a standard test:
/// ```
/// #[cfg(test)]
/// mod test1 {
/// use super::*;
///
/// #[test]
/// fn tiny_test() {
/// assert_eq!(some_function_in_scope("test").unwrap(), "expected output");
/// }
/// }
/// ```
/// the same applies for this more complex closure:
/// ```
/// unit_test!(test2, || {
/// let mut c = some_function_in_scope("test").unwrap().chars()
/// c.next();
/// c.next_back();
/// (
/// c.collect::<String>(),
/// some_other_function_in_scope(73)
/// )
/// }, (
/// "expected output".to_string(),
/// 21
/// )
/// )
/// ```
/// that translates to:
/// ```
/// #[cfg(test)]
/// mod test2 {
/// use super::*;
///
/// #[test]
/// fn tiny_test() {
/// assert_eq!(
/// {
/// let mut c = some_function_in_scope("test").unwrap().chars()
/// c.next();
/// c.next_back();
/// (
/// c.collect::<String>(),
/// some_other_function_in_scope(73)
/// )
/// }, (
/// "expected output".to_string(),
/// 21
/// )
/// );
/// }
/// }
/// ```