1 # $Id: moderrs.mk,v 1.1.1.8 2020/08/26 16:40:43 sjg Exp $
3 # various modifier error tests
6 # incase we have to change it ;-)
11 FIB= 1 1 2 3 5 8 13 21 34
13 all: modunkn modunknV varterm vartermV modtermV modloop
17 all: mod-subst-delimiter
18 all: mod-regex-delimiter
19 all: mod-regex-undefined-subexpression
23 all: mod-remember-parse
27 @echo "Expect: Unknown modifier 'Z'"
28 @echo "VAR:Z=${VAR:Z}"
31 @echo "Expect: Unknown modifier 'Z'"
32 @echo "VAR:${MOD_UNKN}=${VAR:${MOD_UNKN}}"
35 @echo "Expect: Unclosed variable specification for VAR"
36 @echo VAR:S,V,v,=${VAR:S,V,v,
39 @echo "Expect: Unclosed variable specification for VAR"
40 @echo VAR:${MOD_TERM},=${VAR:${MOD_S}
43 @echo "Expect: Unfinished modifier for VAR (',' missing)"
44 -@echo "VAR:${MOD_TERM}=${VAR:${MOD_TERM}}"
47 @echo "Expect: 2 errors about missing @ delimiter"
48 @echo ${UNDEF:U1 2 3:@var}
49 @echo ${UNDEF:U1 2 3:@var@...}
50 @echo ${UNDEF:U1 2 3:@var@${var}@}
52 # The closing brace after the ${var} is part of the replacement string.
53 # In ParseModifierPart, braces and parentheses don't have to be balanced.
54 # This is contrary to the :M, :N modifiers, where both parentheses and
55 # braces must be balanced.
56 # This is also contrary to the SysV modifier, where only the actually
57 # used delimiter (either braces or parentheses) must be balanced.
60 @echo ${UNDEF:U1 2 3:@var@${var}}...@
61 @echo ${UNDEF:U1 2 3:@var@${var}}...@}
64 @echo "Expect: 2 errors about missing ] delimiter"
65 @echo ${UNDEF:U1 2 3:[}
66 @echo ${UNDEF:U1 2 3:[#}
68 # out of bounds => empty
69 @echo 13=${UNDEF:U1 2 3:[13]}
71 # Word index out of bounds.
73 # On LP64I32, strtol returns LONG_MAX,
74 # which is then truncated to int (undefined behavior),
75 # typically resulting in -1.
76 # This -1 is interpreted as "the last word".
78 # On ILP32, strtol returns LONG_MAX,
79 # which is a large number.
80 # This results in a range from LONG_MAX - 1 to 3,
82 @echo 12345=${UNDEF:U1 2 3:[123451234512345123451234512345]:S,^$,ok,:S,^3$,ok,}
85 @echo "Expect: 2 errors about missing ! delimiter"
86 @echo ${VARNAME:!echo}
87 # When the final exclamation mark is missing, there is no
88 # fallback to the SysV substitution modifier.
89 # If there were a fallback, the output would be "exclam",
90 # and the above would have produced an "Unknown modifier '!'".
100 @echo ${VAR:S,from,to,
101 @echo ${VAR:S,from,to,}
104 @echo 3: ${VAR:S,from
106 @echo ${VAR:S,from,to
107 @echo ${VAR:S,from,to,
108 @echo ${VAR:S,from,to,}
116 @echo ${VAR:C,from,to
117 @echo ${VAR:C,from,to,
118 @echo ${VAR:C,from,to,}
121 @echo 3: ${VAR:C,from
123 @echo ${VAR:C,from,to
124 @echo ${VAR:C,from,to,
125 @echo ${VAR:C,from,to,}
127 # In regular expressions with alternatives, not all capturing groups are
128 # always set; some may be missing. Warn about these.
130 # Since there is no way to turn off this warning, the combination of
131 # alternative matches and capturing groups is not widely used.
133 # A newly added modifier 'U' such as in :C,(a.)|(b.),\1\2,U might be added
134 # for treating undefined capturing groups as empty, but that would create a
135 # syntactical ambiguity since the :S and :C modifiers are open-ended (see
136 # mod-subst-chain). Luckily the modifier :U does not make sense after :C,
137 # therefore this case does not happen in practice.
138 # The sub-modifier for the :C modifier would have to be chosen wisely.
139 mod-regex-undefined-subexpression:
141 @echo ${FIB:C,1(.*),one\1,} # all ok
142 @echo ${FIB:C,1(.*)|2(.*),(\1)+(\2),:Q} # no match for subexpression
147 @echo ${FIB:ts\65} # octal 065 == U+0035 == '5'
148 @echo ${FIB:ts\65oct} # bad modifier
149 @echo ${FIB:tsxy} # modifier too long
163 @echo ${FIB:?then:else
164 @echo ${FIB:?then:else}
169 @echo ${FIB:__} # modifier name too long
176 @echo ${FIB:3=x3} # ok