5117f0886ead380fccec4bbb97a8e9d136013606
[pspp] / tests / language / control / define.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([DEFINE])
18
19 m4_define([PSPP_CHECK_MACRO_EXPANSION],
20   [AT_SETUP([macro expansion - $1])
21    AT_DATA([define.sps], [$2
22 DEBUG EXPAND.
23 $3
24 ])
25    AT_DATA([expout], [$4
26 ])
27    AT_CHECK([pspp --testing-mode define.sps | sed '/^$/d'], [$6], [expout])
28    AT_CLEANUP])
29
30 AT_SETUP([simple macro expansion])
31 AT_DATA([define.sps], [dnl
32 DEFINE !macro()
33 a b c d
34 e f g h.
35 i j k l
36 1,2,3,4.
37 5+6+7.
38 m(n,o).
39 "a" "b" "c" 'a' 'b' 'c'.
40 "x "" y".
41 !ENDDEFINE.
42 DEBUG EXPAND.
43 !macro
44 ])
45 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
46 a b c d e f g h.
47 i j k l 1, 2, 3, 4.
48 5 + 6 + 7.
49 m(n, o).
50 "a" "b" "c" 'a' 'b' 'c'.
51 "x "" y".
52 ])
53 AT_CLEANUP
54 \f
55 PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) positional argument],
56   [DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.],
57   [!t1 a.
58 !t1 b.
59 !t1 a b.],
60   [t1(a)
61 t1(b)
62 t1(a)
63 note: unexpanded token "b"])
64 \f
65 AT_SETUP([macro expansion with positional arguments])
66 AT_DATA([define.sps], [dnl
67 DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
68 DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.
69 DEFINE !t2(!positional !tokens(2)) t2 (!1) !ENDDEFINE.
70
71 DEFINE !ce(!positional !charend('/')) ce (!1) !ENDDEFINE.
72 DEFINE !ce2(!positional !charend('(')
73            /!positional !charend(')'))
74 ce2 (!1, !2)
75 !ENDDEFINE.
76
77 DEFINE !e(!positional !enclose('{','}')) e (!1) !ENDDEFINE.
78
79 DEFINE !cmd(!positional !cmdend) cmd(!1) !ENDDEFINE.
80 DEFINE !cmd2(!positional !cmdend
81             /!positional !tokens(1))
82 cmd2(!1, !2)
83 !ENDDEFINE.
84
85 DEFINE !p(!positional !tokens(1)
86          /!positional !tokens(1)
87          /!positional !tokens(1))
88 p(!1, !2, !3)
89 !ENDDEFINE.
90
91 DEBUG EXPAND.
92 !title "!TOKENS(1) argument."
93 !t1 a.
94 !t1 b.
95 !t1 a b.
96
97 !title "!TOKENS(2) argument."
98 !t2 a b.
99 !t2 b c d.
100
101 !title "!CHAREND argument."
102 !ce/.
103 !ce x/.
104 !ce x y/.
105 !ce x y z/.
106
107 !title "Two !CHAREND arguments."
108 !ce2 x(y).
109 !ce2 1 2 3 4().
110
111 !title "!ENCLOSE argument."
112 !e {}.
113 !e {a}.
114 !e {a b}.
115
116 !title "!CMDEND argument."
117 !cmd 1 2 3 4.
118 !cmd2 5 6.
119 7.
120
121 !title "Three !TOKENS(1) arguments."
122 !p a b c.
123 !p 1 -2 -3.
124 ])
125 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
126 "!TOKENS(1) argument."
127
128 t1(a)
129
130 t1(b)
131
132 t1(a)
133
134 note: unexpanded token "b"
135
136 "!TOKENS(2) argument."
137
138 t2(a b)
139
140 t2(b c)
141
142 note: unexpanded token "d"
143
144 "!CHAREND argument."
145
146 ce( )
147
148 ce(x)
149
150 ce(x y)
151
152 ce(x y z)
153
154 "Two !CHAREND arguments."
155
156 ce2(x, y)
157
158 ce2(1 2 3 4, )
159
160 "!ENCLOSE argument."
161
162 e( )
163
164 e(a)
165
166 e(a b)
167
168 "!CMDEND argument."
169
170 cmd(1 2 3 4)
171
172 cmd2(5 6, 7)
173
174 "Three !TOKENS(1) arguments."
175
176 p(a, b, c)
177
178 p(1, -2, -3)
179 ])
180 AT_CLEANUP
181 \f
182 AT_SETUP([macro expansion with positional arguments - negative])
183 AT_DATA([define.sps], [dnl
184 DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
185 DEFINE !p(!positional !tokens(1)
186          /!positional !tokens(1)
187          /!positional !tokens(1))
188 (!1, !2, !3)
189 !ENDDEFINE.
190
191 DEFINE !ce(!positional !charend('/')) ce(!1) !ENDDEFINE.
192
193 DEFINE !enc1(!positional !enclose('{', '}')) enc1(!1) !ENDDEFINE.
194 DEBUG EXPAND.
195 !title "Too few tokens for !TOKENS."
196 !p a b.
197 !p a.
198 !p.
199
200 !title "Missing charend delimiter."
201 !ce a b c.
202
203 !title "Missing start delimiter."
204 !enc1 a b c.
205
206 !title "Missing end delimiter."
207 !enc1{a b c.
208 ])
209 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
210 "Too few tokens for !TOKENS."
211
212 define.sps:13: error: DEBUG EXPAND: Unexpected end of command reading
213 argument !3 to macro !p.
214
215 note: unexpanded token "!p"
216
217 note: unexpanded token "a"
218
219 note: unexpanded token "b"
220
221 define.sps:14: error: DEBUG EXPAND: Unexpected end of command reading
222 argument !2 to macro !p.
223
224 note: unexpanded token "!p"
225
226 note: unexpanded token "a"
227
228 define.sps:15: error: DEBUG EXPAND: Unexpected end of command reading
229 argument !1 to macro !p.
230
231 note: unexpanded token "!p"
232
233 "Missing charend delimiter."
234
235 define.sps:18: error: DEBUG EXPAND: Unexpected end of command reading
236 argument !1 to macro !ce.
237
238 note: unexpanded token "!ce"
239
240 note: unexpanded token "a"
241
242 note: unexpanded token "b"
243
244 note: unexpanded token "c"
245
246 "Missing start delimiter."
247
248 define.sps:21: error: DEBUG EXPAND: Found `a' while expecting `{' reading
249 argument !1 to macro !enc1.
250
251 note: unexpanded token "!enc1"
252
253 note: unexpanded token "a"
254
255 note: unexpanded token "b"
256
257 note: unexpanded token "c"
258
259 "Missing end delimiter."
260
261 define.sps:24: error: DEBUG EXPAND: Unexpected end of command reading
262 argument !1 to macro !enc1.
263
264 note: unexpanded token "!enc1"
265
266 note: unexpanded token "{"
267
268 note: unexpanded token "a"
269
270 note: unexpanded token "b"
271
272 note: unexpanded token "c"
273 ])
274 AT_CLEANUP
275
276 PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) keyword argument],
277   [DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.],
278   [!k arg1=x.
279 !k arg1=x y.
280 !k.],
281   [k(x)
282 k(x)
283 note: unexpanded token "y"
284 k( )])
285
286 PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) keyword argument - negative],
287   [DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.],
288   [!k arg1.
289 !k arg1=.], [dnl
290 define.sps:3: error: DEBUG EXPAND: Found `.' while expecting `=' reading
291 argument !arg1 to macro !k.
292 note: unexpanded token "!k"
293 note: unexpanded token "arg1"
294 define.sps:4: error: DEBUG EXPAND: Unexpected end of command reading argument !
295 arg1 to macro !k.
296 note: unexpanded token "!k"
297 note: unexpanded token "arg1"
298 note: unexpanded token "="], [1])
299
300 PSPP_CHECK_MACRO_EXPANSION([!CHAREND('/') keyword arguments], [dnl
301 DEFINE !k(arg1 = !CHAREND('/')
302          /arg2 = !CHAREND('/'))
303 k(!arg1, !arg2)
304 !ENDDEFINE.],
305   [!k arg1=x/ arg2=y/.
306 !k arg1=x/.
307 !k arg2=y/.
308 !k.],
309   [k(x, y)
310 k(x, )
311 k(, y)
312 k(, )])
313
314 PSPP_CHECK_MACRO_EXPANSION([!CHAREND('/') keyword arguments - negative], [dnl
315 DEFINE !k(arg1 = !CHAREND('/')
316          /arg2 = !CHAREND('/'))
317 k(!arg1, !arg2)
318 !ENDDEFINE.],
319   [!k arg1.
320 !k arg1=.
321 !k arg1=x.
322 !k arg1=x/ arg2=y.],
323   [define.sps:6: error: DEBUG EXPAND: Found `.' while expecting `=' reading
324 argument !arg1 to macro !k.
325 note: unexpanded token "!k"
326 note: unexpanded token "arg1"
327 define.sps:7: error: DEBUG EXPAND: Unexpected end of command reading argument !
328 arg1 to macro !k.
329 note: unexpanded token "!k"
330 note: unexpanded token "arg1"
331 note: unexpanded token "="
332 define.sps:8: error: DEBUG EXPAND: Unexpected end of command reading argument !
333 arg1 to macro !k.
334 note: unexpanded token "!k"
335 note: unexpanded token "arg1"
336 note: unexpanded token "="
337 note: unexpanded token "x"
338 define.sps:9: error: DEBUG EXPAND: Unexpected end of command reading argument !
339 arg2 to macro !k.
340 note: unexpanded token "!k"
341 note: unexpanded token "arg1"
342 note: unexpanded token "="
343 note: unexpanded token "x"
344 note: unexpanded token "/"
345 note: unexpanded token "arg2"
346 note: unexpanded token "="
347 note: unexpanded token "y"])