]>
Commit | Line | Data |
---|---|---|
deb63bfb | 1 | # $FreeBSD: head/bin/sh/tests/expansion/trim1.0 206143 2010-04-03 20:14:10Z jilles $ |
71aad674 A |
2 | |
3 | e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' | |
4 | h='##' | |
5 | failures='' | |
6 | ok='' | |
7 | ||
8 | testcase() { | |
9 | code="$1" | |
10 | expected="$2" | |
11 | oIFS="$IFS" | |
12 | eval "$code" | |
13 | IFS='|' | |
14 | result="$#|$*" | |
15 | IFS="$oIFS" | |
16 | if [ "x$result" = "x$expected" ]; then | |
17 | ok=x$ok | |
18 | else | |
19 | failures=x$failures | |
20 | echo "For $code, expected $expected actual $result" | |
21 | fi | |
22 | } | |
23 | ||
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' | |
41 | ||
42 | set -f | |
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' | |
47 | set +f | |
48 | ||
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|#' | |
62 | ||
63 | set -f | |
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' | |
70 | set +f | |
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]/' | |
84 | ||
85 | test "x$failures" = x |