rateslib/scheduling/
serde.rs1use crate::json::JSON;
2use crate::scheduling::{Cal, Calendar, NamedCal, StubInference, UnionCal};
3
4impl JSON for Cal {}
5impl JSON for UnionCal {}
6impl JSON for NamedCal {}
7impl JSON for Calendar {}
8impl JSON for StubInference {}
9
10#[cfg(test)]
11mod tests {
12 use super::*;
13 use crate::scheduling::ndt;
14
15 #[test]
16 fn test_cal_json() {
17 let hols = vec![ndt(2015, 9, 8), ndt(2015, 9, 10)];
18 let hcal = Cal::new(hols, vec![5, 6]);
19 let js = hcal.to_json().unwrap();
20 let hcal2 = Cal::from_json(&js).unwrap();
21 assert_eq!(hcal, hcal2);
22 }
23
24 #[test]
25 fn test_union_cal_json() {
26 let hols = vec![ndt(2015, 9, 8), ndt(2015, 9, 10)];
27 let settle = vec![ndt(2015, 9, 11)];
28 let hcal = Cal::new(hols, vec![5, 6]);
29 let scal = Cal::new(settle, vec![5, 6]);
30 let ucal = UnionCal::new(vec![hcal], vec![scal].into());
31 let js = ucal.to_json().unwrap();
32 let ucal2 = UnionCal::from_json(&js).unwrap();
33 assert_eq!(ucal, ucal2);
34 }
35
36 #[test]
37 fn test_named_cal_json() {
38 let ncal = NamedCal::try_new("tgt,ldn|fed").unwrap();
39 let js = ncal.to_json().unwrap();
40 let ncal2 = NamedCal::from_json(&js).unwrap();
41 assert_eq!(ncal, ncal2);
42 }
43
44 #[test]
45 fn test_cal_type_json() {
46 let cal = Calendar::NamedCal(NamedCal::try_new("tgt,ldn|fed").unwrap());
47 let js = cal.to_json().unwrap();
48 let cal2 = Calendar::from_json(&js).unwrap();
49 assert_eq!(cal, cal2);
50 }
51
52 #[test]
53 fn test_stub_inf_json() {
54 let si = StubInference::LongBack;
55 let js = si.to_json().unwrap();
56 let si2 = StubInference::from_json(&js).unwrap();
57 assert_eq!(si, si2);
58 }
59}