1 # $FreeBSD: head/bin/sh/tests/expansion/trim1.0 206143 2010-04-03 20:14:10Z jilles $
3 e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
16 if [ "x$result" = "x$expected" ]; then
20 echo "For $code, expected $expected actual $result"
24 testcase 'set -- ${t%t}' '1|texttex'
25 testcase 'set -- "${t%t}"' '1|texttex'
26 testcase 'set -- ${t%e*}' '1|textt'
27 testcase 'set -- "${t%e*}"' '1|textt'
28 testcase 'set -- ${t%%e*}' '1|t'
29 testcase 'set -- "${t%%e*}"' '1|t'
30 testcase 'set -- ${t%%*}' '0|'
31 testcase 'set -- "${t%%*}"' '1|'
32 testcase 'set -- ${t#t}' '1|exttext'
33 testcase 'set -- "${t#t}"' '1|exttext'
34 testcase 'set -- ${t#*x}' '1|ttext'
35 testcase 'set -- "${t#*x}"' '1|ttext'
36 testcase 'set -- ${t##*x}' '1|t'
37 testcase 'set -- "${t##*x}"' '1|t'
38 testcase 'set -- ${t##*}' '0|'
39 testcase 'set -- "${t##*}"' '1|'
40 testcase 'set -- ${t%e$a}' '1|textt'
43 testcase 'set -- ${s%[?]*}' '1|ast*que'
44 testcase 'set -- "${s%[?]*}"' '1|ast*que'
45 testcase 'set -- ${s%[*]*}' '1|ast'
46 testcase 'set -- "${s%[*]*}"' '1|ast'
49 testcase 'set -- $b' '1|{{(#)}}'
50 testcase 'set -- ${b%\}}' '1|{{(#)}'
51 testcase 'set -- ${b#{}' '1|{(#)}}'
52 testcase 'set -- "${b#{}"' '1|{(#)}}'
53 # Parentheses are special in ksh, check that they can be escaped
54 testcase 'set -- ${b%\)*}' '1|{{(#'
55 testcase 'set -- ${b#{}' '1|{(#)}}'
56 testcase 'set -- $h' '1|##'
57 testcase 'set -- ${h#\#}' '1|#'
58 testcase 'set -- ${h###}' '1|#'
59 testcase 'set -- "${h###}"' '1|#'
60 testcase 'set -- ${h%#}' '1|#'
61 testcase 'set -- "${h%#}"' '1|#'
64 testcase 'set -- ${s%"${s#?}"}' '1|a'
65 testcase 'set -- ${s%"${s#????}"}' '1|ast*'
66 testcase 'set -- ${s%"${s#????????}"}' '1|ast*que?'
67 testcase 'set -- ${s#"${s%?}"}' '1|n'
68 testcase 'set -- ${s#"${s%????}"}' '1|?non'
69 testcase 'set -- ${s#"${s%????????}"}' '1|*que?non'
71 testcase 'set -- "${s%"${s#?}"}"' '1|a'
72 testcase 'set -- "${s%"${s#????}"}"' '1|ast*'
73 testcase 'set -- "${s%"${s#????????}"}"' '1|ast*que?'
74 testcase 'set -- "${s#"${s%?}"}"' '1|n'
75 testcase 'set -- "${s#"${s%????}"}"' '1|?non'
76 testcase 'set -- "${s#"${s%????????}"}"' '1|*que?non'
77 testcase 'set -- ${p#${p}}' '1|/etc/'
78 testcase 'set -- "${p#${p}}"' '1|/et[c]/'
79 testcase 'set -- ${p#*[[]}' '1|c]/'
80 testcase 'set -- "${p#*[[]}"' '1|c]/'
81 testcase 'set -- ${p#*\[}' '1|c]/'
82 testcase 'set -- ${p#*"["}' '1|c]/'
83 testcase 'set -- "${p#*"["}"' '1|c]/'