Skip to content

Commit 5afd696

Browse files
calendar: add snapshot test for Date::try_add_with_options across calendars and durations
1 parent b6b00b9 commit 5afd696

10 files changed

+165
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use icu_calendar::{
2+
options::DateAddOptions, types::DateDuration, AnyCalendar, AnyCalendarKind, Date,
3+
};
4+
use insta::assert_debug_snapshot;
5+
6+
#[test]
7+
fn test_date_add_across_calendars_and_durations() {
8+
let calendars = vec![
9+
AnyCalendarKind::Iso,
10+
AnyCalendarKind::Gregorian,
11+
AnyCalendarKind::Buddhist,
12+
];
13+
14+
let iso_dates = vec![(2023, 1, 1), (2024, 6, 15), (2025, 12, 31)];
15+
16+
let durations = vec![
17+
DateDuration {
18+
years: 0,
19+
months: 0,
20+
weeks: 0,
21+
days: 10,
22+
is_negative: false,
23+
},
24+
DateDuration {
25+
years: 0,
26+
months: 2,
27+
weeks: 0,
28+
days: 0,
29+
is_negative: false,
30+
},
31+
DateDuration {
32+
years: 1,
33+
months: 0,
34+
weeks: 0,
35+
days: 0,
36+
is_negative: false,
37+
},
38+
DateDuration {
39+
years: 1,
40+
months: 3,
41+
weeks: 0,
42+
days: 15,
43+
is_negative: false,
44+
},
45+
];
46+
47+
let opts = DateAddOptions::default();
48+
49+
for (y, m, d) in &iso_dates {
50+
for duration in &durations {
51+
for cal_kind in &calendars {
52+
let cal = AnyCalendar::new(*cal_kind);
53+
54+
let mut date = Date::try_new_iso(*y, *m, *d)
55+
.expect("Valid ISO date")
56+
.to_calendar(cal.clone());
57+
58+
date.try_add_with_options(*duration, opts)
59+
.expect("Addition should succeed");
60+
61+
let result_iso = date.to_iso();
62+
63+
assert_debug_snapshot!(
64+
format!("{:?}_{:?}_{:?}_{:?}", y, m, d, cal_kind),
65+
(
66+
format!("Start: {:?}-{:?}-{:?}", y, m, d),
67+
format!("Calendar: {:?}", cal_kind),
68+
format!("Duration added: {:?}", duration),
69+
format!("Resulting ISO date: {:?}", result_iso)
70+
)
71+
);
72+
}
73+
}
74+
}
75+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: components/calendar/tests/date_addition_snapshot.rs
3+
expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
4+
---
5+
(
6+
"Start: 2023-1-1",
7+
"Calendar: Buddhist",
8+
"Duration added: DateDuration { is_negative: false, years: 1, months: 3, weeks: 0, days: 15 }",
9+
"Resulting ISO date: Date(2024-4-16, default era, for calendar ISO)",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: components/calendar/tests/date_addition_snapshot.rs
3+
expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
4+
---
5+
(
6+
"Start: 2023-1-1",
7+
"Calendar: Gregorian",
8+
"Duration added: DateDuration { is_negative: false, years: 1, months: 3, weeks: 0, days: 15 }",
9+
"Resulting ISO date: Date(2024-4-16, default era, for calendar ISO)",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: components/calendar/tests/date_addition_snapshot.rs
3+
expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
4+
---
5+
(
6+
"Start: 2023-1-1",
7+
"Calendar: Iso",
8+
"Duration added: DateDuration { is_negative: false, years: 1, months: 3, weeks: 0, days: 15 }",
9+
"Resulting ISO date: Date(2024-4-16, default era, for calendar ISO)",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: components/calendar/tests/date_addition_snapshot.rs
3+
expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
4+
---
5+
(
6+
"Start: 2024-6-15",
7+
"Calendar: Buddhist",
8+
"Duration added: DateDuration { is_negative: false, years: 1, months: 3, weeks: 0, days: 15 }",
9+
"Resulting ISO date: Date(2025-9-30, default era, for calendar ISO)",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: components/calendar/tests/date_addition_snapshot.rs
3+
expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
4+
---
5+
(
6+
"Start: 2024-6-15",
7+
"Calendar: Gregorian",
8+
"Duration added: DateDuration { is_negative: false, years: 1, months: 3, weeks: 0, days: 15 }",
9+
"Resulting ISO date: Date(2025-9-30, default era, for calendar ISO)",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: components/calendar/tests/date_addition_snapshot.rs
3+
expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
4+
---
5+
(
6+
"Start: 2024-6-15",
7+
"Calendar: Iso",
8+
"Duration added: DateDuration { is_negative: false, years: 1, months: 3, weeks: 0, days: 15 }",
9+
"Resulting ISO date: Date(2025-9-30, default era, for calendar ISO)",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: components/calendar/tests/date_addition_snapshot.rs
3+
expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
4+
---
5+
(
6+
"Start: 2025-12-31",
7+
"Calendar: Buddhist",
8+
"Duration added: DateDuration { is_negative: false, years: 1, months: 3, weeks: 0, days: 15 }",
9+
"Resulting ISO date: Date(2027-4-15, default era, for calendar ISO)",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: components/calendar/tests/date_addition_snapshot.rs
3+
expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
4+
---
5+
(
6+
"Start: 2025-12-31",
7+
"Calendar: Gregorian",
8+
"Duration added: DateDuration { is_negative: false, years: 1, months: 3, weeks: 0, days: 15 }",
9+
"Resulting ISO date: Date(2027-4-15, default era, for calendar ISO)",
10+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: components/calendar/tests/date_addition_snapshot.rs
3+
expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
4+
---
5+
(
6+
"Start: 2025-12-31",
7+
"Calendar: Iso",
8+
"Duration added: DateDuration { is_negative: false, years: 1, months: 3, weeks: 0, days: 15 }",
9+
"Resulting ISO date: Date(2027-4-15, default era, for calendar ISO)",
10+
)

0 commit comments

Comments
 (0)