trim3.0 revision 207127
1207127Sjilles# $FreeBSD: head/tools/regression/bin/sh/expansion/trim3.0 207127 2010-04-23 17:26:49Z jilles $ 2207127Sjilles 3207127Sjillese= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' 4207127Sjillesh='##' c='\\\\' 5207127Sjillesfailures='' 6207127Sjillesok='' 7207127Sjilles 8207127Sjillestestcase() { 9207127Sjilles code="$1" 10207127Sjilles expected="$2" 11207127Sjilles oIFS="$IFS" 12207127Sjilles eval "$code" 13207127Sjilles IFS='|' 14207127Sjilles result="$#|$*" 15207127Sjilles IFS="$oIFS" 16207127Sjilles if [ "x$result" = "x$expected" ]; then 17207127Sjilles ok=x$ok 18207127Sjilles else 19207127Sjilles failures=x$failures 20207127Sjilles echo "For $code, expected $expected actual $result" 21207127Sjilles fi 22207127Sjilles} 23207127Sjilles 24207127Sjilles# This doesn't make much sense, but it fails in dash so I'm adding it here: 25207127Sjillestestcase 'set -- "${w%${w#???}}"' '1|a b' 26207127Sjilles 27207127Sjillestestcase 'set -- ${p#/et[}' '1|c]/' 28207127Sjillestestcase 'set -- "${p#/et[}"' '1|c]/' 29207127Sjillestestcase 'set -- "${p%${p#????}}"' '1|/et[' 30207127Sjilles 31207127Sjillestestcase 'set -- ${b%'\'}\''}' '1|{{(#)}' 32207127Sjilles 33207127Sjillestestcase 'set -- ${c#\\}' '1|\\\' 34207127Sjillestestcase 'set -- ${c#\\\\}' '1|\\' 35207127Sjillestestcase 'set -- ${c#\\\\\\}' '1|\' 36207127Sjillestestcase 'set -- ${c#\\\\\\\\}' '0|' 37207127Sjillestestcase 'set -- "${c#\\}"' '1|\\\' 38207127Sjillestestcase 'set -- "${c#\\\\}"' '1|\\' 39207127Sjillestestcase 'set -- "${c#\\\\\\}"' '1|\' 40207127Sjillestestcase 'set -- "${c#\\\\\\\\}"' '1|' 41207127Sjillestestcase 'set -- "${c#"$c"}"' '1|' 42207127Sjillestestcase 'set -- ${c#"$c"}' '0|' 43207127Sjillestestcase 'set -- "${c%"$c"}"' '1|' 44207127Sjillestestcase 'set -- ${c%"$c"}' '0|' 45207127Sjilles 46207127Sjillestest "x$failures" = x 47