From 0a279f619055cc165bb3cfa3bb737cdd28ed4d70 Mon Sep 17 00:00:00 2001 From: Pádraig Brady
Date: Fri, 19 Jun 2015 19:18:21 +0100 Subject: 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. --- tests/misc/numfmt.pl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'tests/misc') 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"}, -- cgit v1.2.3-70-g09d2