summaryrefslogtreecommitdiff
path: root/tests/misc
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-06-19 19:18:21 +0100
committerPádraig Brady <P@draigBrady.com>2015-06-21 04:16:29 +0100
commit0a279f619055cc165bb3cfa3bb737cdd28ed4d70 (patch)
tree6149ce7f474051369efba96680228e3e0b5716db /tests/misc
parent71063bc858cd927e3622b511297e66b3e13f7453 (diff)
downloadcoreutils-0a279f619055cc165bb3cfa3bb737cdd28ed4d70.tar.xz
numfmt: support user specified output precision
* src/numfmt.c (usage): Update the --format description to indicate precision is allowed. (parse_format_string): Parse a precision specification like the standard printf does. (double_to_human): Honor the precision in --to mode. * tests/misc/numfmt.pl: New tests. * doc/coreutils.texi (numfmt invocation): Mention the new feature. * NEWS: Likewise.
Diffstat (limited to 'tests/misc')
-rwxr-xr-xtests/misc/numfmt.pl21
1 files changed, 19 insertions, 2 deletions
diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl
index 630d18707..4ed1d666d 100755
--- a/tests/misc/numfmt.pl
+++ b/tests/misc/numfmt.pl
@@ -648,6 +648,23 @@ my @Tests =
"(cannot handle values > 999Y)\n"},
{EXIT => 2}],
+ # precision override
+ ['precision-1','--format=%.4f 9991239123 --to=si', {OUT=>"9.9913G"}],
+ ['precision-2','--format=%.1f 9991239123 --to=si', {OUT=>"10.0G"}],
+ ['precision-3','--format=%.1f 1', {OUT=>"1.0"}],
+ ['precision-4','--format=%.1f 1.12', {OUT=>"1.2"}],
+ ['precision-5','--format=%.1f 9991239123 --to-unit=G', {OUT=>"10.0"}],
+ ['precision-6','--format="% .1f" 9991239123 --to-unit=G', {OUT=>"10.0"}],
+ ['precision-7','--format=%.-1f 1.1',
+ {ERR => "$prog: invalid precision in format '%.-1f'\n"},
+ {EXIT => 1}],
+ ['precision-8','--format=%.+1f 1.1',
+ {ERR => "$prog: invalid precision in format '%.+1f'\n"},
+ {EXIT => 1}],
+ ['precision-9','--format="%. 1f" 1.1',
+ {ERR => "$prog: invalid precision in format '%. 1f'\n"},
+ {EXIT => 1}],
+
# debug warnings
['debug-1', '--debug 4096', {OUT=>"4096"},
{ERR=>"$prog: no conversion option specified\n"}],
@@ -715,11 +732,11 @@ my @Tests =
{EXIT=>1}],
['fmt-err-4', '--format "%d"',
{ERR=>"$prog: invalid format '%d', " .
- "directive must be %[0]['][-][N]f\n"},
+ "directive must be %[0]['][-][N][.][N]f\n"},
{EXIT=>1}],
['fmt-err-5', '--format "% -43 f"',
{ERR=>"$prog: invalid format '% -43 f', " .
- "directive must be %[0]['][-][N]f\n"},
+ "directive must be %[0]['][-][N][.][N]f\n"},
{EXIT=>1}],
['fmt-err-6', '--format "%f %f"',
{ERR=>"$prog: format '%f %f' has too many % directives\n"},