1# $NetBSD: varmod-select-words.mk,v 1.6 2024/08/29 20:20:36 rillig Exp $ 2# 3# Tests for the :[...] variable modifier, which selects a single word 4# or a range of words from a variable. 5# 6# History: 7# The variable modifier ':[...]' was added on 2003-09-27. 8# 9# See also: 10# modword.mk (should be migrated here) 11 12all: mod-squarebrackets mod-S-W mod-C-W mod-tW-tw 13 14LIST= one two three four five six 15LONGLIST= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 16 17EMPTY= # the space should be ignored 18ESCAPEDSPACE= \ # escaped space before the '#', the actual value is '\ ' 19REALLYSPACE:= ${:U } 20HASH= \# 21AT= @ 22STAR= * 23ZERO= 0 24ONE= 1 25MINUSONE= -1 26 27mod-squarebrackets: \ 28 mod-squarebrackets-empty \ 29 mod-squarebrackets-0-star-at \ 30 mod-squarebrackets-hash \ 31 mod-squarebrackets-n-ok-1 \ 32 mod-squarebrackets-n-error-1 \ 33 mod-squarebrackets-n-error-2 \ 34 mod-squarebrackets-n-ok-2 \ 35 mod-squarebrackets-n-error-3 \ 36 mod-squarebrackets-n-error-4 \ 37 mod-squarebrackets-n-ok-3 \ 38 mod-squarebrackets-start-end-error-1 \ 39 mod-squarebrackets-start-end-error-2 \ 40 mod-squarebrackets-start-end-error-3 \ 41 mod-squarebrackets-start-end-ok-1 \ 42 mod-squarebrackets-start-end-error-4 \ 43 mod-squarebrackets-start-end-ok-2 \ 44 mod-squarebrackets-start-end-error-5 \ 45 mod-squarebrackets-start-end-error-6 \ 46 mod-squarebrackets-start-end-ok-3 \ 47 mod-squarebrackets-nested-ok-1 \ 48 mod-squarebrackets-nested-error-1 \ 49 mod-squarebrackets-nested-ok-2 \ 50 mod-squarebrackets-space 51 52mod-squarebrackets-empty: 53# expect: make: Bad modifier ":[]" 54 @echo 'LIST:[]="${LIST:[]}" is an error' 55 56mod-squarebrackets-0-star-at: 57 @echo 'LIST:[0]="${LIST:[0]}"' 58 @echo 'LIST:[0x0]="${LIST:[0x0]}"' 59 @echo 'LIST:[000]="${LIST:[000]}"' 60 @echo 'LIST:[*]="${LIST:[*]}"' 61 @echo 'LIST:[@]="${LIST:[@]}"' 62 @echo 'LIST:[0]:C/ /,/="${LIST:[0]:C/ /,/}"' 63 @echo 'LIST:[0]:C/ /,/g="${LIST:[0]:C/ /,/g}"' 64 @echo 'LIST:[0]:C/ /,/1g="${LIST:[0]:C/ /,/1g}"' 65 @echo 'LIST:[*]:C/ /,/="${LIST:[*]:C/ /,/}"' 66 @echo 'LIST:[*]:C/ /,/g="${LIST:[*]:C/ /,/g}"' 67 @echo 'LIST:[*]:C/ /,/1g="${LIST:[*]:C/ /,/1g}"' 68 @echo 'LIST:[@]:C/ /,/="${LIST:[@]:C/ /,/}"' 69 @echo 'LIST:[@]:C/ /,/g="${LIST:[@]:C/ /,/g}"' 70 @echo 'LIST:[@]:C/ /,/1g="${LIST:[@]:C/ /,/1g}"' 71 @echo 'LIST:[@]:[0]:C/ /,/="${LIST:[@]:[0]:C/ /,/}"' 72 @echo 'LIST:[0]:[@]:C/ /,/="${LIST:[0]:[@]:C/ /,/}"' 73 @echo 'LIST:[@]:[*]:C/ /,/="${LIST:[@]:[*]:C/ /,/}"' 74 @echo 'LIST:[*]:[@]:C/ /,/="${LIST:[*]:[@]:C/ /,/}"' 75 76mod-squarebrackets-hash: 77 @echo 'EMPTY="${EMPTY}"' 78 @echo 'EMPTY:[#]="${EMPTY:[#]}" == 1 ?' 79 @echo 'ESCAPEDSPACE="${ESCAPEDSPACE}"' 80 @echo 'ESCAPEDSPACE:[#]="${ESCAPEDSPACE:[#]}" == 1 ?' 81 @echo 'REALLYSPACE="${REALLYSPACE}"' 82 @echo 'REALLYSPACE:[#]="${REALLYSPACE:[#]}" == 1 ?' 83 @echo 'LIST:[#]="${LIST:[#]}"' 84 @echo 'LIST:[0]:[#]="${LIST:[0]:[#]}" == 1 ?' 85 @echo 'LIST:[*]:[#]="${LIST:[*]:[#]}" == 1 ?' 86 @echo 'LIST:[@]:[#]="${LIST:[@]:[#]}"' 87 @echo 'LIST:[1]:[#]="${LIST:[1]:[#]}"' 88 @echo 'LIST:[1..3]:[#]="${LIST:[1..3]:[#]}"' 89 90mod-squarebrackets-n-ok-1: 91 @echo 'EMPTY:[1]="${EMPTY:[1]}"' 92 @echo 'ESCAPEDSPACE="${ESCAPEDSPACE}"' 93 @echo 'ESCAPEDSPACE:[1]="${ESCAPEDSPACE:[1]}"' 94 @echo 'REALLYSPACE="${REALLYSPACE}"' 95 @echo 'REALLYSPACE:[1]="${REALLYSPACE:[1]}" == "" ?' 96 @echo 'REALLYSPACE:[*]:[1]="${REALLYSPACE:[*]:[1]}" == " " ?' 97 @echo 'LIST:[1]="${LIST:[1]}"' 98mod-squarebrackets-n-error-1: 99# expect: make: Bad modifier ":[1.]" 100 @echo 'LIST:[1.]="${LIST:[1.]}" is an error' 101mod-squarebrackets-n-error-2: 102# expect: make: Bad modifier ":[1]." 103 @echo 'LIST:[1].="${LIST:[1].}" is an error' 104mod-squarebrackets-n-ok-2: 105 @echo 'LIST:[2]="${LIST:[2]}"' 106 @echo 'LIST:[6]="${LIST:[6]}"' 107 @echo 'LIST:[7]="${LIST:[7]}"' 108 @echo 'LIST:[999]="${LIST:[999]}"' 109mod-squarebrackets-n-error-3: 110# expect: make: Bad modifier ":[-]" 111 @echo 'LIST:[-]="${LIST:[-]}" is an error' 112mod-squarebrackets-n-error-4: 113# expect: make: Bad modifier ":[--]" 114 @echo 'LIST:[--]="${LIST:[--]}" is an error' 115mod-squarebrackets-n-ok-3: 116 @echo 'LIST:[-1]="${LIST:[-1]}"' 117 @echo 'LIST:[-2]="${LIST:[-2]}"' 118 @echo 'LIST:[-6]="${LIST:[-6]}"' 119 @echo 'LIST:[-7]="${LIST:[-7]}"' 120 @echo 'LIST:[-999]="${LIST:[-999]}"' 121 @echo 'LONGLIST:[17]="${LONGLIST:[17]}"' 122 @echo 'LONGLIST:[0x11]="${LONGLIST:[0x11]}"' 123 @echo 'LONGLIST:[021]="${LONGLIST:[021]}"' 124 @echo 'LIST:[0]:[1]="${LIST:[0]:[1]}"' 125 @echo 'LIST:[*]:[1]="${LIST:[*]:[1]}"' 126 @echo 'LIST:[@]:[1]="${LIST:[@]:[1]}"' 127 @echo 'LIST:[0]:[2]="${LIST:[0]:[2]}"' 128 @echo 'LIST:[*]:[2]="${LIST:[*]:[2]}"' 129 @echo 'LIST:[@]:[2]="${LIST:[@]:[2]}"' 130 @echo 'LIST:[*]:C/ /,/:[2]="${LIST:[*]:C/ /,/:[2]}"' 131 @echo 'LIST:[*]:C/ /,/:[*]:[2]="${LIST:[*]:C/ /,/:[*]:[2]}"' 132 @echo 'LIST:[*]:C/ /,/:[@]:[2]="${LIST:[*]:C/ /,/:[@]:[2]}"' 133 @echo 'LONGLIST:[012..0x12]="${LONGLIST:[012..0x12]}"' 134 135mod-squarebrackets-start-end-error-1: 136# expect: make: Bad modifier ":[1.]" 137 @echo 'LIST:[1.]="${LIST:[1.]}" is an error' 138mod-squarebrackets-start-end-error-2: 139# expect: make: Bad modifier ":[1..]" 140 @echo 'LIST:[1..]="${LIST:[1..]}" is an error' 141mod-squarebrackets-start-end-error-3: 142# expect: make: Bad modifier ":[1.. ]" 143 @echo 'LIST:[1.. ]="${LIST:[1.. ]}" is an error' 144mod-squarebrackets-start-end-ok-1: 145 @echo 'LIST:[1..1]="${LIST:[1..1]}"' 146mod-squarebrackets-start-end-error-4: 147# expect: make: Bad modifier ":[1..1.]" 148 @echo 'LIST:[1..1.]="${LIST:[1..1.]}" is an error' 149mod-squarebrackets-start-end-ok-2: 150 @echo 'LIST:[1..2]="${LIST:[1..2]}"' 151 @echo 'LIST:[2..1]="${LIST:[2..1]}"' 152 @echo 'LIST:[3..-2]="${LIST:[3..-2]}"' 153 @echo 'LIST:[-4..4]="${LIST:[-4..4]}"' 154mod-squarebrackets-start-end-error-5: 155# expect: make: Bad modifier ":[0..1]" 156 @echo 'LIST:[0..1]="${LIST:[0..1]}" is an error' 157mod-squarebrackets-start-end-error-6: 158# expect: make: Bad modifier ":[-1..0]" 159 @echo 'LIST:[-1..0]="${LIST:[-1..0]}" is an error' 160mod-squarebrackets-start-end-ok-3: 161 @echo 'LIST:[-1..1]="${LIST:[-1..1]}"' 162 @echo 'LIST:[0..0]="${LIST:[0..0]}"' 163 @echo 'LIST:[3..99]="${LIST:[3..99]}"' 164 @echo 'LIST:[-3..-99]="${LIST:[-3..-99]}"' 165 @echo 'LIST:[-99..-3]="${LIST:[-99..-3]}"' 166 167mod-squarebrackets-nested-ok-1: 168 @echo 'HASH="${HASH}" == "#" ?' 169 @echo 'LIST:[$${HASH}]="${LIST:[${HASH}]}"' 170 @echo 'LIST:[$${ZERO}]="${LIST:[${ZERO}]}"' 171 @echo 'LIST:[$${ZERO}x$${ONE}]="${LIST:[${ZERO}x${ONE}]}"' 172 @echo 'LIST:[$${ONE}]="${LIST:[${ONE}]}"' 173 @echo 'LIST:[$${MINUSONE}]="${LIST:[${MINUSONE}]}"' 174 @echo 'LIST:[$${STAR}]="${LIST:[${STAR}]}"' 175 @echo 'LIST:[$${AT}]="${LIST:[${AT}]}"' 176mod-squarebrackets-nested-error-1: 177# expect: make: Bad modifier ":[${EMPTY" 178 @echo 'LIST:[$${EMPTY}]="${LIST:[${EMPTY}]}" is an error' 179mod-squarebrackets-nested-ok-2: 180 @echo 'LIST:[$${LONGLIST:[21]:S/2//}]="${LIST:[${LONGLIST:[21]:S/2//}]}"' 181 @echo 'LIST:[$${LIST:[#]}]="${LIST:[${LIST:[#]}]}"' 182 @echo 'LIST:[$${LIST:[$${HASH}]}]="${LIST:[${LIST:[${HASH}]}]}"' 183 184mod-squarebrackets-space: 185 # As of 2020-11-01, it is possible to have spaces before the numbers 186 # but not after them. This is an unintended side-effect of using 187 # strtol for parsing the numbers. 188 @echo 'LIST:[ -1.. +3]="${LIST:[ -1.. +3]}"' 189 190mod-C-W: 191 @echo 'LIST:C/ /,/="${LIST:C/ /,/}"' 192 @echo 'LIST:C/ /,/W="${LIST:C/ /,/W}"' 193 @echo 'LIST:C/ /,/gW="${LIST:C/ /,/gW}"' 194 @echo 'EMPTY:C/^/,/="${EMPTY:C/^/,/}"' 195 @echo 'EMPTY:C/^/,/W="${EMPTY:C/^/,/W}"' 196 197mod-S-W: 198 @echo 'LIST:S/ /,/="${LIST:S/ /,/}"' 199 @echo 'LIST:S/ /,/W="${LIST:S/ /,/W}"' 200 @echo 'LIST:S/ /,/gW="${LIST:S/ /,/gW}"' 201 @echo 'EMPTY:S/^/,/="${EMPTY:S/^/,/}"' 202 @echo 'EMPTY:S/^/,/W="${EMPTY:S/^/,/W}"' 203 204mod-tW-tw: 205 @echo 'LIST:tW="${LIST:tW}"' 206 @echo 'LIST:tw="${LIST:tw}"' 207 @echo 'LIST:tW:C/ /,/="${LIST:tW:C/ /,/}"' 208 @echo 'LIST:tW:C/ /,/g="${LIST:tW:C/ /,/g}"' 209 @echo 'LIST:tW:C/ /,/1g="${LIST:tW:C/ /,/1g}"' 210 @echo 'LIST:tw:C/ /,/="${LIST:tw:C/ /,/}"' 211 @echo 'LIST:tw:C/ /,/g="${LIST:tw:C/ /,/g}"' 212 @echo 'LIST:tw:C/ /,/1g="${LIST:tw:C/ /,/1g}"' 213 @echo 'LIST:tw:tW:C/ /,/="${LIST:tw:tW:C/ /,/}"' 214 @echo 'LIST:tW:tw:C/ /,/="${LIST:tW:tw:C/ /,/}"' 215