use_test_expectation/
lib.rs1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4#[derive(Clone, Debug, Eq, Hash, PartialEq)]
6pub struct TestExpectation<T> {
7 pub expected: T,
8 pub actual: T,
9}
10
11impl<T> TestExpectation<T> {
12 pub const fn new(expected: T, actual: T) -> Self {
13 Self { expected, actual }
14 }
15
16 pub const fn expected(&self) -> &T {
17 &self.expected
18 }
19
20 pub const fn actual(&self) -> &T {
21 &self.actual
22 }
23
24 pub fn into_parts(self) -> (T, T) {
25 (self.expected, self.actual)
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use super::TestExpectation;
32
33 #[test]
34 fn stores_expected_and_actual_values() {
35 let expectation = TestExpectation::new("expected".to_string(), "actual".to_string());
36
37 assert_eq!(expectation.expected(), "expected");
38 assert_eq!(expectation.actual(), "actual");
39 }
40
41 #[test]
42 fn splits_into_parts() {
43 let expectation = TestExpectation::new(1, 2);
44
45 assert_eq!(expectation.into_parts(), (1, 2));
46 }
47}