trim8.0 revision 221646
1221646Sjilles# $FreeBSD: head/tools/regression/bin/sh/expansion/trim8.0 221646 2011-05-08 11:32:20Z jilles $ 2221646Sjilles 3221646Sjillesunset LC_ALL 4221646SjillesLC_CTYPE=en_US.UTF-8 5221646Sjillesexport LC_CTYPE 6221646Sjilles 7221646Sjillesc1=e 8221646Sjilles# a umlaut 9221646Sjillesc2=$(printf '\303\244') 10221646Sjilles# euro sign 11221646Sjillesc3=$(printf '\342\202\254') 12221646Sjilles# some sort of 't' outside BMP 13221646Sjillesc4=$(printf '\360\235\225\245') 14221646Sjilles 15221646Sjilless=$c1$c2$c3$c4 16221646Sjilles 17221646Sjillestestcase() { 18221646Sjilles code="$1" 19221646Sjilles expected="$2" 20221646Sjilles oIFS="$IFS" 21221646Sjilles eval "$code" 22221646Sjilles IFS='|' 23221646Sjilles result="$#|$*" 24221646Sjilles IFS="$oIFS" 25221646Sjilles if [ "x$result" = "x$expected" ]; then 26221646Sjilles ok=x$ok 27221646Sjilles else 28221646Sjilles failures=x$failures 29221646Sjilles echo "For $code, expected $expected actual $result" 30221646Sjilles fi 31221646Sjilles} 32221646Sjilles 33221646Sjillestestcase 'set -- "$s"' "1|$s" 34221646Sjillestestcase 'set -- "${s#$c2}"' "1|$s" 35221646Sjillestestcase 'set -- "${s#*}"' "1|$s" 36221646Sjillestestcase 'set -- "${s#$c1}"' "1|$c2$c3$c4" 37221646Sjillestestcase 'set -- "${s#$c1$c2}"' "1|$c3$c4" 38221646Sjillestestcase 'set -- "${s#$c1$c2$c3}"' "1|$c4" 39221646Sjillestestcase 'set -- "${s#$c1$c2$c3$c4}"' "1|" 40221646Sjillestestcase 'set -- "${s#?}"' "1|$c2$c3$c4" 41221646Sjillestestcase 'set -- "${s#??}"' "1|$c3$c4" 42221646Sjillestestcase 'set -- "${s#???}"' "1|$c4" 43221646Sjillestestcase 'set -- "${s#????}"' "1|" 44221646Sjillestestcase 'set -- "${s#*$c3}"' "1|$c4" 45221646Sjillestestcase 'set -- "${s%$c4}"' "1|$c1$c2$c3" 46221646Sjillestestcase 'set -- "${s%$c3$c4}"' "1|$c1$c2" 47221646Sjillestestcase 'set -- "${s%$c2$c3$c4}"' "1|$c1" 48221646Sjillestestcase 'set -- "${s%$c1$c2$c3$c4}"' "1|" 49221646Sjillestestcase 'set -- "${s%?}"' "1|$c1$c2$c3" 50221646Sjillestestcase 'set -- "${s%??}"' "1|$c1$c2" 51221646Sjillestestcase 'set -- "${s%???}"' "1|$c1" 52221646Sjillestestcase 'set -- "${s%????}"' "1|" 53221646Sjillestestcase 'set -- "${s%$c2*}"' "1|$c1" 54221646Sjillestestcase 'set -- "${s##$c2}"' "1|$s" 55221646Sjillestestcase 'set -- "${s##*}"' "1|" 56221646Sjillestestcase 'set -- "${s##$c1}"' "1|$c2$c3$c4" 57221646Sjillestestcase 'set -- "${s##$c1$c2}"' "1|$c3$c4" 58221646Sjillestestcase 'set -- "${s##$c1$c2$c3}"' "1|$c4" 59221646Sjillestestcase 'set -- "${s##$c1$c2$c3$c4}"' "1|" 60221646Sjillestestcase 'set -- "${s##?}"' "1|$c2$c3$c4" 61221646Sjillestestcase 'set -- "${s##??}"' "1|$c3$c4" 62221646Sjillestestcase 'set -- "${s##???}"' "1|$c4" 63221646Sjillestestcase 'set -- "${s##????}"' "1|" 64221646Sjillestestcase 'set -- "${s##*$c3}"' "1|$c4" 65221646Sjillestestcase 'set -- "${s%%$c4}"' "1|$c1$c2$c3" 66221646Sjillestestcase 'set -- "${s%%$c3$c4}"' "1|$c1$c2" 67221646Sjillestestcase 'set -- "${s%%$c2$c3$c4}"' "1|$c1" 68221646Sjillestestcase 'set -- "${s%%$c1$c2$c3$c4}"' "1|" 69221646Sjillestestcase 'set -- "${s%%?}"' "1|$c1$c2$c3" 70221646Sjillestestcase 'set -- "${s%%??}"' "1|$c1$c2" 71221646Sjillestestcase 'set -- "${s%%???}"' "1|$c1" 72221646Sjillestestcase 'set -- "${s%%????}"' "1|" 73221646Sjillestestcase 'set -- "${s%%$c2*}"' "1|$c1" 74221646Sjilles 75221646Sjillestest "x$failures" = x 76