trim2.0 revision 206147
1206147Sjilles# $FreeBSD: head/tools/regression/bin/sh/expansion/trim2.0 206147 2010-04-03 21:07:50Z jilles $ 2206147Sjilles 3206147Sjillese= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' 4206147Sjillesh='##' 5206147Sjillesfailures='' 6206147Sjillesok='' 7206147Sjilles 8206147Sjillestestcase() { 9206147Sjilles code="$1" 10206147Sjilles expected="$2" 11206147Sjilles oIFS="$IFS" 12206147Sjilles eval "$code" 13206147Sjilles IFS='|' 14206147Sjilles result="$#|$*" 15206147Sjilles IFS="$oIFS" 16206147Sjilles if [ "x$result" = "x$expected" ]; then 17206147Sjilles ok=x$ok 18206147Sjilles else 19206147Sjilles failures=x$failures 20206147Sjilles echo "For $code, expected $expected actual $result" 21206147Sjilles fi 22206147Sjilles} 23206147Sjilles 24206147Sjillesset -f 25206147Sjillestestcase 'set -- $s' '1|ast*que?non' 26206147Sjillestestcase 'set -- ${s%\?*}' '1|ast*que' 27206147Sjillestestcase 'set -- "${s%\?*}"' '1|ast*que' 28206147Sjillestestcase 'set -- ${s%\**}' '1|ast' 29206147Sjillestestcase 'set -- "${s%\**}"' '1|ast' 30206147Sjillestestcase 'set -- ${s%"$q"*}' '1|ast*que' 31206147Sjillestestcase 'set -- "${s%"$q"*}"' '1|ast*que' 32206147Sjillestestcase 'set -- ${s%"$a"*}' '1|ast' 33206147Sjillestestcase 'set -- "${s%"$a"*}"' '1|ast' 34206147Sjillestestcase 'set -- ${s%"$q"$a}' '1|ast*que' 35206147Sjillestestcase 'set -- "${s%"$q"$a}"' '1|ast*que' 36206147Sjillestestcase 'set -- ${s%"$a"$a}' '1|ast' 37206147Sjillestestcase 'set -- "${s%"$a"$a}"' '1|ast' 38206147Sjillesset +f 39206147Sjilles 40206147Sjillestestcase 'set -- "${b%\}}"' '1|{{(#)}' 41206147Sjilles# Parentheses are special in ksh, check that they can be escaped 42206147Sjillestestcase 'set -- "${b%\)*}"' '1|{{(#' 43206147Sjillestestcase 'set -- "${h#\#}"' '1|#' 44206147Sjilles 45206147Sjillestestcase 'set -- ${p%"${p#?}"}' '1|/' 46206147Sjillestestcase 'set -- ${p%"${p#??????}"}' '1|/etc' 47206147Sjillestestcase 'set -- ${p%"${p#???????}"}' '1|/etc/' 48206147Sjillestestcase 'set -- "${p%"${p#?}"}"' '1|/' 49206147Sjillestestcase 'set -- "${p%"${p#??????}"}"' '1|/et[c]' 50206147Sjillestestcase 'set -- "${p%"${p#???????}"}"' '1|/et[c]/' 51206147Sjillestestcase 'set -- ${p#"${p}"}' '0|' 52206147Sjillestestcase 'set -- "${p#"${p}"}"' '1|' 53206147Sjillestestcase 'set -- "${p#*\[}"' '1|c]/' 54206147Sjilles 55206147Sjillestest "x$failures" = x 56