test: make date nanos test locale-agnostic (#1223) - #1230
Open
MsfPablo wants to merge 1 commit into
Open
Conversation
The `test_date_custom_format_supports_nanos_with_length` integration test
asserts the fractional-second output of `--date +testDateFormat%.3f`
matches the regex `testDateFormat\.[0-9]{3}` (a literal `.`).
chrono's `format_localized` renders `%.3f` using the active locale's
decimal separator, which is `,` in locales such as es_ES, de_DE and fr_FR
rather than `.`. On such locales the test fails:
assertion `left == right` failed
left: 0
right: 2
(the literal `.` matches 0 of the 2 `testDateFormat,NNN` lines)
The production behaviour — localising the decimal separator — is arguably
correct, so this is a test-only fix: accept either `.` or `,` as the
decimal separator (`testDateFormat[.,][0-9]{3}`). The assertion only cares
that three fractional digits follow a decimal separator.
Verified: test passes under es_ES (comma) and LC_ALL=C (dot); full
integration suite passes 43/0 under es_ES. No new clippy warnings.
Refs lsd-rs#1223
Author
|
Gentle ping — this one's still green and applies cleanly. Happy to rebase if it's gone stale on your end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1223.
test_date_custom_format_supports_nanos_with_lengthasserts the output of--date +testDateFormat%.3fmatches the regextestDateFormat\.[0-9]{3}(a literal.).Root cause
chrono's
format_localized(used forDateFlag::Formattedinsrc/meta/date.rs) renders the%.3ffractional seconds using the active locale's decimal separator. That separator is,in locales such ases_ES,de_DE,fr_FR— not.. On those locales the literal-.regex matches 0 of the 2testDateFormat,NNNlines, so the test fails:This reproduces on my machine (
LC_ALL=es_ES.UTF-8).Fix
The production behaviour — localising the decimal separator — is arguably correct (a user in
es_ESexpects,), so this is a test-only fix: accept either.or,as the decimal separator:The assertion only cares that three fractional digits follow a decimal separator, which holds under both separators.
Verification
cargo test --test integration test_date_custom_format_supports_nanos_with_lengthpasses underLC_ALL=es_ES.UTF-8(comma)LC_ALL=C(dot)es_ES.UTF-8: 43 passed, 0 failedcargo fmt --check: cleancargo clippy --tests: no new warnings introduced (7 pre-existing warnings are unchanged by this edit, confirmed via stash diff)🤖 This is an AI-assisted contribution. The analysis, root-cause investigation, and fix were produced with the help of an AI assistant (Claude Code) and reviewed by me; the code is my own and I stand behind it.