summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2014-04-30 15:05:15 +0100
committerPádraig Brady <P@draigBrady.com>2014-05-02 01:59:31 +0100
commit10a96524355775e6d8533555f185656c7f29075c (patch)
tree67c8aa976f39add33397afdeeaae67800d1bb55f /tests
parent59eacf2764a522f017c8289be94162b6f5163e8f (diff)
downloadcoreutils-10a96524355775e6d8533555f185656c7f29075c.tar.xz
numfmt: support zero padding using --format="%010f"
* src/numfmt.c (setup_padding_buffer): Simplify the code by not explicitly dealing with heap exhaustion. (parse_format_string): Likewise. Handle multiple grouping modifiers as does the standard printf. Handle the new leading zero --format modifier. (double_to_human): Use more defensive coding against overwriting stack buffers. Honor the leading zeros width. (usage): Mention the leading zero --format modifier. (main): Allow --padding in combo with a --format (width), as the number of leading zeros are useful independent of the main field width. * doc/coreutils.texi (numfmt invocation): Likewise. * tests/misc/numfmt.pl: Add new test cases. * NEWS: Mention the improvement.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/misc/numfmt.pl25
1 files changed, 20 insertions, 5 deletions
diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl
index ca3c89675..dfb4b2e0a 100755
--- a/tests/misc/numfmt.pl
+++ b/tests/misc/numfmt.pl
@@ -695,11 +695,11 @@ my @Tests =
{EXIT=>1}],
['fmt-err-4', '--format "%d"',
{ERR=>"$prog: invalid format '%d', " .
- "directive must be %['][-][N]f\n"},
+ "directive must be %[0]['][-][N]f\n"},
{EXIT=>1}],
['fmt-err-5', '--format "% -43 f"',
{ERR=>"$prog: invalid format '% -43 f', " .
- "directive must be %['][-][N]f\n"},
+ "directive must be %[0]['][-][N]f\n"},
{EXIT=>1}],
['fmt-err-6', '--format "%f %f"',
{ERR=>"$prog: format '%f %f' has too many % directives\n"},
@@ -708,9 +708,6 @@ my @Tests =
{ERR=>"$prog: invalid format '%123456789012345678901234567890f'".
" (width overflow)\n"},
{EXIT=>1}],
- ['fmt-err-8', '--format "%f" --padding 20',
- {ERR=>"$prog: --padding cannot be combined with --format\n"},
- {EXIT=>1}],
['fmt-err-9', '--format "%f" --grouping',
{ERR=>"$prog: --grouping cannot be combined with --format\n"},
{EXIT=>1}],
@@ -748,6 +745,17 @@ my @Tests =
['fmt-15', '--format "--%100000f--" --to=si 4200',
{OUT=>"--" . " " x 99996 . "4.2K--" }],
+ # --format padding overrides --padding
+ ['fmt-16', '--format="%6f" --padding=66 1234',{OUT=>" 1234"}],
+
+ # zero padding
+ ['fmt-17', '--format="%06f" 1234',{OUT=>"001234"}],
+ # also support spaces (which are ignored as spacing is handled separately)
+ ['fmt-18', '--format="%0 6f" 1234',{OUT=>"001234"}],
+ # handle generic padding in combination
+ ['fmt-22', '--format="%06f" --padding=7 1234',{OUT=>" 001234"}],
+ ['fmt-23', '--format="%06f" --padding=-7 1234',{OUT=>"001234 "}],
+
## Check all errors again, this time with --invalid=fail
## Input will be printed without conversion,
@@ -881,6 +889,13 @@ my @Locale_Tests =
['lcl-fmt-4', '--format "--%-10f--" --to=si 5000000',
{OUT=>"--5,0M --"},
{ENV=>"LC_ALL=$locale"}],
+ # handle zero/grouping in combination
+ ['lcl-fmt-5', '--format="%\'06f" 1234',{OUT=>"01 234"},
+ {ENV=>"LC_ALL=$locale"}],
+ ['lcl-fmt-6', '--format="%0\'6f" 1234',{OUT=>"01 234"},
+ {ENV=>"LC_ALL=$locale"}],
+ ['lcl-fmt-7', '--format="%0\'\'6f" 1234',{OUT=>"01 234"},
+ {ENV=>"LC_ALL=$locale"}],
);
if ($locale ne 'C')