1# $NetBSD: varmod-range.mk,v 1.8 2023/06/01 20:56:35 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# expect+2: Invalid number "x}Rest" != "Rest"" for ':range' modifier
54# expect+1: Malformed conditional ("${:U:range=x}Rest" != "Rest")
55.if "${:U:range=x}Rest" != "Rest"
56.  error
57.else
58.  error
59.endif
60
61# The upper limit of the range must always be given in decimal.
62# This parse error stops at the 'x', trying to parse it as a variable
63# modifier.
64# expect+2: Unknown modifier "x0"
65# expect+1: Malformed conditional ("${:U:range=0x0}Rest" != "Rest")
66.if "${:U:range=0x0}Rest" != "Rest"
67.  error
68.else
69.  error
70.endif
71
72# As of 2020-11-01, numeric overflow is not detected.
73# Since strtoul returns ULONG_MAX in such a case, it is interpreted as a
74# very large number, consuming all available memory.
75#.if "${:U:range=18446744073709551619}Rest" != "Rest"
76#.  error
77#.else
78#.  error
79#.endif
80
81# modifier name too short
82# expect+2: Unknown modifier "rang"
83# expect+1: Malformed conditional ("${a b c:L:rang}Rest" != "Rest")
84.if "${a b c:L:rang}Rest" != "Rest"
85.  error
86.else
87.  error
88.endif
89
90# misspelled modifier name
91# expect+2: Unknown modifier "rango"
92# expect+1: Malformed conditional ("${a b c:L:rango}Rest" != "Rest")
93.if "${a b c:L:rango}Rest" != "Rest"
94.  error
95.else
96.  error
97.endif
98
99# modifier name too long
100# expect+2: Unknown modifier "ranger"
101# expect+1: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest")
102.if "${a b c:L:ranger}Rest" != "Rest"
103.  error
104.else
105.  error
106.endif
107
108all:
109