Root/
| 1 | #!/bin/bash |
| 2 | . ./Common |
| 3 | |
| 4 | ############################################################################### |
| 5 | |
| 6 | tst "substitutions: match fixed string, return other string (match)" \ |
| 7 | -ds -q FOO=x <<EOF |
| 8 | !-s |
| 9 | FOO=x { BAR=y } |
| 10 | EOF |
| 11 | |
| 12 | expect <<EOF |
| 13 | FOO=RE { |
| 14 | BAR=y |
| 15 | } |
| 16 | BAR=y |
| 17 | EOF |
| 18 | |
| 19 | #------------------------------------------------------------------------------ |
| 20 | |
| 21 | tst "substitutions: match fixed string, return other string (no match)" \ |
| 22 | -q FOO=y <<EOF |
| 23 | !-s |
| 24 | FOO=x { BAR=y } |
| 25 | EOF |
| 26 | |
| 27 | expect <<EOF |
| 28 | EOF |
| 29 | |
| 30 | #------------------------------------------------------------------------------ |
| 31 | |
| 32 | tst "substitutions: match fixed string, return input" -ds -q FOO=x <<EOF |
| 33 | !-s |
| 34 | FOO=x { BAR=\$\$ } |
| 35 | EOF |
| 36 | |
| 37 | expect <<EOF |
| 38 | FOO=RE { |
| 39 | BAR=\$\$ |
| 40 | } |
| 41 | BAR=x |
| 42 | EOF |
| 43 | |
| 44 | #------------------------------------------------------------------------------ |
| 45 | |
| 46 | tst "substitutions: match *, return input" -q FOO=xyz <<EOF |
| 47 | !-s |
| 48 | FOO=* { BAR=\$\$ } |
| 49 | EOF |
| 50 | |
| 51 | expect <<EOF |
| 52 | BAR=xyz |
| 53 | EOF |
| 54 | |
| 55 | #------------------------------------------------------------------------------ |
| 56 | |
| 57 | tst "substitutions: match ??? with xyz" -q FOO=xyz <<EOF |
| 58 | !-s |
| 59 | FOO=??? { BAR=x } |
| 60 | EOF |
| 61 | |
| 62 | expect <<EOF |
| 63 | BAR=x |
| 64 | EOF |
| 65 | |
| 66 | #------------------------------------------------------------------------------ |
| 67 | |
| 68 | tst "substitutions: don't match ??? with axyz" -q FOO=axyz <<EOF |
| 69 | !-s |
| 70 | FOO=??? { BAR=x } |
| 71 | EOF |
| 72 | |
| 73 | expect <<EOF |
| 74 | EOF |
| 75 | |
| 76 | #------------------------------------------------------------------------------ |
| 77 | |
| 78 | tst "substitutions: don't match ??? with xyza" -q FOO=xyza <<EOF |
| 79 | !-s |
| 80 | FOO=??? { BAR=x } |
| 81 | EOF |
| 82 | |
| 83 | expect <<EOF |
| 84 | EOF |
| 85 | |
| 86 | #------------------------------------------------------------------------------ |
| 87 | |
| 88 | tst "substitutions: match ?.? with x.z" -q FOO=x.z <<EOF |
| 89 | !-s |
| 90 | FOO=?.? { BAR=x } |
| 91 | EOF |
| 92 | |
| 93 | expect <<EOF |
| 94 | BAR=x |
| 95 | EOF |
| 96 | |
| 97 | #------------------------------------------------------------------------------ |
| 98 | |
| 99 | tst "substitutions: don't match ?.? with xyz" -q FOO=xyz <<EOF |
| 100 | !-s |
| 101 | FOO=?.? { BAR=x } |
| 102 | EOF |
| 103 | |
| 104 | expect <<EOF |
| 105 | EOF |
| 106 | |
| 107 | #------------------------------------------------------------------------------ |
| 108 | |
| 109 | tst "substitutions: match ?(?)?, return \$1" -q FOO=xyz <<EOF |
| 110 | !-s |
| 111 | FOO=?(?)? { BAR=\$1 } |
| 112 | EOF |
| 113 | |
| 114 | expect <<EOF |
| 115 | BAR=y |
| 116 | EOF |
| 117 | |
| 118 | #------------------------------------------------------------------------------ |
| 119 | |
| 120 | tst "substitutions: match ?(*)?, return \$1" -q FOO=xyzzy <<EOF |
| 121 | !-s |
| 122 | FOO=?(*)? { BAR=\$1 } |
| 123 | EOF |
| 124 | |
| 125 | expect <<EOF |
| 126 | BAR=yzz |
| 127 | EOF |
| 128 | |
| 129 | #------------------------------------------------------------------------------ |
| 130 | |
| 131 | tst_fail "substitutions: $0 does not exist" -q FOO=xyzzy <<EOF |
| 132 | !-s |
| 133 | FOO=?(*)? { BAR=\$0 } |
| 134 | EOF |
| 135 | |
| 136 | expect <<EOF |
| 137 | s:1: invalid variable name |
| 138 | EOF |
| 139 | |
| 140 | #------------------------------------------------------------------------------ |
| 141 | |
| 142 | tst_fail "substitutions: $2 with only one () pair" -q FOO=xyzzy <<EOF |
| 143 | !-s |
| 144 | FOO=?(*)? { BAR=\$2 } |
| 145 | EOF |
| 146 | |
| 147 | expect <<EOF |
| 148 | s:2: \$2 but only 1 parenthesis |
| 149 | EOF |
| 150 | |
| 151 | #------------------------------------------------------------------------------ |
| 152 | |
| 153 | tst "substitutions: $2 with two () pairs" -q FOO=xyzzy <<EOF |
| 154 | !-s |
| 155 | FOO=?(?)(*)? { BAR=\$2 } |
| 156 | EOF |
| 157 | |
| 158 | expect <<EOF |
| 159 | BAR=zz |
| 160 | EOF |
| 161 | |
| 162 | #------------------------------------------------------------------------------ |
| 163 | |
| 164 | tst_fail "substitutions: $3 with only two () pairs" -q FOO=xyzzy <<EOF |
| 165 | !-s |
| 166 | FOO=?(?)(*)? { BAR=\$3 } |
| 167 | EOF |
| 168 | |
| 169 | expect <<EOF |
| 170 | s:2: \$3 but only 2 parentheses |
| 171 | EOF |
| 172 | |
| 173 | #------------------------------------------------------------------------------ |
| 174 | |
| 175 | tst "substitutions: [ab], match a" -q FOO=abc <<EOF |
| 176 | !-s |
| 177 | FOO=([ab])* { BAR=\$1 } |
| 178 | EOF |
| 179 | |
| 180 | expect <<EOF |
| 181 | BAR=a |
| 182 | EOF |
| 183 | |
| 184 | #------------------------------------------------------------------------------ |
| 185 | |
| 186 | tst "substitutions: [ab], match b" -q FOO=abc <<EOF |
| 187 | !-s |
| 188 | FOO=*([ab])* { BAR=\$1 } |
| 189 | EOF |
| 190 | |
| 191 | expect <<EOF |
| 192 | BAR=b |
| 193 | EOF |
| 194 | |
| 195 | #------------------------------------------------------------------------------ |
| 196 | |
| 197 | tst_fail "substitutions: [ab is invalid" <<EOF |
| 198 | !-s |
| 199 | FOO=[ab { BAR=x } |
| 200 | EOF |
| 201 | |
| 202 | expect <<EOF |
| 203 | s:2: Unmatched [ or [^ |
| 204 | EOF |
| 205 | |
| 206 | #------------------------------------------------------------------------------ |
| 207 | |
| 208 | tst "substitutions: (a|b), match a" -q FOO=xa <<EOF |
| 209 | !-s |
| 210 | FOO=*(a|b) { BAR=\$1 } |
| 211 | EOF |
| 212 | |
| 213 | expect <<EOF |
| 214 | BAR=a |
| 215 | EOF |
| 216 | |
| 217 | #------------------------------------------------------------------------------ |
| 218 | |
| 219 | tst "substitutions: (a|b), match b" -q FOO=xb <<EOF |
| 220 | !-s |
| 221 | FOO=*(a|b) { BAR=\$1 } |
| 222 | EOF |
| 223 | |
| 224 | expect <<EOF |
| 225 | BAR=b |
| 226 | EOF |
| 227 | |
| 228 | #------------------------------------------------------------------------------ |
| 229 | |
| 230 | tst "substitutions: (|x), match the empty part" -q FOO=y <<EOF |
| 231 | !-s |
| 232 | FOO=(|x)y { BAR=\$1 } |
| 233 | EOF |
| 234 | |
| 235 | expect <<EOF |
| 236 | BAR= |
| 237 | EOF |
| 238 | |
| 239 | ############################################################################### |
| 240 |
Branches:
master
