Add regression test: Dehumanize() with trailing digit after a word - #1972
hikmetba-bit wants to merge 1 commit into
Conversation
Humanizr#1959 reported that "Item1".Dehumanize() returned "Item 1" in 3.0.1+ instead of "Item1" (v2.14.1 behavior), tracing it to PascalizePattern's capture group excluding digits. Traced the current Dehumanize() -> Humanize() -> Pascalize() chain by hand against the current ASCII fast paths (TryFromAsciiPascalCase / TryPascalizeAscii in StringHumanizeExtensions.cs / InflectorExtensions.cs): neither excludes digits from the "keep capitalizing/copying" logic the way the old PascalizePattern regex did, so "Item1" now round-trips correctly already. This appears to have been fixed as a side effect of the ASCII fast-path optimization added after this issue was filed (Pascalize's own test suite already covers the equivalent "customer name 1" -> "CustomerName1" case), but Dehumanize() itself had no regression test for this specific scenario. Adds that coverage so a future change to either fast path that reintroduces the regression fails a test instead of shipping silently. No production code change - Humanizr#1959 appears already fixed on main. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughChangesDehumanize test coverage
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~5 minutes Change: Other Merge Risk: ⚪ Minimal · up to This PR adds regression tests for the reported numeric-suffix behavior without changing production code; it is mergeable pending normal test execution when the .NET SDK is available. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Relates to #1959, which reported that
"Item1".Dehumanize()returned"Item 1"in 3.0.1+ instead of"Item1"(the v2.14.1 behavior), tracing the cause toPascalizePattern's capture group excluding digits.I went to fix
PascalizePattern, but tracing the current code by hand, I believe this is already fixed onmain— as a side effect of the ASCII fast-path optimizations added since the issue was filed, not the regex path the issue described:Dehumanize()callsword.Humanize().Pascalize().Humanize("Item1")goes throughTryFromAsciiPascalCase(inStringHumanizeExtensions.cs), which viaReadAsciiWordcorrectly splits the trailing digit run into its own word, producing"Item 1".Pascalize("Item 1")goes throughTryPascalizeAscii(inInflectorExtensions.cs), whose separator check isc is ' ' or '_' or '-' or '.'— digits are not excluded from the "keep capitalizing" logic the way the old regex's[a-zA-Z]capture group was, so the space before1is correctly stripped, giving back"Item1".This matches the existing
Pascalizetest suite, which already has[InlineData("customer name 1", "CustomerName1")]inInflectorTests.cs— the equivalent case forPascalizealone is already covered. What's missing is coverage for the exactDehumanize()round-trip from the issue.Change
Adds
[InlineData("Item1", "Item1")]and[InlineData("Item 1", "Item1")]toStringDehumanizeTests.CanDehumanizeIntoAPascalCaseWord. No production code changes.Test plan
TryFromAsciiPascalCaseandTryPascalizeAsciicharacter-by-character for both"Item1"and"Item 1", and cross-checked that trace with a direct line-for-line port of both functions' character loop to Python, run against both inputs, to make sure I wasn't making an arithmetic mistake tracing it manually. Both confirm the expected"Item1"result.main, this test will make that failure visible and point at the actual root cause directly — happy to turn it into a real code fix if so.🤖 Generated with Claude Code
Summary by CodeRabbit