########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
function err_exit
{
print -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
integer Errors=0
cd $tmp || exit
# test shift-jis \x81\x40 ... \x81\x7E encodings
# (shift char followed by 7 bit ascii)
do c=${chr#16#}
eval n=\$\'$s\'
[[ $b == "$n" ]] || err_exit "LC_ALL=$locale printf difference for \"$s\" -- expected '$n', got '$b'"
u=$(print -- $b)
q=$(print -- "$b")
[[ $u == "$q" ]] || err_exit "LC_ALL=$locale quoted print difference for \"$s\" -- $b => '$u' vs \"$b\" => '$q'"
done
done
done
# this locale is supported by ast on all platforms
# EU for { decimal_point="," thousands_sep="." }
export LC_ALL=C
if [[ "$c" != "$u" ]]
x=$'+2+ typeset item.text\
+3+ item.text=\303\274\
+4+ print -- \303\274\
\303\274\
+5+ eval $\'arr[0]=(\\n\\ttext=\\303\\274\\n)\'
+2+ arr[0].text=ü\
+6+ print -- \303\274\
ü\
+7+ eval txt=$\'(\\n\\ttext=\\303\\274\\n)\'
+2+ txt.text=\303\274\
+8+ print -- \'(\' text=$\'\\303\\274\' \')\'\
( text=\303\274 )'
item=(typeset text)
item.text=$'\303\274'
print -- \"\${item.text}\"
eval \"arr[0]=\$item\"
print -- \"\${arr[0].text}\"
eval \"txt=\${arr[0]}\"
print -- \$txt
" 2>&1)
x=$'00fc\n20ac'
fi
if (( $($SHELL -c $'export LC_ALL='$locale$'; print -r "\342\202\254\342\202\254\342\202\254\342\202\254w\342\202\254\342\202\254\342\202\254\342\202\254" | wc -m' 2>/dev/null) == 10 ))
then LC_ALL=$locale $SHELL -c b1=$'"\342\202\254\342\202\254\342\202\254\342\202\254w\342\202\254\342\202\254\342\202\254\342\202\254"; [[ ${b1:4:1} == w ]]' || err_exit 'multibyte ${var:offset:len} not working correctly'
fi
#$SHELL -c 'export LANG='$locale'; printf "\u[20ac]\u[20ac]" > $tmp/two_euro_chars.txt'
exp="6 2 6"
set -- $($SHELL -c "
unset LC_CTYPE
export LANG=$locale
export LC_ALL=C
command wc -C < $tmp/two_euro_chars.txt
unset LC_ALL
command wc -C < $tmp/two_euro_chars.txt
export LC_ALL=C
command wc -C < $tmp/two_euro_chars.txt
")
got=$*
set -- $($SHELL -c "
then unset LC_CTYPE
export LANG=$locale
export LC_ALL=C
wc -C < $tmp/two_euro_chars.txt
unset LC_ALL
wc -C < $tmp/two_euro_chars.txt
export LC_ALL=C
wc -C < $tmp/two_euro_chars.txt
fi
")
got=$*
# multibyte char straddling buffer boundary
{
unset i
integer i
for ((i = 0; i < 163; i++))
do print "#234567890123456789012345678901234567890123456789"
done
for ((i = 0; i < 2; i++))
do print $': "\xe5\xae\x9f\xe8\xa1\x8c\xe6\xa9\x9f\xe8\x83\xbd\xe3\x82\x92\xe8\xa1\xa8\xe7\xa4\xba\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82" :'
done
} > ko.dat
LC_ALL=$locale $SHELL < ko.dat 2> /dev/null || err_exit "script with multibyte char straddling buffer boundary fails"
# exp LC_ALL LC_NUMERIC LANG
set -- \
unset a b c
integer a b c
while (( $# >= 4 ))
do exp=$1
unset H V
typeset -A H
typeset -a V
[[ $2 ]] && V[0]="export LC_ALL=$2;"
[[ $3 ]] && V[1]="export LC_NUMERIC=$3;"
[[ $4 ]] && V[2]="export LANG=$4;"
for ((a = 0; a < 3; a++))
do for ((b = 0; b < 3; b++))
do if (( b != a ))
then for ((c = 0; c < 3; c++))
do if (( c != a && c != b ))
then T=${V[$a]}${V[$b]}${V[$c]}
if [[ ! ${H[$T]} ]]
then H[$T]=1
fi
fi
done
fi
done
done
shift 4
done
# setocale(LC_ALL,"") after setlocale() initialization
print "export LC_ALL=$locale
join -j1 1 -j2 2 -o 1.1 -t \$(cat delim) input1 input2 > out" > script
$SHELL -c 'unset LANG ${!LC_*}; $SHELL ./script' ||
err_exit "join test script failed -- exit code $?"
exp="f1"
# multibyte identifiers
[[ $got == "$exp" ]] || err_exit "multibyte variable definition/expansion failed -- expected '$exp', got '$got'"
[[ $got == "$exp" ]] || err_exit "multibyte ksh function definition/execution failed -- expected '$exp', got '$got'"
[[ $got == "$exp" ]] || err_exit "multibyte posix function definition/execution failed -- expected '$exp', got '$got'"
# this locale is supported by ast on all platforms
# mainly used to debug multibyte and message translation code
# however wctype is not supported but that's ok for these tests
x=a<1z>b<2yx>c
print ${#x}
]]
then err_exit '${#x} not working with multibyte locales'
fi
exp=2
done
exp=121
do for cmd in "($lc=$locale;cd $dir)" "$lc=$locale;cd $dir;unset $lc" "function tst { typeset $lc=$locale;cd $dir; }; tst"
integer id=0
unset msg
typeset -A msg
got=
while read -r line
fi
done < out
done
done
exp=123
[[ $got == $exp ]] || err_exit "multibyte debug locale \$a<2A@>z failed -- expected '$exp', got '$got'"
unset LC_ALL LC_MESSAGES
function message
{
print -r $"An error occurred."
}
exp=$'(libshell,3,46)\nAn error occurred.\n(libshell,3,46)'
alt=$'(debug,message,libshell,An error occurred.)\nAn error occurred.\n(debug,message,libshell,An error occurred.)'
}
typeset got=$"This is a string\n"
unset LANG
LC_ALL=C
x=$"hello"
# tests for multibyte characteer at buffer boundary
{
print 'cat << \\EOF'
for ((i=1; i < 164; i++))
do print 123456789+123456789+123456789+123456789+123456789
done
print $'next character is multibyte<2b|>c<3d|\>foo'
for ((i=1; i < 10; i++))
do print 123456789+123456789+123456789+123456789+123456789
done
print EOF
[[ ${#x} == 8641 ]] || err_exit 'here doc contains wrong number of chars with multibyte locale'
[[ $x == *$'next character is multibyte<2b|>c<3d|\>foo'* ]] || err_exit "here_doc doesn't contain line with multibyte chars"
for i in 9 b c d 20 1680 2000 2001 2002 2003 2004 2005 2006 2008 2009 200a 2028 2029 3000 # 1803 2007 202f 205f
do if ! eval "[[ \$'\\u[$i]' == [[:space:]] ]]"
then x+=,$i
fi
done
if [[ $x ]]
then if [[ $x == ,*,* ]]
fi
fi
unset x
[[ $(print -r -- "$x") == $'hello\u[20ac]\xee world' ]] || err_exit '%q with unicode and non-unicode not working'
if [[ $(whence od) ]]
then got='68 65 6c 6c 6f e2 82 ac ee 20 77 6f 72 6c 64 0a'
fi
fi