1# $FreeBSD$ 2 3unset LC_ALL 4LC_CTYPE=en_US.UTF-8 5export LC_CTYPE 6 7c1=e 8# a umlaut 9c2=$(printf '\303\244') 10# euro sign 11c3=$(printf '\342\202\254') 12# some sort of 't' outside BMP 13c4=$(printf '\360\235\225\245') 14 15s=$c1$c2$c3$c4 16 17testcase() { 18 code="$1" 19 expected="$2" 20 oIFS="$IFS" 21 eval "$code" 22 IFS='|' 23 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