varmod-sysv.mk revision 1.7 1 1.7 rillig # $NetBSD: varmod-sysv.mk,v 1.7 2020/10/31 09:03:36 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix
4 1.2 rillig # "from" with "to". It can also use '%' as a wildcard.
5 1.2 rillig #
6 1.2 rillig # This modifier is applied when the other modifiers don't match exactly.
7 1.6 rillig #
8 1.6 rillig # See ApplyModifier_SysV.
9 1.1 rillig
10 1.4 rillig all:
11 1.1 rillig
12 1.3 rillig # The :Q looks like a modifier but isn't.
13 1.3 rillig # It is part of the replacement string.
14 1.4 rillig .if ${a b c d e:L:%a=x:Q} != "x:Q b c d e"
15 1.4 rillig . error
16 1.4 rillig .endif
17 1.3 rillig
18 1.3 rillig # Before 2020-07-19, an ampersand could be used in the replacement part
19 1.4 rillig # of a SysV substitution modifier, and it was replaced with the whole match,
20 1.4 rillig # just like in the :S modifier.
21 1.4 rillig #
22 1.4 rillig # This was probably a copy-and-paste mistake since the code for the SysV
23 1.4 rillig # modifier looked a lot like the code for the :S and :C modifiers.
24 1.4 rillig # The ampersand is not mentioned in the manual page.
25 1.4 rillig .if ${a.bcd.e:L:a.%=%} != "bcd.e"
26 1.4 rillig . error
27 1.4 rillig .endif
28 1.4 rillig # Before 2020-07-19, the result of the expression was "a.bcd.e".
29 1.4 rillig .if ${a.bcd.e:L:a.%=&} != "&"
30 1.4 rillig . error
31 1.4 rillig .endif
32 1.3 rillig
33 1.3 rillig # Before 2020-07-20, when a SysV modifier was parsed, a single dollar
34 1.4 rillig # before the '=' was parsed (but not interpreted) as an anchor.
35 1.4 rillig # Parsing something without then evaluating it accordingly doesn't make
36 1.4 rillig # sense.
37 1.4 rillig .if ${value:L:e$=x} != "value"
38 1.4 rillig . error
39 1.4 rillig .endif
40 1.4 rillig # Before 2020-07-20, the modifier ":e$=x" was parsed as having a left-hand
41 1.4 rillig # side "e" and a right-hand side "x". The dollar was parsed (but not
42 1.4 rillig # interpreted) as 'anchor at the end'. Therefore the modifier was equivalent
43 1.4 rillig # to ":e=x", which doesn't match the string "value$". Therefore the whole
44 1.4 rillig # expression evaluated to "value$".
45 1.4 rillig .if ${${:Uvalue\$}:L:e$=x} != "valux"
46 1.4 rillig . error
47 1.4 rillig .endif
48 1.4 rillig .if ${value:L:e=x} != "valux"
49 1.4 rillig . error
50 1.4 rillig .endif
51 1.3 rillig
52 1.3 rillig # Words that don't match are copied unmodified.
53 1.4 rillig .if ${:Ufile.c file.h:%.c=%.cpp} != "file.cpp file.h"
54 1.4 rillig . error
55 1.4 rillig .endif
56 1.4 rillig
57 1.4 rillig # The % placeholder can be anywhere in the string, it doesn't have to be at
58 1.4 rillig # the beginning of the pattern.
59 1.4 rillig .if ${:Ufile.c other.c:file.%=renamed.%} != "renamed.c other.c"
60 1.4 rillig . error
61 1.4 rillig .endif
62 1.3 rillig
63 1.7 rillig # Each word gets the suffix "X" appended.
64 1.7 rillig .if ${one two:L:=X} != "oneX twoX"
65 1.7 rillig . error
66 1.7 rillig .endif
67 1.7 rillig
68 1.6 rillig # The suffix "o" is replaced with "X".
69 1.6 rillig .if ${one two:L:o=X} != "one twX"
70 1.4 rillig . error
71 1.4 rillig .endif
72 1.6 rillig
73 1.6 rillig # The suffix "o" is replaced with nothing.
74 1.6 rillig .if ${one two:L:o=} != "one tw"
75 1.4 rillig . error
76 1.4 rillig .endif
77 1.6 rillig
78 1.6 rillig # The suffix "o" is replaced with a literal percent. The percent is only
79 1.6 rillig # a wildcard when it appears on the left-hand side.
80 1.6 rillig .if ${one two:L:o=%} != "one tw%"
81 1.4 rillig . error
82 1.4 rillig .endif
83 1.6 rillig
84 1.6 rillig # Each word with the suffix "o" is replaced with "X". The percent is a
85 1.6 rillig # wildcard even though the right-hand side does not contain another percent.
86 1.6 rillig .if ${one two:L:%o=X} != "one X"
87 1.4 rillig . error
88 1.4 rillig .endif
89 1.6 rillig
90 1.6 rillig # Each word with the prefix "o" is replaced with "X". The percent is a
91 1.6 rillig # wildcard even though the right-hand side does not contain another percent.
92 1.6 rillig .if ${one two:L:o%=X} != "X two"
93 1.4 rillig . error
94 1.4 rillig .endif
95 1.6 rillig
96 1.6 rillig # For each word with the prefix "o" and the suffix "e", the whole word is
97 1.6 rillig # replaced with "X".
98 1.6 rillig .if ${one two oe oxen:L:o%e=X} != "X two X oxen"
99 1.4 rillig . error
100 1.4 rillig .endif
101 1.6 rillig
102 1.6 rillig # Only the first '%' is the wildcard.
103 1.6 rillig .if ${one two o%e other%e:L:o%%e=X} != "one two X X"
104 1.4 rillig . error
105 1.4 rillig .endif
106 1.6 rillig
107 1.6 rillig # In the replacement, only the first '%' is the placeholder, all others
108 1.6 rillig # are literal percent characters.
109 1.6 rillig .if ${one two:L:%=%%} != "one% two%"
110 1.4 rillig . error
111 1.4 rillig .endif
112 1.6 rillig
113 1.6 rillig # In the word "one", only a prefix of the pattern suffix "nes" matches,
114 1.6 rillig # the whole word is too short. Therefore it doesn't match.
115 1.6 rillig .if ${one two:L:%nes=%xxx} != "one two"
116 1.4 rillig . error
117 1.3 rillig .endif
118 1.5 rillig
119 1.5 rillig # As of 2020-10-06, the right-hand side of the SysV modifier is expanded
120 1.5 rillig # twice. The first expansion happens in ApplyModifier_SysV, where the
121 1.5 rillig # modifier is split into its two parts. The second expansion happens
122 1.5 rillig # when each word is replaced in ModifyWord_SYSVSubst.
123 1.5 rillig # XXX: This is unexpected. Add more test case to demonstrate the effects
124 1.5 rillig # of removing one of the expansions.
125 1.5 rillig VALUE= value
126 1.5 rillig INDIRECT= 1:${VALUE} 2:$${VALUE} 4:$$$${VALUE}
127 1.5 rillig .if ${x:L:x=${INDIRECT}} != "1:value 2:value 4:\${VALUE}"
128 1.5 rillig . error
129 1.5 rillig .endif
130