logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

printf.sh (2122B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. plans=37
  5. WD="$(dirname "$0")/../"
  6. target="${WD}/cmd/printf"
  7. . "${WD}/test-cmd/tap.sh"
  8. t esc '\b\t\n' '
  9. '
  10. t octal '\041' '!'
  11. t hex '\x7B\x7d' '{}'
  12. t_args repeat 'foo,bar,baz,' '%s,' foo bar baz
  13. var_c_upper='\c@\cA\cB\cC\cD\cE\cF\cG\cH\cI\cJ\cK\cL\cM\cN\cO\cP\cQ\cR\cS\cT\cU\cV\cW\cX\cY\cZ\c[\c\\c]\c^\c_ !"#$\%&'"'"'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\c?'
  14. t_file esc_c_upper "${WD}/test-cmd/inputs/all_ascii" "${var_c_upper}"
  15. var_c_lower='\c@\ca\cb\cc\cd\ce\cf\cg\ch\ci\cj\ck\cl\cm\cn\co\cp\cq\cr\cs\ct\cu\cv\cw\cx\cy\cz\c[\c\\c]\c^\c_ !"#$\%&'"'"'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\c?'
  16. t_file esc_c_lower "${WD}/test-cmd/inputs/all_ascii" "${var_c_lower}"
  17. t_args clear_vs_caret_esc 'foo :bar' 'foo \cH:%brat\n' 'bar\cHbaz'
  18. t_args fmt_b '
  19. !{}' '%b' '\b\t\n\041\x7B\x7d'
  20. t_args fmt_b_rightpad '!{} .' '%-6b%c' '\041\x7B\x7d' .
  21. t_args fmt_b_leftpad ' !{}.' '%6b%c' '\041\x7B\x7d' .
  22. t_args fmt_q_print 'foo
  23. baré
  24. ' '%q\n' foo baré
  25. t_args fmt_q_cntrl "back$'\cHdel\c?nl\cJ'" '%q' 'backdelnl
  26. '
  27. t_args fmt_q_sq "single$'\\'quote'" %q "single'quote"
  28. t_args fmt_q_dq "double$'"'"'"quote'" %q 'double"quote'
  29. t_args fmt_c 'foo' %c f oo oooo
  30. t_args fmt_d 10, %d, 10
  31. t_args fmt_Ld 10, %Ld, 10
  32. t_args fmt_i 10, %i, 10
  33. t_args fmt_o 12, %o, 10
  34. t_args fmt_u 10, %u, 10
  35. t_args fmt_x a, %x, 10
  36. t_args fmt_X A, %X, 10
  37. t_args fmt_e '1.000000e+01,' %e, 10
  38. t_args fmt_E '1.000000E+01,' %E, 10
  39. t_args fmt_f '10.000000,' %f, 10
  40. t_args fmt_Lf '10.000000,' %Lf, 10
  41. t_args fmt_F '10.000000,' %F, 10
  42. t_args fmt_g '10,' %g, 10
  43. t_args fmt_G '10,' %G, 10
  44. t_args fmt_a '0x1.4p+3,' %a, 10
  45. t_args fmt_A '0X1.4P+3,' %A, 10
  46. t_args nofmtarg '[
  47. ]' '[%s\n]'
  48. t_args nofmtconv 'foobar
  49. ' 'foobar\n' 1 2 3
  50. t_args nofmtconv_caret 'foo bar' 'foo \cHbar'
  51. t_args precision_s 'abcde' '%.5s' abcdefghijklmnopqrstuvwxyz
  52. t_args nofmt_doubledash '--' '--'
  53. t_args doubledash_fmt '10.000000' '--' '%f' 10