1 //! Test use of `rdroidtest`.
2
3 use rdroidtest::{ptest, test};
4
5 // Tests using raw declarative macros.
6
7 test!(one_plus_one);
one_plus_one()8 fn one_plus_one() {
9 let result = 1 + 1;
10 assert_eq!(result, 2);
11 }
12
13 test!(grumble, ignore_if: feeling_happy());
grumble()14 fn grumble() {
15 let result = 1 + 1;
16 assert_eq!(result, 2);
17 }
18
19 test!(clap_hands, ignore_if: !feeling_happy());
clap_hands()20 fn clap_hands() {
21 let result = 1 + 1;
22 assert_eq!(result, 3);
23 }
24
feeling_happy() -> bool25 fn feeling_happy() -> bool {
26 false
27 }
28
29 ptest!(is_less_than_five, my_instances());
is_less_than_five(param: u32)30 fn is_less_than_five(param: u32) {
31 assert!(param < 5);
32 }
33
34 ptest!(is_even, my_instances(), ignore_if: feeling_odd);
is_even(param: u32)35 fn is_even(param: u32) {
36 assert_eq!(param % 2, 0);
37 }
38
39 ptest!(is_odd, my_instances(), ignore_if: |p| !feeling_odd(p));
is_odd(param: u32)40 fn is_odd(param: u32) {
41 assert_eq!(param % 2, 1);
42 }
43
feeling_odd(param: &u32) -> bool44 fn feeling_odd(param: &u32) -> bool {
45 *param % 2 == 1
46 }
47
my_instances() -> Vec<(String, u32)>48 fn my_instances() -> Vec<(String, u32)> {
49 vec![("one".to_string(), 1), ("two".to_string(), 2), ("three".to_string(), 3)]
50 }
51
52 ptest!(is_odder, wrapped_instances(), ignore_if: |p| !feeling_odder(p));
is_odder(param: Param)53 fn is_odder(param: Param) {
54 assert_eq!(param.0 % 2, 1);
55 }
56
feeling_odder(param: &Param) -> bool57 fn feeling_odder(param: &Param) -> bool {
58 param.0 % 2 == 1
59 }
60
61 struct Param(u32);
62
wrapped_instances() -> Vec<(String, Param)>63 fn wrapped_instances() -> Vec<(String, Param)> {
64 vec![
65 ("one".to_string(), Param(1)),
66 ("two".to_string(), Param(2)),
67 ("three".to_string(), Param(3)),
68 ]
69 }
70
71 ptest!(is_the_one, more_instances(), ignore_if: |p| p != "one");
is_the_one(param: String)72 fn is_the_one(param: String) {
73 assert_eq!(param, "one");
74 }
75
more_instances() -> Vec<(String, String)>76 fn more_instances() -> Vec<(String, String)> {
77 vec![("one".to_string(), "one".to_string()), ("two".to_string(), "two".to_string())]
78 }
79