tr.sh (1516B)
- #!/bin/sh
- # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- plans=12
- WD="$(dirname "$0")/../"
- target="${WD}/cmd/tr"
- . "$(dirname "$0")/tap.sh"
- test_str="abcdefABCDEF123456./-=_"
- t_args --input="$test_str" --exit=1 alpha_empty 'tr: error: empty string2
- ' '[:alpha:]' ''
- t_args --input="$test_str" empty:alpha "$test_str" '' '[:alpha:]'
- t_args --input="$test_str" alpha:alpha "$test_str" '[:alpha:]' '[:alpha:]'
- t_args --input="$test_str" lower:upper "ABCDEFABCDEF123456./-=_" '[:lower:]' '[:upper:]'
- t_args --input="$test_str" upper:lower "abcdefabcdef123456./-=_" '[:upper:]' '[:lower:]'
- t_args --input="$test_str" range_nobracket "###defABCDEF123456./-=_" 'a-c' '[#*]'
- # Historical SysV behavior
- t_args --input="$test_str" range_bracket "###defABCDEF123456./-=_" '[a-c]' '[#*]'
- t_args --input="$test_str" 'lower-punct:upper-[_*]' "ABCDEFABCDEF123456_____" '[:lower:][:punct:]' '[:upper:][_*]'
- # non-POSIX BSD-ism (Only because of SysV behavior)
- t_args --input="$test_str" lower-punct:upper-_ "ABCDEFABCDEF123456_____" '[:lower:][:punct:]' '[:upper:]_'
- t_file --infile="${WD}/test-cmd/inputs/all_ascii" all_ascii_cntrl "${WD}/test-cmd/outputs/tr/all_ascii_cntrl" '[:cntrl:]' '[?*]'
- test_tr_null() {
- printf '%s\0' a b c d 01 2 | "$target" '\0b[:digit:]' '_B[#*]'
- }
- t_cmd test_tr_null 'a_B_c_d_##_#_' test_tr_null
- test_tr_d_null() {
- printf '%s\0' a b c d 01 2 | "$target" -d '\0[:digit:]'
- }
- t_cmd test_tr_d_null 'abcd' test_tr_d_null