|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Test parseargs with single byte |
| 4 | +# |
| 5 | +# shellcheck disable=SC2016 |
| 6 | + |
| 7 | +script_dir="$(cd "$(dirname "$0")" && pwd)" || exit 1 |
| 8 | +script_name="$(basename "$0")" |
| 9 | +script_file="$script_dir/$script_name" |
| 10 | + |
| 11 | +. "$script_dir/_test.shinc" |
| 12 | + |
| 13 | + |
| 14 | +check_single_byte() |
| 15 | +{ |
| 16 | + # print the bytes for the UTF-8 Euro sign and check whether this results in |
| 17 | + # a single character |
| 18 | + x="$(printf '\342\202\254' | sed "s/./X/g")" |
| 19 | + if [ ${#x} = 1 ]; then |
| 20 | + return 1 |
| 21 | + else |
| 22 | + return 0 |
| 23 | + fi |
| 24 | +} |
| 25 | + |
| 26 | +if ! check_single_byte; then |
| 27 | + # set ISO-8859-1 if available |
| 28 | + SB_LOCALE=$(locale -a | grep 'iso88591$' | head -n1) |
| 29 | + if [ -n "$SB_LOCALE" ]; then |
| 30 | + echo "Setting LC_ALL to $SB_LOCALE" |
| 31 | + export LC_ALL="$SB_LOCALE" |
| 32 | + fi |
| 33 | + |
| 34 | + # If still no single byte char set -> exit |
| 35 | + if ! check_single_byte; then |
| 36 | + echo "No ISO-8859-1 character encoding available ... skipping" |
| 37 | + exit 0 |
| 38 | + fi |
| 39 | + luit -encoding 'ISO 8859-1' "$script_file" |
| 40 | + exit $? |
| 41 | +fi |
| 42 | + |
| 43 | +start_test |
| 44 | + |
| 45 | +if [ -n "$IS_WINDOWS" ]; then |
| 46 | + skip_test "on Windows" |
| 47 | +elif [ "$TEST_SHELL" = "yash" ]; then |
| 48 | + skip_test "shell Yash, can't handle this" |
| 49 | +fi |
| 50 | + |
| 51 | +test_pa 'test "${#1}" = 3' -o "n:name=name" -- "$(printf '\342\202\254')" |
| 52 | + |
| 53 | +test_pa 'test "$1" = "Ä"' -o "n:name=name" -- Ä |
| 54 | +test_pa 'test "$name" = "Ä"' -o "n:name=name" -- -n Ä |
| 55 | +test_pa 'test "$name" = "Ä"' -o "n:name=name" -- -nÄ |
| 56 | +test_pa 'test "$name" = "Ä"' -o "n:name=name" -- --name Ä |
| 57 | +test_pa 'test "$name" = "Ä"' -o "n:name=name" -- --name=Ä |
| 58 | + |
| 59 | +test_pa 'test "$1" = "Ä'\''Ö"' -o "n:name=name" -- Ä\'Ö |
| 60 | +test_pa 'test "$name" = "Ä'\''Ö"' -o "n:name=name" -- -n Ä\'Ö |
| 61 | +test_pa 'test "$name" = "Ä'\''Ö"' -o "n:name=name" -- -nÄ\'Ö |
| 62 | +test_pa 'test "$name" = "Ä'\''Ö"' -o "n:name=name" -- --name Ä\'Ö |
| 63 | +test_pa 'test "$name" = "Ä'\''Ö"' -o "n:name=name" -- --name=Ä\'Ö |
| 64 | + |
| 65 | +end_test |
| 66 | + |
| 67 | +# vim:fileencoding=latin1 |
| 68 | + |
0 commit comments