Debian Codegraph @

debian/rust-vendor/icu_calendar/src/tests/mod.rs

raw
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5 mod arithmetic;
6 mod constructor_roundtrip;
7 mod continuity_test;
8 mod date_arithmetic_snapshot;
9 mod exhaustive;
10 mod extended_year;
11 mod extrema;
12 mod month;
13 mod not_enough_fields;
14
15 use crate::Date;
16 use crate::types::Month;
17 use calendrical_calculations::rata_die::RataDie;
18
19 macro_rules! test_all_cals {
20 ($(#[$meta:meta])* fn $name:ident<C: Calendar + Copy>($cal:ident: C) $tt:tt) => {
21 mod $name {
22 #[allow(unused_imports)]
23 use super::*;
24
25 fn test<C: crate::Calendar + Copy>(cal: C) where Date<C>: Ord {
26 let $cal = cal;
27 $tt
28 }
29
30 $(#[$meta])*
31 #[test]
32 fn buddhist() {
33 test(crate::cal::Buddhist);
34 }
35
36 $(#[$meta])*
37 #[test]
38 fn chinese_traditional() {
39 test(crate::cal::east_asian_traditional::EastAsianTraditional(crate::cal::east_asian_traditional_internal::EastAsianTraditionalYears::china()));
40 }
41
42 $(#[$meta])*
43 #[test]
44 fn coptic() {
45 test(crate::cal::Coptic);
46 }
47
48 $(#[$meta])*
49 #[test]
50 fn korean_traditional() {
51 test(crate::cal::east_asian_traditional::EastAsianTraditional(crate::cal::east_asian_traditional_internal::EastAsianTraditionalYears::korea()));
52 }
53
54 $(#[$meta])*
55 #[test]
56 fn ethiopian() {
57 test(crate::cal::Ethiopian::new());
58 }
59
60 $(#[$meta])*
61 #[test]
62 fn ethiopian_amete_alem() {
63 test(crate::cal::Ethiopian::new_with_era_style(crate::cal::EthiopianEraStyle::AmeteAlem));
64 }
65
66 $(#[$meta])*
67 #[test]
68 fn gregorian() {
69 test(crate::cal::Gregorian);
70 }
71
72 $(#[$meta])*
73 #[test]
74 fn hebrew() {
75 test(crate::cal::Hebrew::new());
76 }
77
78 $(#[$meta])*
79 #[test]
80 fn hijri_tabular_friday() {
81 test(crate::cal::Hijri::new_tabular(crate::cal::hijri::TabularAlgorithmLeapYears::TypeII, crate::cal::hijri::TabularAlgorithmEpoch::Friday));
82 }
83
84 $(#[$meta])*
85 #[test]
86 fn hijri_tabular_thursday() {
87 test(crate::cal::Hijri::new_tabular(crate::cal::hijri::TabularAlgorithmLeapYears::TypeII, crate::cal::hijri::TabularAlgorithmEpoch::Thursday));
88 }
89
90 $(#[$meta])*
91 #[test]
92 fn hijri_uaq() {
93 test(crate::cal::Hijri::new_umm_al_qura());
94 }
95
96 $(#[$meta])*
97 #[test]
98 fn indian() {
99 test(crate::cal::Indian::new());
100 }
101
102 $(#[$meta])*
103 #[test]
104 fn iso() {
105 test(crate::cal::Iso::new());
106 }
107
108 $(#[$meta])*
109 #[test]
110 fn julian() {
111 test(crate::cal::Julian::new());
112 }
113
114 $(#[$meta])*
115 #[test]
116 fn japanese() {
117 test(crate::cal::Japanese::new());
118 }
119
120 $(#[$meta])*
121 #[test]
122 fn persian() {
123 test(crate::cal::Persian::new());
124 }
125
126 $(#[$meta])*
127 #[test]
128 fn roc() {
129 test(crate::cal::Roc);
130 }
131 }
132 };
133 }
134 use test_all_cals;
135
136 pub(crate) fn get_interesting_rds() -> Vec<RataDie> {
137 let mut rds = Vec::new();
138
139 // Iso / Gregorian leap day
140 let date = Date::try_new_iso(2020, 2, 29).expect("2020-02-29 is a valid ISO date");
141 rds.push(date.to_rata_die());
142
143 // Hebrew leap month (Adar I) in leap year 5784
144 let date = Date::try_new_hebrew_v2(5784, Month::leap(5), 15).expect("Valid Hebrew date");
145 rds.push(date.to_rata_die());
146
147 // Hebrew Adar II in leap year 5784
148 let date = Date::try_new_hebrew_v2(5784, Month::new(6), 15).expect("Valid Hebrew date");
149 rds.push(date.to_rata_die());
150
151 // Hebrew non-Adar month in leap year 5784
152 let date = Date::try_new_hebrew_v2(5784, Month::new(1), 15).expect("Valid Hebrew date");
153 rds.push(date.to_rata_die());
154
155 // Chinese leap month date
156 let date =
157 Date::try_new_chinese_traditional(2023, Month::leap(2), 1).expect("Valid Chinese date");
158 rds.push(date.to_rata_die());
159
160 // Chinese leap year 2023, non-leap month
161 let date =
162 Date::try_new_chinese_traditional(2023, Month::new(1), 1).expect("Valid Chinese date");
163 rds.push(date.to_rata_die());
164
165 // Japanese era transition
166 let date = Date::try_new_japanese_with_calendar("reiwa", 1, 5, 1, crate::cal::Japanese::new())
167 .expect("Valid Japanese date");
168 rds.push(date.to_rata_die());
169
170 // Ethiopic month 13
171 let date = Date::try_new_ethiopian(crate::cal::EthiopianEraStyle::AmeteMihret, 2015, 13, 5)
172 .expect("Valid Ethiopian date");
173 rds.push(date.to_rata_die());
174
175 // Coptic month 13
176 let date = Date::try_new_coptic(1686, 13, 5).expect("Valid Coptic date");
177 rds.push(date.to_rata_die());
178
179 // Add some more general dates
180 rds.push(RataDie::new(0));
181 rds.push(RataDie::new(1));
182 rds.push(RataDie::new(-1));
183 rds.push(RataDie::new(730000)); // ~2000 CE
184 rds.push(RataDie::new(100));
185 rds.push(RataDie::new(-100));
186 rds.push(RataDie::new(1000000)); // ~2739 CE
187 rds.push(RataDie::new(-1000000)); // ~ -2739 CE
188 rds.push(RataDie::new(123456));
189 rds.push(RataDie::new(-123456));
190
191 rds
192 }