From 3db4e7f84cf795de8559ea0d96eaa491999ccf24 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Fri, 19 Oct 2018 15:25:41 +0200 Subject: printf: fix printing +-prefixed numbers Thanks to Cristian Ionescu-Idbohrn for noticing. Also fix "%d" ' 42' to skip leading whitespace. function old new delta print_direc 435 454 +19 bb_strtoll 99 103 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 23/0) Total: 23 bytes Signed-off-by: Bernhard Reutner-Fischer --- testsuite/printf.tests | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'testsuite/printf.tests') diff --git a/testsuite/printf.tests b/testsuite/printf.tests index 963ded94b..34a65926e 100755 --- a/testsuite/printf.tests +++ b/testsuite/printf.tests @@ -79,6 +79,39 @@ testing "printf understands %Ld" \ "-5\n""0\n" \ "" "" +testing "printf handles positive numbers for %d" \ + "${bb}printf '%d\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \ + "3\n"\ +"3\n"\ +"3\n"\ +"3\n""0\n" \ + "" "" + +testing "printf handles positive numbers for %i" \ + "${bb}printf '%i\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \ + "3\n"\ +"3\n"\ +"3\n"\ +"3\n""0\n" \ + "" "" + +testing "printf handles positive numbers for %x" \ + "${bb}printf '%x\n' 42 +42 ' 42' ' +42' 2>&1; echo \$?" \ + "2a\n"\ +"2a\n"\ +"2a\n"\ +"2a\n""0\n" \ + "" "" + +testing "printf handles positive numbers for %f" \ + "${bb}printf '%0.3f\n' .42 +.42 ' .42' ' +.42' 2>&1; echo \$?" \ + "0.420\n"\ +"0.420\n"\ +"0.420\n"\ +"0.420\n""0\n" \ + "" "" + + # "FIXED" now to act compatibly ## We are "more correct" here than bash/coreutils: they happily print -2 ## as if it is a huge unsigned number -- cgit v1.2.3