logo

utils-std

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

tr.sh (1516B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. plans=12
  5. WD="$(dirname "$0")/../"
  6. target="${WD}/cmd/tr"
  7. . "$(dirname "$0")/tap.sh"
  8. test_str="abcdefABCDEF123456./-=_"
  9. t_args --input="$test_str" --exit=1 alpha_empty 'tr: error: empty string2
  10. ' '[:alpha:]' ''
  11. t_args --input="$test_str" empty:alpha "$test_str" '' '[:alpha:]'
  12. t_args --input="$test_str" alpha:alpha "$test_str" '[:alpha:]' '[:alpha:]'
  13. t_args --input="$test_str" lower:upper "ABCDEFABCDEF123456./-=_" '[:lower:]' '[:upper:]'
  14. t_args --input="$test_str" upper:lower "abcdefabcdef123456./-=_" '[:upper:]' '[:lower:]'
  15. t_args --input="$test_str" range_nobracket "###defABCDEF123456./-=_" 'a-c' '[#*]'
  16. # Historical SysV behavior
  17. t_args --input="$test_str" range_bracket "###defABCDEF123456./-=_" '[a-c]' '[#*]'
  18. t_args --input="$test_str" 'lower-punct:upper-[_*]' "ABCDEFABCDEF123456_____" '[:lower:][:punct:]' '[:upper:][_*]'
  19. # non-POSIX BSD-ism (Only because of SysV behavior)
  20. t_args --input="$test_str" lower-punct:upper-_ "ABCDEFABCDEF123456_____" '[:lower:][:punct:]' '[:upper:]_'
  21. t_file --infile="${WD}/test-cmd/inputs/all_ascii" all_ascii_cntrl "${WD}/test-cmd/outputs/tr/all_ascii_cntrl" '[:cntrl:]' '[?*]'
  22. test_tr_null() {
  23. printf '%s\0' a b c d 01 2 | "$target" '\0b[:digit:]' '_B[#*]'
  24. }
  25. t_cmd test_tr_null 'a_B_c_d_##_#_' test_tr_null
  26. test_tr_d_null() {
  27. printf '%s\0' a b c d 01 2 | "$target" -d '\0[:digit:]'
  28. }
  29. t_cmd test_tr_d_null 'abcd' test_tr_d_null