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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use super::*;
use std::fmt::Debug;
#[extend::ext(name=SweetOrd)]
pub impl<T: PartialOrd + Debug + Copy> T {
/// Performs an assertion ensuring this value is less than `other`.
///
/// ## Example
///
/// ```
/// # use sweet::prelude::*;
/// 1.xpect_less_than(2);
/// ```
///
/// ## Panics
///
/// Panics if the value is not less than `other`.
fn xpect_less_than(&self, other: T) -> &Self {
if *self < other {
self
} else {
assert_ext::panic_expected_received_display_debug(
&format!("less than {:?}", other),
self,
);
}
}
/// Performs an assertion ensuring this value is less or equal to `other`.
///
/// ## Example
///
/// ```
/// # use sweet::prelude::*;
/// 2.xpect_less_or_equal_to(2);
/// ```
///
/// ## Panics
///
/// Panics if the value is not less or equal to `other`.
fn xpect_less_or_equal_to(&self, other: T) -> &Self {
if *self <= other {
self
} else {
assert_ext::panic_expected_received_display_debug(
&format!("less or equal to {:?}", other),
self,
);
}
}
/// Performs an assertion ensuring this value is greater than `other`.
///
/// ## Example
///
/// ```
/// # use sweet::prelude::*;
/// 3.xpect_greater_than(2);
/// ```
///
/// ## Panics
///
/// Panics if the value is not greater than `other`.
fn xpect_greater_than(&self, other: T) -> &Self {
if *self > other {
self
} else {
assert_ext::panic_expected_received_display_debug(
&format!("greater than {:?}", other),
self,
);
}
}
/// Performs an assertion ensuring this value is greater or equal to `other`.
///
/// ## Example
///
/// ```
/// # use sweet::prelude::*;
/// 3.xpect_greater_or_equal_to(3);
/// ```
///
/// ## Panics
///
/// Panics if the value is not greater or equal to `other`.
fn xpect_greater_or_equal_to(&self, other: T) -> &Self {
if *self >= other {
self
} else {
assert_ext::panic_expected_received_display_debug(
&format!("greater or equal to {:?}", other),
self,
);
}
}
}
#[cfg(test)]
mod test {
use crate::prelude::*;
#[test]
fn order() {
0.xpect_greater_or_equal_to(0);
10.xpect_greater_than(-10);
10.xpect_less_or_equal_to(11);
}
}