moderrs.mk revision 1.18 1 1.18 rillig # $NetBSD: moderrs.mk,v 1.18 2020/11/01 10:12:38 rillig Exp $
2 1.1 apb #
3 1.1 apb # various modifier error tests
4 1.1 apb
5 1.17 rillig VAR= TheVariable
6 1.18 rillig # in case we have to change it ;-)
7 1.17 rillig MOD_UNKN= Z
8 1.17 rillig MOD_TERM= S,V,v
9 1.17 rillig MOD_S:= ${MOD_TERM},
10 1.1 apb
11 1.7 rillig FIB= 1 1 2 3 5 8 13 21 34
12 1.7 rillig
13 1.2 rillig all: modunkn modunknV varterm vartermV modtermV modloop
14 1.5 rillig all: modloop-close
15 1.3 rillig all: modwords
16 1.4 rillig all: modexclam
17 1.6 rillig all: mod-subst-delimiter
18 1.7 rillig all: mod-regex-delimiter
19 1.13 rillig all: mod-regex-undefined-subexpression
20 1.7 rillig all: mod-ts-parse
21 1.7 rillig all: mod-t-parse
22 1.7 rillig all: mod-ifelse-parse
23 1.7 rillig all: mod-remember-parse
24 1.7 rillig all: mod-sysv-parse
25 1.1 apb
26 1.18 rillig modunkn: print-name
27 1.1 apb @echo "Expect: Unknown modifier 'Z'"
28 1.1 apb @echo "VAR:Z=${VAR:Z}"
29 1.1 apb
30 1.18 rillig modunknV: print-name
31 1.1 apb @echo "Expect: Unknown modifier 'Z'"
32 1.1 apb @echo "VAR:${MOD_UNKN}=${VAR:${MOD_UNKN}}"
33 1.1 apb
34 1.18 rillig varterm: print-name
35 1.1 apb @echo "Expect: Unclosed variable specification for VAR"
36 1.1 apb @echo VAR:S,V,v,=${VAR:S,V,v,
37 1.1 apb
38 1.18 rillig vartermV: print-name
39 1.1 apb @echo "Expect: Unclosed variable specification for VAR"
40 1.1 apb @echo VAR:${MOD_TERM},=${VAR:${MOD_S}
41 1.1 apb
42 1.18 rillig modtermV: print-name
43 1.12 rillig @echo "Expect: Unfinished modifier for VAR (',' missing)"
44 1.1 apb -@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
45 1.2 rillig
46 1.18 rillig modloop: print-name
47 1.3 rillig @echo "Expect: 2 errors about missing @ delimiter"
48 1.2 rillig @echo ${UNDEF:U1 2 3:@var}
49 1.2 rillig @echo ${UNDEF:U1 2 3:@var (a] ...}
50 1.2 rillig @echo ${UNDEF:U1 2 3:@var@${var}@}
51 1.3 rillig
52 1.5 rillig # The closing brace after the ${var} is part of the replacement string.
53 1.5 rillig # In ParseModifierPart, braces and parentheses don't have to be balanced.
54 1.5 rillig # This is contrary to the :M, :N modifiers, where both parentheses and
55 1.5 rillig # braces must be balanced.
56 1.5 rillig # This is also contrary to the SysV modifier, where only the actually
57 1.5 rillig # used delimiter (either braces or parentheses) must be balanced.
58 1.18 rillig modloop-close: print-name
59 1.5 rillig @echo ${UNDEF:U1 2 3:@var@${var}}...@
60 1.5 rillig @echo ${UNDEF:U1 2 3:@var@${var}}...@}
61 1.5 rillig
62 1.18 rillig modwords: print-name
63 1.3 rillig @echo "Expect: 2 errors about missing ] delimiter"
64 1.3 rillig @echo ${UNDEF:U1 2 3:[}
65 1.3 rillig @echo ${UNDEF:U1 2 3:[#}
66 1.3 rillig
67 1.3 rillig # out of bounds => empty
68 1.3 rillig @echo 13=${UNDEF:U1 2 3:[13]}
69 1.3 rillig
70 1.3 rillig # Word index out of bounds.
71 1.3 rillig #
72 1.3 rillig # On LP64I32, strtol returns LONG_MAX,
73 1.3 rillig # which is then truncated to int (undefined behavior),
74 1.3 rillig # typically resulting in -1.
75 1.3 rillig # This -1 is interpreted as "the last word".
76 1.3 rillig #
77 1.3 rillig # On ILP32, strtol returns LONG_MAX,
78 1.3 rillig # which is a large number.
79 1.3 rillig # This results in a range from LONG_MAX - 1 to 3,
80 1.3 rillig # which is empty.
81 1.3 rillig @echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
82 1.4 rillig
83 1.18 rillig modexclam: print-name
84 1.4 rillig @echo "Expect: 2 errors about missing ! delimiter"
85 1.4 rillig @echo ${VARNAME:!echo}
86 1.4 rillig # When the final exclamation mark is missing, there is no
87 1.4 rillig # fallback to the SysV substitution modifier.
88 1.4 rillig # If there were a fallback, the output would be "exclam",
89 1.4 rillig # and the above would have produced an "Unknown modifier '!'".
90 1.4 rillig @echo ${!:L:!=exclam}
91 1.6 rillig
92 1.18 rillig mod-subst-delimiter: print-name
93 1.6 rillig @echo ${VAR:S
94 1.6 rillig @echo ${VAR:S,
95 1.6 rillig @echo ${VAR:S,from
96 1.6 rillig @echo ${VAR:S,from,
97 1.6 rillig @echo ${VAR:S,from,to
98 1.6 rillig @echo ${VAR:S,from,to,
99 1.6 rillig @echo ${VAR:S,from,to,}
100 1.6 rillig @echo 1: ${VAR:S
101 1.6 rillig @echo 2: ${VAR:S,
102 1.6 rillig @echo 3: ${VAR:S,from
103 1.6 rillig @echo ${VAR:S,from,
104 1.6 rillig @echo ${VAR:S,from,to
105 1.6 rillig @echo ${VAR:S,from,to,
106 1.6 rillig @echo ${VAR:S,from,to,}
107 1.7 rillig
108 1.18 rillig mod-regex-delimiter: print-name
109 1.7 rillig @echo ${VAR:C
110 1.7 rillig @echo ${VAR:C,
111 1.7 rillig @echo ${VAR:C,from
112 1.7 rillig @echo ${VAR:C,from,
113 1.7 rillig @echo ${VAR:C,from,to
114 1.7 rillig @echo ${VAR:C,from,to,
115 1.7 rillig @echo ${VAR:C,from,to,}
116 1.7 rillig @echo 1: ${VAR:C
117 1.7 rillig @echo 2: ${VAR:C,
118 1.7 rillig @echo 3: ${VAR:C,from
119 1.7 rillig @echo ${VAR:C,from,
120 1.7 rillig @echo ${VAR:C,from,to
121 1.7 rillig @echo ${VAR:C,from,to,
122 1.7 rillig @echo ${VAR:C,from,to,}
123 1.7 rillig
124 1.13 rillig # In regular expressions with alternatives, not all capturing groups are
125 1.13 rillig # always set; some may be missing. Warn about these.
126 1.13 rillig #
127 1.13 rillig # Since there is no way to turn off this warning, the combination of
128 1.13 rillig # alternative matches and capturing groups is not widely used.
129 1.13 rillig #
130 1.13 rillig # A newly added modifier 'U' such as in :C,(a.)|(b.),\1\2,U might be added
131 1.13 rillig # for treating undefined capturing groups as empty, but that would create a
132 1.13 rillig # syntactical ambiguity since the :S and :C modifiers are open-ended (see
133 1.13 rillig # mod-subst-chain). Luckily the modifier :U does not make sense after :C,
134 1.13 rillig # therefore this case does not happen in practice.
135 1.13 rillig # The sub-modifier for the :C modifier would have to be chosen wisely.
136 1.18 rillig mod-regex-undefined-subexpression: print-name
137 1.13 rillig @echo ${FIB:C,1(.*),one\1,} # all ok
138 1.14 rillig @echo ${FIB:C,1(.*)|2(.*),(\1)+(\2),:Q} # no match for subexpression
139 1.13 rillig
140 1.18 rillig mod-ts-parse: print-name
141 1.7 rillig @echo ${FIB:ts}
142 1.7 rillig @echo ${FIB:ts\65} # octal 065 == U+0035 == '5'
143 1.7 rillig @echo ${FIB:ts\65oct} # bad modifier
144 1.7 rillig @echo ${FIB:tsxy} # modifier too long
145 1.7 rillig
146 1.18 rillig mod-t-parse: print-name
147 1.10 rillig @echo ${FIB:t
148 1.7 rillig @echo ${FIB:txy}
149 1.7 rillig @echo ${FIB:t}
150 1.7 rillig @echo ${FIB:t:M*}
151 1.7 rillig
152 1.18 rillig mod-ifelse-parse: print-name
153 1.7 rillig @echo ${FIB:?
154 1.7 rillig @echo ${FIB:?then
155 1.7 rillig @echo ${FIB:?then:
156 1.7 rillig @echo ${FIB:?then:else
157 1.7 rillig @echo ${FIB:?then:else}
158 1.7 rillig
159 1.18 rillig mod-remember-parse: print-name
160 1.7 rillig @echo ${FIB:_} # ok
161 1.7 rillig @echo ${FIB:__} # modifier name too long
162 1.7 rillig
163 1.18 rillig mod-sysv-parse: print-name
164 1.7 rillig @echo ${FIB:3
165 1.7 rillig @echo ${FIB:3=
166 1.7 rillig @echo ${FIB:3=x3
167 1.7 rillig @echo ${FIB:3=x3} # ok
168 1.18 rillig
169 1.18 rillig print-name: .USEBEFORE
170 1.18 rillig @echo $@:
171