trim8.0 revision 221646
1284345Ssjg# $FreeBSD: head/tools/regression/bin/sh/expansion/trim8.0 221646 2011-05-08 11:32:20Z jilles $ 2284345Ssjg 3284345Ssjgunset LC_ALL 4284345SsjgLC_CTYPE=en_US.UTF-8 5284345Ssjgexport LC_CTYPE 6284345Ssjg 7284345Ssjgc1=e 8284345Ssjg# a umlaut 9284345Ssjgc2=$(printf '\303\244') 10284345Ssjg# euro sign 11284345Ssjgc3=$(printf '\342\202\254') 12284345Ssjg# some sort of 't' outside BMP 13291558Sbdreweryc4=$(printf '\360\235\225\245') 14284345Ssjg 15284345Ssjgs=$c1$c2$c3$c4 16284345Ssjg 17284345Ssjgtestcase() { 18284345Ssjg code="$1" 19284345Ssjg expected="$2" 20284345Ssjg oIFS="$IFS" 21284345Ssjg eval "$code" 22284345Ssjg IFS='|' 23284345Ssjg result="$#|$*" 24 IFS="$oIFS" 25 if [ "x$result" = "x$expected" ]; then 26 ok=x$ok 27 else 28 failures=x$failures 29 echo "For $code, expected $expected actual $result" 30 fi 31} 32 33testcase 'set -- "$s"' "1|$s" 34testcase 'set -- "${s#$c2}"' "1|$s" 35testcase 'set -- "${s#*}"' "1|$s" 36testcase 'set -- "${s#$c1}"' "1|$c2$c3$c4" 37testcase 'set -- "${s#$c1$c2}"' "1|$c3$c4" 38testcase 'set -- "${s#$c1$c2$c3}"' "1|$c4" 39testcase 'set -- "${s#$c1$c2$c3$c4}"' "1|" 40testcase 'set -- "${s#?}"' "1|$c2$c3$c4" 41testcase 'set -- "${s#??}"' "1|$c3$c4" 42testcase 'set -- "${s#???}"' "1|$c4" 43testcase 'set -- "${s#????}"' "1|" 44testcase 'set -- "${s#*$c3}"' "1|$c4" 45testcase 'set -- "${s%$c4}"' "1|$c1$c2$c3" 46testcase 'set -- "${s%$c3$c4}"' "1|$c1$c2" 47testcase 'set -- "${s%$c2$c3$c4}"' "1|$c1" 48testcase 'set -- "${s%$c1$c2$c3$c4}"' "1|" 49testcase 'set -- "${s%?}"' "1|$c1$c2$c3" 50testcase 'set -- "${s%??}"' "1|$c1$c2" 51testcase 'set -- "${s%???}"' "1|$c1" 52testcase 'set -- "${s%????}"' "1|" 53testcase 'set -- "${s%$c2*}"' "1|$c1" 54testcase 'set -- "${s##$c2}"' "1|$s" 55testcase 'set -- "${s##*}"' "1|" 56testcase 'set -- "${s##$c1}"' "1|$c2$c3$c4" 57testcase 'set -- "${s##$c1$c2}"' "1|$c3$c4" 58testcase 'set -- "${s##$c1$c2$c3}"' "1|$c4" 59testcase 'set -- "${s##$c1$c2$c3$c4}"' "1|" 60testcase 'set -- "${s##?}"' "1|$c2$c3$c4" 61testcase 'set -- "${s##??}"' "1|$c3$c4" 62testcase 'set -- "${s##???}"' "1|$c4" 63testcase 'set -- "${s##????}"' "1|" 64testcase 'set -- "${s##*$c3}"' "1|$c4" 65testcase 'set -- "${s%%$c4}"' "1|$c1$c2$c3" 66testcase 'set -- "${s%%$c3$c4}"' "1|$c1$c2" 67testcase 'set -- "${s%%$c2$c3$c4}"' "1|$c1" 68testcase 'set -- "${s%%$c1$c2$c3$c4}"' "1|" 69testcase 'set -- "${s%%?}"' "1|$c1$c2$c3" 70testcase 'set -- "${s%%??}"' "1|$c1$c2" 71testcase 'set -- "${s%%???}"' "1|$c1" 72testcase 'set -- "${s%%????}"' "1|" 73testcase 'set -- "${s%%$c2*}"' "1|$c1" 74 75test "x$failures" = x 76