[Toybox] fmt tests.

enh enh at google.com
Fri Jun 22 13:24:24 PDT 2018


On Wed, Jun 20, 2018 at 10:30 PM Rob Landley <rob at landley.net> wrote:
>
> So I redid fmt.c and think it's ready to promote, but now I'm tweaking it to
> pass the fmt tests and... making them match what ubuntu's doing exactly is weird?
>
> $ echo -e 'hello world\n this is some text' | fmt -w 10
> hello
> world
>  this
>  is some
>  text
> $ echo -e 'hello world\n this is some text' | ./fmt -w 10
> hello
> world
>  this is
>  some
>  text
>
> Why is ubuntu _not_ producing the second output? If -w means wrap before this
> column, then space, 4 char word, space, 2 char word is 8 characters which is
> less than 10. (Heck, it's less than 9.) So why does "this" wind up on its own
> line on line 3 in ubuntu's version?

iirc i read somewhere that FSF fmt now uses the TeX algorithm. for my
purposes, traditional Unix "first fit" was fine, so that's all i did.

yeah, here you go:

   ‘fmt’ prefers breaking lines at the end of a sentence, and tries to
avoid line breaks after the first word of a sentence or before the last
word of a sentence.  A “sentence break” is defined as either the end of
a paragraph or a word ending in any of ‘.?!’, followed by two spaces or
end of line, ignoring any intervening parentheses or quotes.  Like TeX,
‘fmt’ reads entire “paragraphs” before choosing line breaks; the
algorithm is a variant of that given by Donald E. Knuth and Michael F.
Plass in “Breaking Paragraphs Into Lines”, ‘Software—Practice &
Experience’ 11, 11 (November 1981), 1119–1184.

> If you remove the space after the newline they match, but testing fmt without
> indentation is missing like half the logic? I made the existing tests pass, but
> I want to add tests to actually test what the new one is doing, like measuring
> and preserving tab/space mixes in indents. But fmt turns into weird corner case
> city. I ran the README and main.c through it when developing it, but that's not
> a stable test I can put in the test suite...

yeah, i hit this too, and most of my testing was done manually with
toybox's README. (sorry, i think the gap between me starting on fmt
and actually sending it in was large enough that i'd forgotten these
details.)

> Sigh. I can write tests that toybox passes, but a test that simply matches the
> output of a single implementation doesn't really prove much, does it? Grrr...
>
> *shrug* Probably promote it and cut a release this week anyway...
>
> Rob
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net



More information about the Toybox mailing list