logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 0836695d8442e2dd961d047ce560e7d41b606204
parent 552e198f5dc2f57fd39a36f45bf247e9e5300db2
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 26 Sep 2025 18:45:02 +0200

test-cmd/tr.sh: new

Diffstat:

Atest-cmd/outputs/tr/all_ascii_cntrl2++
Atest-cmd/tr.sh39+++++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/test-cmd/outputs/tr/all_ascii_cntrl b/test-cmd/outputs/tr/all_ascii_cntrl @@ -0,0 +1 @@ +???????????????????????????????? !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~? +\ No newline at end of file diff --git a/test-cmd/tr.sh b/test-cmd/tr.sh @@ -0,0 +1,39 @@ +#!/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