]> git.saurik.com Git - apple/shell_cmds.git/blob - sh/tests/expansion/trim8.0
shell_cmds-216.60.1.tar.gz
[apple/shell_cmds.git] / sh / tests / expansion / trim8.0
1 # $FreeBSD: head/bin/sh/tests/expansion/trim8.0 221646 2011-05-08 11:32:20Z jilles $
2
3 unset LC_ALL
4 LC_CTYPE=en_US.UTF-8
5 export LC_CTYPE
6
7 c1=e
8 # a umlaut
9 c2=$(printf '\303\244')
10 # euro sign
11 c3=$(printf '\342\202\254')
12 # some sort of 't' outside BMP
13 c4=$(printf '\360\235\225\245')
14
15 s=$c1$c2$c3$c4
16
17 testcase() {
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
33 testcase 'set -- "$s"' "1|$s"
34 testcase 'set -- "${s#$c2}"' "1|$s"
35 testcase 'set -- "${s#*}"' "1|$s"
36 testcase 'set -- "${s#$c1}"' "1|$c2$c3$c4"
37 testcase 'set -- "${s#$c1$c2}"' "1|$c3$c4"
38 testcase 'set -- "${s#$c1$c2$c3}"' "1|$c4"
39 testcase 'set -- "${s#$c1$c2$c3$c4}"' "1|"
40 testcase 'set -- "${s#?}"' "1|$c2$c3$c4"
41 testcase 'set -- "${s#??}"' "1|$c3$c4"
42 testcase 'set -- "${s#???}"' "1|$c4"
43 testcase 'set -- "${s#????}"' "1|"
44 testcase 'set -- "${s#*$c3}"' "1|$c4"
45 testcase 'set -- "${s%$c4}"' "1|$c1$c2$c3"
46 testcase 'set -- "${s%$c3$c4}"' "1|$c1$c2"
47 testcase 'set -- "${s%$c2$c3$c4}"' "1|$c1"
48 testcase 'set -- "${s%$c1$c2$c3$c4}"' "1|"
49 testcase 'set -- "${s%?}"' "1|$c1$c2$c3"
50 testcase 'set -- "${s%??}"' "1|$c1$c2"
51 testcase 'set -- "${s%???}"' "1|$c1"
52 testcase 'set -- "${s%????}"' "1|"
53 testcase 'set -- "${s%$c2*}"' "1|$c1"
54 testcase 'set -- "${s##$c2}"' "1|$s"
55 testcase 'set -- "${s##*}"' "1|"
56 testcase 'set -- "${s##$c1}"' "1|$c2$c3$c4"
57 testcase 'set -- "${s##$c1$c2}"' "1|$c3$c4"
58 testcase 'set -- "${s##$c1$c2$c3}"' "1|$c4"
59 testcase 'set -- "${s##$c1$c2$c3$c4}"' "1|"
60 testcase 'set -- "${s##?}"' "1|$c2$c3$c4"
61 testcase 'set -- "${s##??}"' "1|$c3$c4"
62 testcase 'set -- "${s##???}"' "1|$c4"
63 testcase 'set -- "${s##????}"' "1|"
64 testcase 'set -- "${s##*$c3}"' "1|$c4"
65 testcase 'set -- "${s%%$c4}"' "1|$c1$c2$c3"
66 testcase 'set -- "${s%%$c3$c4}"' "1|$c1$c2"
67 testcase 'set -- "${s%%$c2$c3$c4}"' "1|$c1"
68 testcase 'set -- "${s%%$c1$c2$c3$c4}"' "1|"
69 testcase 'set -- "${s%%?}"' "1|$c1$c2$c3"
70 testcase 'set -- "${s%%??}"' "1|$c1$c2"
71 testcase 'set -- "${s%%???}"' "1|$c1"
72 testcase 'set -- "${s%%????}"' "1|"
73 testcase 'set -- "${s%%$c2*}"' "1|$c1"
74
75 test "x$failures" = x