Skip to content

fmt: restore GNU compatibility for tests/fmt/width#11073

Merged
cakebaker merged 1 commit intouutils:mainfrom
karanabe:test/fix-gnu-fmt-width
Feb 24, 2026
Merged

fmt: restore GNU compatibility for tests/fmt/width#11073
cakebaker merged 1 commit intouutils:mainfrom
karanabe:test/fix-gnu-fmt-width

Conversation

@karanabe
Copy link
Contributor

@karanabe karanabe commented Feb 23, 2026

This PR fixes fmt line wrapping to match GNU coreutils behavior for tests/fmt/width. In particular, fmt -w 7 for aa bb cc dd ee now produces aa, bb cc, dd ee, which matches GNU.

The change updates Knuth-Plass scoring to avoid dropping valid short-line candidates, evaluates break-before and break-after candidates independently, and applies orphan-style penalties for sentence-final placement. It also adds a regression test covering both -w 7 and -w 8.

Specifically, for input aa bb cc dd ee, fmt -w 7 now produces:
Before

aa bb
cc dd
ee

After (GNU-compatible)

aa
bb cc
dd ee

@karanabe karanabe force-pushed the test/fix-gnu-fmt-width branch from 76f1edc to 17733ee Compare February 23, 2026 14:12
Align fmt line-breaking with GNU coreutils 9.10 for the
tests/fmt/width case. The -w 7 input "aa bb cc dd ee" now
breaks as:
  aa
  bb cc
  dd ee

Update Knuth-Plass scoring to keep finite penalties,
evaluate break-before candidates, and apply orphan penalties.
Add a regression test for -w 7 and -w 8 behavior.
@karanabe karanabe force-pushed the test/fix-gnu-fmt-width branch from 17733ee to 04015af Compare February 23, 2026 14:41
@cakebaker cakebaker merged commit c138b38 into uutils:main Feb 24, 2026
157 checks passed
@cakebaker
Copy link
Contributor

Thanks!

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.

2 participants