Add to_lower function
This commit is contained in:
parent
4caadf77be
commit
91812c9742
2 changed files with 44 additions and 0 deletions
25
test/test_to_lower.py
Normal file
25
test/test_to_lower.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
"""Test to_lower function"""
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"case",
|
||||
[
|
||||
{"input": "abcdefghijklmnopqrstuvwxyz", "expected": "abcdefghijklmnopqrstuvwxyz"},
|
||||
{"input": "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "expected": "abcdefghijklmnopqrstuvwxyz"},
|
||||
{"input": "MixedCase", "expected": "mixedcase"},
|
||||
{"input": "MixedCase", "expected": "mixedcase"},
|
||||
{"input": "ABC abc Ɛ🤷 1234567890!@#$%^&*()-=+_ XYZ", "expected": "abc abc Ɛ🤷 1234567890!@#$%^&*()-=+_ xyz"},
|
||||
],
|
||||
)
|
||||
def test_get_mode(runner, yadm, case):
|
||||
"""Test function to_lower"""
|
||||
script = f"""
|
||||
YADM_TEST=1 source {yadm}
|
||||
result=$(to_lower "{case["input"]}")
|
||||
echo "RESULT:$result"
|
||||
"""
|
||||
run = runner(command=["bash"], inp=script)
|
||||
assert run.success
|
||||
assert run.err == ""
|
||||
assert f"RESULT:{case['expected']}\n" in run.out
|
19
yadm
19
yadm
|
@ -2131,6 +2131,25 @@ function mk_tmp_dir {
|
|||
echo "$tempdir"
|
||||
}
|
||||
|
||||
function to_lower {
|
||||
local str="$1"
|
||||
local length="${#str}"
|
||||
|
||||
for ((i = 0; i < length; i++)); do
|
||||
local char="${str:i:1}"
|
||||
local ascii_val
|
||||
ascii_val=$(printf "%d" "'$char'")
|
||||
|
||||
if ((ascii_val>=65 && ascii_val<=90)); then
|
||||
ascii_val=$((ascii_val + 32))
|
||||
# shellcheck disable=SC2059
|
||||
printf "\\$(printf '%03o' "$ascii_val")"
|
||||
else
|
||||
printf '%s' "$char"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# ****** Prerequisites Functions ******
|
||||
|
||||
function require_archive() {
|
||||
|
|
Loading…
Reference in a new issue