fix(transactions): handle common irregular English plurals in pluralize()#136
Merged
Conversation
…uralize() `pluralize` in `entity/transaction.rs` only handled regular suffix rules (`+s`, `+es` after sibilants, consonant-y → -ies). Irregular nouns came out grammatically wrong in the transaction accessor names: child → childs (was) → children (now) person → persons (was) → people (now) mouse → mouses (was) → mice (now) goose → gooses (was) → geese (now) foot → foots (was) → feet (now) tooth → tooths (was) → teeth (now) man → mans (was) → men (now) woman → womans (was) → women (now) datum → datums (was) → data (now) criterion → criterions (was) → criteria (now) Not a data-corruption bug — the irregular only appeared in generated method names (`Transaction::with_<plural>()`, `ctx.<plural>()`) — but it made `#[entity(transactions)]` on entities like `Child` or `Person` look unpolished. New helper `irregular_plural(word)` looks up a small fixed table of the ten most common English irregulars (case-insensitive match on the singular, original casing preserved on the plural). `pluralize` checks it first and falls back to the existing regular-suffix logic on miss. Exact-word match only — `childcare` stays `childcares`, not `childrencare`. Tests: - 16 new lib unit tests in `entity::transaction::tests` covering all ten irregulars, the case-insensitive lookup, the compound-word guard, and the three regular paths (sibilants, consonant-y → -ies, vowel-y stays, default +s). Bump (changed crates only): - entity-derive-impl: 0.6.4 -> 0.6.5 - entity-derive: 0.8.5 -> 0.8.6 Out of scope: an explicit `#[entity(plural = "...")]` override for exotic plurals beyond the ten irregulars. If a real need surfaces, open a follow-up issue. Closes #135
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Closes #135
Summary
`pluralize` only handled regular suffix rules, so irregular nouns came out grammatically wrong in transaction accessor names. Not a data-corruption bug — only generated method names were affected — but ten common English irregulars now match expectation.
New helper `irregular_plural` checks a small fixed table first (case-insensitive on the singular, casing preserved on the plural). `pluralize` falls through to the existing regular logic on miss. Exact-word match only — `childcare → childcares` (not `childrencare`).
Tests
16 lib unit tests covering all ten irregulars, the case-insensitive lookup, the compound-word guard, and the four regular paths.
Version bump
`entity-core` is unchanged.
Test plan
Out of scope
`#[entity(plural = "...")]` override for exotic Latin/Greek/loanword plurals. Open a follow-up if a real entity name needs it.