]>
Commit | Line | Data |
---|---|---|
deb63bfb | 1 | # $FreeBSD: head/bin/sh/tests/expansion/trim2.0 206147 2010-04-03 21:07:50Z 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 | set -f | |
25 | testcase 'set -- $s' '1|ast*que?non' | |
26 | testcase 'set -- ${s%\?*}' '1|ast*que' | |
27 | testcase 'set -- "${s%\?*}"' '1|ast*que' | |
28 | testcase 'set -- ${s%\**}' '1|ast' | |
29 | testcase 'set -- "${s%\**}"' '1|ast' | |
30 | testcase 'set -- ${s%"$q"*}' '1|ast*que' | |
31 | testcase 'set -- "${s%"$q"*}"' '1|ast*que' | |
32 | testcase 'set -- ${s%"$a"*}' '1|ast' | |
33 | testcase 'set -- "${s%"$a"*}"' '1|ast' | |
34 | testcase 'set -- ${s%"$q"$a}' '1|ast*que' | |
35 | testcase 'set -- "${s%"$q"$a}"' '1|ast*que' | |
36 | testcase 'set -- ${s%"$a"$a}' '1|ast' | |
37 | testcase 'set -- "${s%"$a"$a}"' '1|ast' | |
38 | set +f | |
39 | ||
40 | testcase 'set -- "${b%\}}"' '1|{{(#)}' | |
41 | # Parentheses are special in ksh, check that they can be escaped | |
42 | testcase 'set -- "${b%\)*}"' '1|{{(#' | |
43 | testcase 'set -- "${h#\#}"' '1|#' | |
44 | ||
45 | testcase 'set -- ${p%"${p#?}"}' '1|/' | |
46 | testcase 'set -- ${p%"${p#??????}"}' '1|/etc' | |
47 | testcase 'set -- ${p%"${p#???????}"}' '1|/etc/' | |
48 | testcase 'set -- "${p%"${p#?}"}"' '1|/' | |
49 | testcase 'set -- "${p%"${p#??????}"}"' '1|/et[c]' | |
50 | testcase 'set -- "${p%"${p#???????}"}"' '1|/et[c]/' | |
51 | testcase 'set -- ${p#"${p}"}' '0|' | |
52 | testcase 'set -- "${p#"${p}"}"' '1|' | |
53 | testcase 'set -- "${p#*\[}"' '1|c]/' | |
54 | ||
55 | test "x$failures" = x |