]>
Commit | Line | Data |
---|---|---|
deb63bfb A |
1 | # $FreeBSD: head/bin/sh/tests/expansion/trim9.0 292758 2015-12-26 22:27:48Z jilles $ |
2 | ||
3 | # POSIX does not specify these but they occasionally occur in the wild. | |
4 | # This just serves to keep working what currently works. | |
5 | ||
6 | failures='' | |
7 | ok='' | |
8 | ||
9 | testcase() { | |
10 | code="$1" | |
11 | expected="$2" | |
12 | oIFS="$IFS" | |
13 | eval "$code" | |
14 | IFS='|' | |
15 | result="$#|$*" | |
16 | IFS="$oIFS" | |
17 | if [ "x$result" = "x$expected" ]; then | |
18 | ok=x$ok | |
19 | else | |
20 | failures=x$failures | |
21 | echo "For $code, expected $expected actual $result" | |
22 | fi | |
23 | } | |
24 | ||
25 | testcase 'shift $#; set -- "${*#Q}"' '1|' | |
26 | testcase 'shift $#; set -- "${*##Q}"' '1|' | |
27 | testcase 'shift $#; set -- "${*%Q}"' '1|' | |
28 | testcase 'shift $#; set -- "${*%%Q}"' '1|' | |
29 | testcase 'set -- Q R; set -- "${*#Q}"' '1| R' | |
30 | testcase 'set -- Q R; set -- "${*##Q}"' '1| R' | |
31 | testcase 'set -- Q R; set -- "${*%R}"' '1|Q ' | |
32 | testcase 'set -- Q R; set -- "${*%%R}"' '1|Q ' | |
33 | testcase 'set -- Q R; set -- "${*#S}"' '1|Q R' | |
34 | testcase 'set -- Q R; set -- "${*##S}"' '1|Q R' | |
35 | testcase 'set -- Q R; set -- "${*%S}"' '1|Q R' | |
36 | testcase 'set -- Q R; set -- "${*%%S}"' '1|Q R' | |
37 | testcase 'set -- Q R; set -- ${*#Q}' '1|R' | |
38 | testcase 'set -- Q R; set -- ${*##Q}' '1|R' | |
39 | testcase 'set -- Q R; set -- ${*%R}' '1|Q' | |
40 | testcase 'set -- Q R; set -- ${*%%R}' '1|Q' | |
41 | testcase 'set -- Q R; set -- ${*#S}' '2|Q|R' | |
42 | testcase 'set -- Q R; set -- ${*##S}' '2|Q|R' | |
43 | testcase 'set -- Q R; set -- ${*%S}' '2|Q|R' | |
44 | testcase 'set -- Q R; set -- ${*%%S}' '2|Q|R' | |
45 | testcase 'set -- Q R; set -- ${@#Q}' '1|R' | |
46 | testcase 'set -- Q R; set -- ${@##Q}' '1|R' | |
47 | testcase 'set -- Q R; set -- ${@%R}' '1|Q' | |
48 | testcase 'set -- Q R; set -- ${@%%R}' '1|Q' | |
49 | testcase 'set -- Q R; set -- ${@#S}' '2|Q|R' | |
50 | testcase 'set -- Q R; set -- ${@##S}' '2|Q|R' | |
51 | testcase 'set -- Q R; set -- ${@%S}' '2|Q|R' | |
52 | testcase 'set -- Q R; set -- ${@%%S}' '2|Q|R' | |
53 | testcase 'set -- Q R; set -- "${@#Q}"' '2||R' | |
54 | testcase 'set -- Q R; set -- "${@%R}"' '2|Q|' | |
55 | testcase 'set -- Q R; set -- "${@%%R}"' '2|Q|' | |
56 | testcase 'set -- Q R; set -- "${@#S}"' '2|Q|R' | |
57 | testcase 'set -- Q R; set -- "${@##S}"' '2|Q|R' | |
58 | testcase 'set -- Q R; set -- "${@%S}"' '2|Q|R' | |
59 | testcase 'set -- Q R; set -- "${@%%S}"' '2|Q|R' | |
60 | ||
61 | test "x$failures" = x |