| 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 |
use crate::calendar_arithmetic::{CONSTRUCTOR_YEAR_RANGE, VALID_RD_RANGE}; |
| 6 |
use crate::*; |
| 7 |
|
| 8 |
// Check rd -> date -> iso -> date -> rd for whole range |
| 9 |
super::test_all_cals!( |
| 10 |
#[ignore] // takes about 200 seconds in release-with-assertions |
| 11 |
fn check_round_trip<C: Calendar + Copy>(cal: C) { |
| 12 |
let low = *VALID_RD_RANGE.start(); |
| 13 |
let high = *VALID_RD_RANGE.end(); |
| 14 |
let mut prev = Date::from_rata_die(low, cal); |
| 15 |
let mut curr = low + 1; |
| 16 |
while curr <= high { |
| 17 |
let date = Date::from_rata_die(curr, cal); |
| 18 |
assert!(prev < date); |
| 19 |
|
| 20 |
assert_eq!( |
| 21 |
date.to_rata_die(), |
| 22 |
curr, |
| 23 |
"{}", |
| 24 |
cal.as_calendar().debug_name() |
| 25 |
); |
| 26 |
|
| 27 |
prev = date; |
| 28 |
curr += 1; |
| 29 |
} |
| 30 |
} |
| 31 |
); |
| 32 |
|
| 33 |
super::test_all_cals!( |
| 34 |
#[ignore] // takes about 90 seconds in release-with-assertions |
| 35 |
fn check_from_fields<C: Calendar + Copy>(cal: C) { |
| 36 |
let months = (1..19) |
| 37 |
.flat_map(|i| [types::Month::new(i), types::Month::leap(i)].into_iter()) |
| 38 |
.collect::<Vec<_>>(); |
| 39 |
for year in CONSTRUCTOR_YEAR_RANGE { |
| 40 |
if year % 50000 == 0 { |
| 41 |
println!("{} {year:?}", cal.as_calendar().debug_name()); |
| 42 |
} |
| 43 |
for overflow in [options::Overflow::Constrain, options::Overflow::Reject] { |
| 44 |
#![allow(clippy::field_reassign_with_default)] // use public API |
| 45 |
let mut options = options::DateFromFieldsOptions::default(); |
| 46 |
options.overflow = Some(overflow); |
| 47 |
for mut fields in months |
| 48 |
.iter() |
| 49 |
.map(|&m| { |
| 50 |
let mut fields = types::DateFields::default(); |
| 51 |
fields.month = Some(m); |
| 52 |
fields |
| 53 |
}) |
| 54 |
.chain((1..20).map(|m| { |
| 55 |
let mut fields = types::DateFields::default(); |
| 56 |
fields.ordinal_month = Some(m); |
| 57 |
fields |
| 58 |
})) |
| 59 |
{ |
| 60 |
for day in 1..50 { |
| 61 |
fields.extended_year = Some(year); |
| 62 |
fields.day = Some(day); |
| 63 |
let _ = Date::try_from_fields(fields, options, cal); |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
); |