Skip to content

test: make date nanos test locale-agnostic (#1223) - #1230

Open
MsfPablo wants to merge 1 commit into
lsd-rs:mainfrom
MsfPablo:fix/locale-agnostic-date-nanos-test
Open

test: make date nanos test locale-agnostic (#1223)#1230
MsfPablo wants to merge 1 commit into
lsd-rs:mainfrom
MsfPablo:fix/locale-agnostic-date-nanos-test

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 9, 2026

Copy link
Copy Markdown

Summary

Fixes #1223.

test_date_custom_format_supports_nanos_with_length asserts the output of --date +testDateFormat%.3f matches the regex testDateFormat\.[0-9]{3} (a literal .).

Root cause

chrono's format_localized (used for DateFlag::Formatted in src/meta/date.rs) renders the %.3f fractional seconds using the active locale's decimal separator. That separator is , in locales such as es_ES, de_DE, fr_FR — not .. On those locales the literal-. regex matches 0 of the 2 testDateFormat,NNN lines, so the test fails:

assertion `left == right` failed
  left: 0
 right: 2

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_ES expects ,), so this is a test-only fix: accept either . or , as the decimal separator:

predicate::str::is_match("testDateFormat[.,][0-9]{3}")

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_length passes under LC_ALL=es_ES.UTF-8 (comma)
  • same test passes under LC_ALL=C (dot)
  • full integration suite under es_ES.UTF-8: 43 passed, 0 failed
  • cargo fmt --check: clean
  • cargo 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.

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
@MsfPablo

Copy link
Copy Markdown
Author

Gentle ping — this one's still green and applies cleanly. Happy to rebase if it's gone stale on your end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_date_custom_format_supports_nanos_with_length fails on macOS (aarch64-darwin)

1 participant