1 # $NetBSD: varmod-to-separator.mk,v 1.6 2020/11/01 14:36:25 rillig Exp $
3 # Tests for the :ts variable modifier, which joins the words of the variable
4 # using an arbitrary character as word separator.
6 WORDS= one two three four five six
8 # The words are separated by a single space, just as usual.
9 .if ${WORDS:ts } != "one two three four five six"
10 . warning Space as separator does not work.
13 # The separator can be an arbitrary character, for example a comma.
14 .if ${WORDS:ts,} != "one,two,three,four,five,six"
15 . warning Comma as separator does not work.
18 # After the :ts modifier, other modifiers can follow.
19 .if ${WORDS:ts/:tu} != "ONE/TWO/THREE/FOUR/FIVE/SIX"
20 . warning Chaining modifiers does not work.
23 # To use the ':' as the separator, just write it normally.
24 # The first colon is the separator, the second ends the modifier.
25 .if ${WORDS:ts::tu} != "ONE:TWO:THREE:FOUR:FIVE:SIX"
26 . warning Colon as separator does not work.
29 # When there is just a colon but no other character, the words are
30 # "separated" by an empty string, that is, they are all squashed
32 .if ${WORDS:ts:tu} != "ONETWOTHREEFOURFIVESIX"
33 . warning Colon as separator does not work.
36 # Applying the :tu modifier first and then the :ts modifier does not change
37 # anything since neither of these modifiers is related to how the string is
38 # split into words. Beware of separating the words using a single or double
39 # quote though, or other special characters like dollar or backslash.
41 # This example also demonstrates that the closing brace is not interpreted
42 # as a separator, but as the closing delimiter of the whole variable
44 .if ${WORDS:tu:ts} != "ONETWOTHREEFOURFIVESIX"
45 . warning Colon as separator does not work.
48 # The '}' plays the same role as the ':' in the preceding examples.
49 # Since there is a single character before it, that character is taken as
51 .if ${WORDS:tu:ts/} != "ONE/TWO/THREE/FOUR/FIVE/SIX"
52 . warning Colon as separator does not work.
55 # Now it gets interesting and ambiguous: The separator could either be empty
56 # since it is followed by a colon. Or it could be the colon since that
57 # colon is followed by the closing brace. It's the latter case.
58 .if ${WORDS:ts:} != "one:two:three:four:five:six"
59 . warning Colon followed by closing brace does not work.
62 # As in the ${WORDS:tu:ts} example above, the separator is empty.
63 .if ${WORDS:ts} != "onetwothreefourfivesix"
64 . warning Empty separator before closing brace does not work.
67 # The :ts modifier can be followed by other modifiers.
68 .if ${WORDS:ts:S/two/2/} != "one2threefourfivesix"
69 . warning Separator followed by :S modifier does not work.
72 # The :ts modifier can follow other modifiers.
73 .if ${WORDS:S/two/2/:ts} != "one2threefourfivesix"
74 . warning :S modifier followed by :ts modifier does not work.
77 # The :ts modifier with an actual separator can be followed by other
79 .if ${WORDS:ts/:S/two/2/} != "one/2/three/four/five/six"
80 . warning The :ts modifier followed by an :S modifier does not work.
83 # The separator can be \n, which is a newline.
84 .if ${WORDS:[1..3]:ts\n} != "one${.newline}two${.newline}three"
85 . warning The separator \n does not produce a newline.
88 # The separator can be \t, which is a tab.
89 .if ${WORDS:[1..3]:ts\t} != "one two three"
90 . warning The separator \t does not produce a tab.
93 # The separator can be given as octal number.
94 .if ${WORDS:[1..3]:ts\012:tu} != "ONE${.newline}TWO${.newline}THREE"
95 . warning The separator \012 is not interpreted in octal ASCII.
98 # The octal number can have as many digits as it wants.
99 .if ${WORDS:[1..2]:ts\000000000000000000000000012:tu} != "ONE${.newline}TWO"
100 . warning The separator \012 cannot have many leading zeroes.
103 # The value of the separator character must not be outside the value space
104 # for an unsigned character though.
106 # Since 2020-11-01, these out-of-bounds values are rejected.
107 .if ${WORDS:[1..3]:ts\400:tu}
108 . warning The separator \400 is accepted even though it is out of bounds.
110 . warning The separator \400 is accepted even though it is out of bounds.
113 # The separator can be given as hexadecimal number.
114 .if ${WORDS:[1..3]:ts\xa:tu} != "ONE${.newline}TWO${.newline}THREE"
115 . warning The separator \xa is not interpreted in hexadecimal ASCII.
118 # The hexadecimal number must be in the range of an unsigned char.
120 # Since 2020-11-01, these out-of-bounds values are rejected.
121 .if ${WORDS:[1..3]:ts\x100:tu}
122 . warning The separator \x100 is accepted even though it is out of bounds.
124 . warning The separator \x100 is accepted even though it is out of bounds.
127 # Negative numbers are not allowed for the separator character.
128 .if ${WORDS:[1..3]:ts\-300:tu}
129 . warning The separator \-300 is accepted even though it is negative.
131 . warning The separator \-300 is accepted even though it is negative.
134 # The character number is interpreted as octal number by default.
135 # The digit '8' is not an octal digit though.
136 .if ${1 2 3:L:ts\8:tu}
137 . warning The separator \8 is accepted even though it is not octal.
139 . warning The separator \8 is accepted even though it is not octal.
142 # Trailing characters after the octal character number are rejected.
143 .if ${1 2 3:L:ts\100L}
144 . warning The separator \100L is accepted even though it contains an 'L'.
146 . warning The separator \100L is accepted even though it contains an 'L'.
149 # Trailing characters after the hexadecimal character number are rejected.
150 .if ${1 2 3:L:ts\x40g}
151 . warning The separator \x40g is accepted even though it contains a 'g'.
153 . warning The separator \x40g is accepted even though it contains a 'g'.
157 # In the :t modifier, the :t must be followed by any of A, l, s, u.
158 .if ${WORDS:tx} != "anything"
159 . info This line is not reached because of the malformed condition.
160 . info If this line were reached, it would be visible in the -dcpv log.
163 # After the backslash, only n, t, an octal number, or x and a hexadecimal
164 # number are allowed.
165 .if ${WORDS:t\X} != "anything"
166 . info This line is not reached.