diff options
Diffstat (limited to 'tests/misc/numfmt.pl')
-rwxr-xr-x[-rw-r--r--] | tests/misc/numfmt.pl | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl index 61917fb8..dfb4b2e0 100644..100755 --- a/tests/misc/numfmt.pl +++ b/tests/misc/numfmt.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # Basic tests for "numfmt". -# Copyright (C) 2012 Free Software Foundation, Inc. +# Copyright (C) 2012-2014 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -260,7 +260,7 @@ my @Tests = # so these are 40 of "M", not 40,000,000. ['mix-1', '--suffix=M --from=si 40M', {OUT=>"40M"}], - # These are fourty-million Ms . + # These are forty-million Ms . ['mix-2', '--suffix=M --from=si 40MM', {OUT=>"40000000M"}], ['mix-3', '--suffix=M --from=auto 40MM', {OUT=>"40000000M"}], @@ -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,13 +889,20 @@ 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') { # Reset locale to 'C' if LOCALE_FR_UTF8 doesn't output as expected # as determined by the separate printf program. - open(LOC_NUM, "LC_ALL=$locale printf \"%'d\" 1234|") + open(LOC_NUM, "env LC_ALL=$locale printf \"%'d\" 1234|") or die "Can't fork command: $!"; my $loc_num = <LOC_NUM>; close(LOC_NUM) || die "Failed to read grouped number from printf"; |