-
Notifications
You must be signed in to change notification settings - Fork 238
calendar: add snapshot test for Date::try_add_with_options (clean version) #7226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
calendar: add snapshot test for Date::try_add_with_options (clean version) #7226
Conversation
|
This still changes a lot of files that it shouldn't. Please verify your PRs before making them. Are you using AI to make these? I think we're giving you the same feedback multiple times. |
|
The 3rd last commit which i did did all those changes you asked for perfectly. but then some workflows were failing. so I then again ran the commands and then did git add . for that purpose. |
|
I see now - I will ensure my subsequent PRs only contain the file change that was intended. I am not using AI to create code- but I have been learning and validating everything manually, using guidance to understand how to do that better. I will tidy this up in due course and submit a more focused PR. |
|
Please use one PR instead of opening new PRs every time. |
|
Thank you for your explanation! |
6b4a691 to
e566546
Compare
…endars and durations
e566546 to
5afd696
Compare
|
I did a rebase onto the latest main branch and confirmed the only changes are in the snapshot test files under components/calendar/tests/. I also ran cargo fmt and clippy locally with no warnings. The snapshot tests are working and are ready for review. Also, thanks for the feedback earlier — I've ensured this is PR is only on the tests I intended to cover. |
|
Hi Manishearth Just to clarify, I’m not using AI-generated code; I’ve been writing and testing these changes manually but was still learning the correct workflow for your repo. |
Manishearth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would prefer the output snapshot to be a single file with all of the individual snapshots contained in it.
You can do this by collecting up a big string.
| expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))" | ||
| --- | ||
| ( | ||
| "Start: 2023-1-1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggested format so that this fits in one line:
y-m-d (Buddhist) + DateDuration {....} = Date(y-m-d, ....)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I'm not sure if we should try and fit it on one line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it — thank you for the suggestion
I’ll modify the test to collect all individual snapshot outputs into a single string and assert once, as you suggested.
I’ll also experiment with the one-line format you mentioned to see if it remains readable.
I’ll push the updated version shortly.
…gle readable snapshot
|
I combined all the earlier individual snapshot tests into a single, more readable snapshot that loops through multiple ISO dates, calendar types (Iso, Gregorian, Buddhist), and different duration combinations. I have also removed the old redundant snapshot files to keep the test cleaner and easier to maintain. Hope this resolves the issue. |
| let calendars = vec![ | ||
| AnyCalendarKind::Iso, | ||
| AnyCalendarKind::Gregorian, | ||
| AnyCalendarKind::Buddhist, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: please include all calendars here.
| for (y, m, d) in &iso_dates { | ||
| for duration in &durations { | ||
| for cal_kind in &calendars { | ||
| let cal = AnyCalendar::new(*cal_kind); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is now just outputting a single file, instead of trying to collapse everything in one line, perhaps we can generate a nested list? Something like
- 2025-12-31
- Buddhist (Date (...))
- add(DateDuration {...}): Date(...)
- add(DateDuration {...}): Date(...)
- add(DateDuration {...}): Date(...)
- Iso
- ...
- Buddhist (Date (...))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we actually produce a nested list instead of syntax heavy output?
I want this to be relatively readable, this is currently very messy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve reformatted the snapshot output into a nested list structure for better readability.
Each ISO start date now groups all calendars, and each calendar lists the durations and their resulting ISO dates in an indented format.
Hope this is the output you expected.
SATVIKsynopsis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve restructured the test output to generate a nested snapshot format as suggested.
The results are now grouped by start date → calendar → applied durations, so it’s much easier to inspect the behavior across different calendars for each date.
This structure also keeps the snapshot compact while still covering all possible combinations.
| date.try_add_with_options(*duration, opts) | ||
| .expect("Addition should succeed"); | ||
|
|
||
| let result_iso = date.to_iso(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be outputting the result in that calendar, not in ISO.
| writeln!(&mut output, "{}-{}-{}", y, m, d).unwrap(); | ||
|
|
||
| for cal_kind in &calendars { | ||
| writeln!(&mut output, " {:?}", cal_kind).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's compute date here and include it in the output, since the per-calendar date will be different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve updated the test to output results in their respective calendars instead of converting to ISO. Each calendar section now includes both its localized starting date and all resulting dates within that same calendar.
Manishearth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test looks better now.
Potentially would be nice to have a more compact representation of per-calendar dates instead of the Debug output but that's a change that can be figured out later.
@sffc are there cases you'd like to see covered here?
|
Glad the structure looks good now. |
This PR adds a snapshot test for
Date::try_add_with_optionsto ensure that date addition usingDateDurationbehaves as expected and produces stable results.It is a clean recreation of the previous PR (#7221), which was linked to:
The earlier PR accidentally included unintended changes across many files after a rebase issue.
This one only contains the intended snapshot test additions under
components/calendar/tests/.