diff --git a/functions.sh.in b/functions.sh.in index 7b00980618df71cf50a36b2d44752d4b729ae2b2..189a67f78b82c1cd246ade0d77c3c68041de74f5 100644 --- a/functions.sh.in +++ b/functions.sh.in @@ -273,6 +273,26 @@ error2() { printf " %s\n" "$1" >&2 } +lowercase() { + str=$1 + for pair in Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz; do + orig=${pair:0:1} + repl=${pair:1:1} + str=${str//"$orig"/"$repl"} + done + echo "$str" +} + +uppercase() { + str=$1 + for pair in aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ; do + orig=${pair:0:1} + repl=${pair:1:1} + str=${str//"$orig"/"$repl"} + done + echo "$str" +} + set_xterm_title() { if [ "$TERM" = xterm ] && [ -n "$USE_COLORS" ]; then printf "\033]0;$1\007" >&2 diff --git a/tests/functions_test b/tests/functions_test index fd6e59436aec1854cc60c25b3bd3c8a4ec9ef183..8665895a569d691f4706ca06aa828e6dcdb4f5e8 100755 --- a/tests/functions_test +++ b/tests/functions_test @@ -7,7 +7,9 @@ init_tests \ funcs_check_missing_apk \ funcs_check_missing_git \ funcs_check_env_set_but_empty \ - funcs_check_defconfig + funcs_check_defconfig \ + funcs_check_lowercase \ + funcs_check_uppercase FUNCS=$(atf_get_srcdir)/../functions.sh @@ -85,3 +87,15 @@ funcs_check_defconfig_body() { -o match:"envcflags" \ sh -e -c " . $FUNCS; echo \"\$CFLAGS\"" } + +funcs_check_lowercase_body() { + atf_check \ + -o match:"aabcdefghijklkmnopqrstuvwxyz" \ + sh -e -c " . $FUNCS; lowercase 'AABCDEFGHIJKLKMNOPQRSTUVWXYZ'" +} + +funcs_check_uppercase_body() { + atf_check \ + -o match:"AABCDEFGHIJKLKMNOPQRSTUVWXYZ" \ + sh -e -c " . $FUNCS; uppercase 'aabcdefghijklkmnopqrstuvwxyz'" +}