1# $NetBSD: varmod-range.mk,v 1.7 2020/11/01 14:36:25 rillig Exp $
2#
3# Tests for the :range variable modifier, which generates sequences
4# of integers from the given range.
5#
6# See also:
7#	modword.mk
8
9# The :range modifier generates a sequence of integers, one number per
10# word of the variable expression's value.
11.if ${a b c:L:range} != "1 2 3"
12.  error
13.endif
14
15# To preserve spaces in a word, they can be enclosed in quotes, just like
16# everywhere else.
17.if ${:U first "the second word" third 4 :range} != "1 2 3 4"
18.  error
19.endif
20
21# The :range modifier takes the number of words from the value of the
22# variable expression.  If that expression is undefined, the range is
23# undefined as well.  This should not come as a surprise.
24.if "${:range}" != ""
25.  error
26.endif
27
28# The :range modifier can be given a parameter, which makes the generated
29# range independent from the value or the name of the variable expression.
30#
31# XXX: As of 2020-09-27, the :range=... modifier does not turn the undefined
32# expression into a defined one.  This looks like an oversight.
33.if "${:range=5}" != ""
34.  error
35.endif
36
37# Negative ranges don't make sense.
38# As of 2020-11-01, they are accepted though, using up all available memory.
39#.if "${:range=-1}"
40#.  error
41#.else
42#.  error
43#.endif
44
45# The :range modifier requires a number as parameter.
46#
47# Until 2020-11-01, the parser tried to read the 'x' as a number, failed and
48# stopped there.  It then tried to parse the next modifier at that point,
49# which failed with the message "Unknown modifier".
50#
51# Since 2020-11-01, the parser issues a more precise "Invalid number" error
52# instead.
53.if "${:U:range=x}Rest" != "Rest"
54.  error
55.else
56.  error
57.endif
58
59# The upper limit of the range must always be given in decimal.
60# This parse error stops at the 'x', trying to parse it as a variable
61# modifier.
62.if "${:U:range=0x0}Rest" != "Rest"
63.  error
64.else
65.  error
66.endif
67
68# As of 2020-11-01, numeric overflow is not detected.
69# Since strtoul returns ULONG_MAX in such a case, it is interpreted as a
70# very large number, consuming all available memory.
71#.if "${:U:range=18446744073709551619}Rest" != "Rest"
72#.  error
73#.else
74#.  error
75#.endif
76
77# modifier name too short
78.if "${a b c:L:rang}Rest" != "Rest"
79.  error
80.else
81.  error
82.endif
83
84# misspelled modifier name
85.if "${a b c:L:rango}Rest" != "Rest"
86.  error
87.else
88.  error
89.endif
90
91# modifier name too long
92.if "${a b c:L:ranger}Rest" != "Rest"
93.  error
94.else
95.  error
96.endif
97
98all:
99