Page MenuHomeFreeBSD

libutil: Better tests for expand_number(3)
ClosedPublic

Authored by des on Jun 28 2019, 6:17 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 17, 10:54 AM
Unknown Object (File)
Fri, Oct 10, 3:35 PM
Unknown Object (File)
Fri, Oct 10, 12:47 PM
Unknown Object (File)
Fri, Oct 10, 12:47 PM
Unknown Object (File)
Fri, Oct 10, 12:47 PM
Unknown Object (File)
Fri, Oct 10, 12:46 PM
Unknown Object (File)
Fri, Oct 10, 5:56 AM
Unknown Object (File)
Thu, Oct 9, 8:13 PM
Subscribers

Details

Summary

Note that some tests currently fail and are commented out. The
manpage is pretty weak on the supported format. One of des' commits
claim negative numbers aren't supported, but humanize_number(3)
supports them. Note that negative numbers without suffixes do work if
you cast the result, but negative numbers with scales are incorrectly
detected as overflow. Some other questions I have:

  • Should we only support decimal since that is what humanize_number(3) generates?
  • Should we support negative numbers?

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

One more question, should we fail for trailing garbage? I think we should but we don't currently.

pstef added a subscriber: pstef.
@jhb wrote:

Should we only support decimal since that is what humanize_number(3) generates?

My answer would be a no. Input might come from elsewhere and this is true for code that possibly exists now and also code that might be written in the future.

Should we support negative numbers?

It would be a nice feature, but seems out of scope of this change.

One more question, should we fail for trailing garbage? I think we should but we don't currently.

I think we should, as it seems that a consumer would still be able to accept the result regardless (by reading num and ignoring the returned -1). But I'd suggest doing that via separate review/commit in order avoid blocking this one.

This revision is now accepted and ready to land.Sep 24 2021, 10:41 AM
des retitled this revision from Add tests for expand_number(3). to libutil: Better tests for expand_number(3).
des edited the test plan for this revision. (Show Details)
des edited reviewers, added: jhb; removed: des.
This revision now requires review to proceed.Jul 25 2025, 9:33 PM
This revision was not accepted when it landed; it landed in state Needs Review.Aug 2 2025, 2:07 PM
This revision was automatically updated to reflect the committed changes.