diff options
author | Elliott Hughes <enh@google.com> | 2019-08-17 19:53:56 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-08-19 11:23:41 -0500 |
commit | 81518f643d4d53b035b2cefbce25f06bd3cb5079 (patch) | |
tree | 9420219c83f68c0345b770a31d7958dc1eb6295a /tests/printf.test | |
parent | aa88ba047fa4210c03c3ad1168f84261167c3644 (diff) | |
download | toybox-81518f643d4d53b035b2cefbce25f06bd3cb5079.tar.gz |
echo/printf: expand test cases, fix \x corner cases.
The behavior with "\xAV" (where the second hex digit is invalid) is
different from the behavior with "\xVA", and echo and printf differ from
each other.
Diffstat (limited to 'tests/printf.test')
-rwxr-xr-x | tests/printf.test | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/printf.test b/tests/printf.test index eb0e0bec..a341615e 100755 --- a/tests/printf.test +++ b/tests/printf.test @@ -68,3 +68,19 @@ testing "printf posix inconsistency" "$PRINTF '\\0066-%b' '\\0066'" "\x066-6" \ testing "printf \x" "$PRINTF 'A\x1b\x2B\x3Q\xa' | od -An -tx1" \ " 41 1b 2b 03 51 0a\n" "" "" + +testing "printf \c" "$PRINTF 'one\ctwo'" "one" "" "" + +# An extra leading 0 is fine for %b, but not as a direct escape, for some +# reason... +testing "printf octal %b" "$PRINTF '\0007%b' '\0007' | xxd -p" "003707\n" "" "" + +# Unlike echo, printf errors out on bad hex. +testcmd "invalid hex 1" "'one\xvdtwo' 2>/dev/null || echo err" "oneerr\n" "" "" +testcmd "invalid hex 2" "'one\xavtwo'" "one\nvtwo" "" "" +# But bad octal is shown as text. +testcmd "invalid oct" "'one\079two'" "one\a9two" "" "" + +# extension for ESC +testcmd "%b \e" "'%b' '\\e' | xxd -p" "1b\n" "" "" +testcmd "\e" "'\\e' | xxd -p" "1b\n" "" "" |