1# $FreeBSD$ 2 3e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' 4h='##' 5failures='' 6ok='' 7 8testcase() { 9 code="$1" 10 expected="$2" 11 oIFS="$IFS" 12 eval "$code" 13 IFS='|' 14 result="$#|$*" 15 IFS="$oIFS" 16 if [ "x$result" = "x$expected" ]; then 17 ok=x$ok 18 else 19 failures=x$failures 20 echo "For $code, expected $expected actual $result" 21 fi 22} 23 24set -f 25testcase 'set -- $s' '1|ast*que?non' 26testcase 'set -- ${s%\?*}' '1|ast*que' 27testcase 'set -- "${s%\?*}"' '1|ast*que' 28testcase 'set -- ${s%\**}' '1|ast' 29testcase 'set -- "${s%\**}"' '1|ast' 30testcase 'set -- ${s%"$q"*}' '1|ast*que' 31testcase 'set -- "${s%"$q"*}"' '1|ast*que' 32testcase 'set -- ${s%"$a"*}' '1|ast' 33testcase 'set -- "${s%"$a"*}"' '1|ast' 34testcase 'set -- ${s%"$q"$a}' '1|ast*que' 35testcase 'set -- "${s%"$q"$a}"' '1|ast*que' 36testcase 'set -- ${s%"$a"$a}' '1|ast' 37testcase 'set -- "${s%"$a"$a}"' '1|ast' 38set +f 39 40testcase 'set -- "${b%\}}"' '1|{{(#)}' 41# Parentheses are special in ksh, check that they can be escaped 42testcase 'set -- "${b%\)*}"' '1|{{(#' 43testcase 'set -- "${h#\#}"' '1|#' 44 45testcase 'set -- ${p%"${p#?}"}' '1|/' 46testcase 'set -- ${p%"${p#??????}"}' '1|/etc' 47testcase 'set -- ${p%"${p#???????}"}' '1|/etc/' 48testcase 'set -- "${p%"${p#?}"}"' '1|/' 49testcase 'set -- "${p%"${p#??????}"}"' '1|/et[c]' 50testcase 'set -- "${p%"${p#???????}"}"' '1|/et[c]/' 51testcase 'set -- ${p#"${p}"}' '0|' 52testcase 'set -- "${p#"${p}"}"' '1|' 53testcase 'set -- "${p#*\[}"' '1|c]/' 54 55test "x$failures" = x 56