0d4ef96b8240841c5832d902a5b8d6d6c0766ce1
[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_KEYWORDS([m4_bpatsubst([$1], [!], [])])
22    AT_DATA([define.sps], [$2
23 DEBUG EXPAND.
24 $3
25 ])
26    AT_CAPTURE_FILE([define.sps])
27    AT_DATA([expout], [$4
28 ])
29    AT_CHECK([pspp --testing-mode define.sps | sed '/^$/d'], [$6], [expout])
30    AT_CLEANUP])
31
32 AT_SETUP([simple macro expansion])
33 AT_DATA([define.sps], [dnl
34 DEFINE !macro()
35 a b c d
36 e f g h.
37 i j k l
38 1,2,3,4.
39 5+6+7.
40 m(n,o).
41 "a" "b" "c" 'a' 'b' 'c'.
42 "x "" y".
43 !ENDDEFINE.
44 DEBUG EXPAND.
45 !macro
46 ])
47 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
48 a b c d e f g h.
49 i j k l 1, 2, 3, 4.
50 5 + 6 + 7.
51 m(n, o).
52 "a" "b" "c" 'a' 'b' 'c'.
53 "x "" y".
54 ])
55 AT_CLEANUP
56 \f
57 PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) positional argument],
58   [DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.],
59   [!t1 a.
60 !t1 b.
61 !t1 a b.],
62   [t1(a)
63 t1(b)
64 t1(a)
65 note: unexpanded token "b"])
66 \f
67 AT_SETUP([macro expansion with positional arguments])
68 AT_DATA([define.sps], [dnl
69 DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
70 DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.
71 DEFINE !t2(!positional !tokens(2)) t2 (!1) !ENDDEFINE.
72
73 DEFINE !ce(!positional !charend('/')) ce (!1) !ENDDEFINE.
74 DEFINE !ce2(!positional !charend('(')
75            /!positional !charend(')'))
76 ce2 (!1, !2)
77 !ENDDEFINE.
78
79 DEFINE !e(!positional !enclose('{','}')) e (!1) !ENDDEFINE.
80
81 DEFINE !cmd(!positional !cmdend) cmd(!1) !ENDDEFINE.
82 DEFINE !cmd2(!positional !cmdend
83             /!positional !tokens(1))
84 cmd2(!1, !2)
85 !ENDDEFINE.
86
87 DEFINE !p(!positional !tokens(1)
88          /!positional !tokens(1)
89          /!positional !tokens(1))
90 p(!1, !2, !3)
91 !ENDDEFINE.
92
93 DEBUG EXPAND.
94 !title "!TOKENS(1) argument."
95 !t1 a.
96 !t1 b.
97 !t1 a b.
98
99 !title "!TOKENS(2) argument."
100 !t2 a b.
101 !t2 b c d.
102
103 !title "!CHAREND argument."
104 !ce/.
105 !ce x/.
106 !ce x y/.
107 !ce x y z/.
108
109 !title "Two !CHAREND arguments."
110 !ce2 x(y).
111 !ce2 1 2 3 4().
112
113 !title "!ENCLOSE argument."
114 !e {}.
115 !e {a}.
116 !e {a b}.
117
118 !title "!CMDEND argument."
119 !cmd 1 2 3 4.
120 !cmd2 5 6.
121 7.
122
123 !title "Three !TOKENS(1) arguments."
124 !p a b c.
125 !p 1 -2 -3.
126 ])
127 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
128 "!TOKENS(1) argument."
129
130 t1(a)
131
132 t1(b)
133
134 t1(a)
135
136 note: unexpanded token "b"
137
138 "!TOKENS(2) argument."
139
140 t2(a b)
141
142 t2(b c)
143
144 note: unexpanded token "d"
145
146 "!CHAREND argument."
147
148 ce( )
149
150 ce(x)
151
152 ce(x y)
153
154 ce(x y z)
155
156 "Two !CHAREND arguments."
157
158 ce2(x, y)
159
160 ce2(1 2 3 4, )
161
162 "!ENCLOSE argument."
163
164 e( )
165
166 e(a)
167
168 e(a b)
169
170 "!CMDEND argument."
171
172 cmd(1 2 3 4)
173
174 cmd2(5 6, 7)
175
176 "Three !TOKENS(1) arguments."
177
178 p(a, b, c)
179
180 p(1, -2, -3)
181 ])
182 AT_CLEANUP
183 \f
184 AT_SETUP([macro expansion with positional arguments - negative])
185 AT_DATA([define.sps], [dnl
186 DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
187 DEFINE !p(!positional !tokens(1)
188          /!positional !tokens(1)
189          /!positional !tokens(1))
190 (!1, !2, !3)
191 !ENDDEFINE.
192
193 DEFINE !ce(!positional !charend('/')) ce(!1) !ENDDEFINE.
194
195 DEFINE !enc1(!positional !enclose('{', '}')) enc1(!1) !ENDDEFINE.
196 DEBUG EXPAND.
197 !title "Too few tokens for !TOKENS."
198 !p a b.
199 !p a.
200 !p.
201
202 !title "Missing charend delimiter."
203 !ce a b c.
204
205 !title "Missing start delimiter."
206 !enc1 a b c.
207
208 !title "Missing end delimiter."
209 !enc1{a b c.
210 ])
211 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
212 "Too few tokens for !TOKENS."
213
214 define.sps:13: error: DEBUG EXPAND: Unexpected end of command reading
215 argument !3 to macro !p.
216
217 note: unexpanded token "!p"
218
219 note: unexpanded token "a"
220
221 note: unexpanded token "b"
222
223 define.sps:14: error: DEBUG EXPAND: Unexpected end of command reading
224 argument !2 to macro !p.
225
226 note: unexpanded token "!p"
227
228 note: unexpanded token "a"
229
230 define.sps:15: error: DEBUG EXPAND: Unexpected end of command reading
231 argument !1 to macro !p.
232
233 note: unexpanded token "!p"
234
235 "Missing charend delimiter."
236
237 define.sps:18: error: DEBUG EXPAND: Unexpected end of command reading
238 argument !1 to macro !ce.
239
240 note: unexpanded token "!ce"
241
242 note: unexpanded token "a"
243
244 note: unexpanded token "b"
245
246 note: unexpanded token "c"
247
248 "Missing start delimiter."
249
250 define.sps:21: error: DEBUG EXPAND: Found `a' while expecting `{' reading
251 argument !1 to macro !enc1.
252
253 note: unexpanded token "!enc1"
254
255 note: unexpanded token "a"
256
257 note: unexpanded token "b"
258
259 note: unexpanded token "c"
260
261 "Missing end delimiter."
262
263 define.sps:24: error: DEBUG EXPAND: Unexpected end of command reading
264 argument !1 to macro !enc1.
265
266 note: unexpanded token "!enc1"
267
268 note: unexpanded token "{"
269
270 note: unexpanded token "a"
271
272 note: unexpanded token "b"
273
274 note: unexpanded token "c"
275 ])
276 AT_CLEANUP
277
278 PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) keyword argument],
279   [DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.],
280   [!k arg1=x.
281 !k arg1=x y.
282 !k.],
283   [k(x)
284 k(x)
285 note: unexpanded token "y"
286 k( )])
287
288 PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) keyword argument - negative],
289   [DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.],
290   [!k arg1.
291 !k arg1=.], [dnl
292 define.sps:3: error: DEBUG EXPAND: Found `.' while expecting `=' reading
293 argument !arg1 to macro !k.
294 note: unexpanded token "!k"
295 note: unexpanded token "arg1"
296 define.sps:4: error: DEBUG EXPAND: Unexpected end of command reading argument !
297 arg1 to macro !k.
298 note: unexpanded token "!k"
299 note: unexpanded token "arg1"
300 note: unexpanded token "="], [1])
301
302 PSPP_CHECK_MACRO_EXPANSION([!CHAREND('/') keyword arguments], [dnl
303 DEFINE !k(arg1 = !CHAREND('/')
304          /arg2 = !CHAREND('/'))
305 k(!arg1, !arg2)
306 !ENDDEFINE.],
307   [!k arg1=x/ arg2=y/.
308 !k arg1=x/.
309 !k arg2=y/.
310 !k.],
311   [k(x, y)
312 k(x, )
313 k(, y)
314 k(, )])
315
316 PSPP_CHECK_MACRO_EXPANSION([!CHAREND('/') keyword arguments - negative], [dnl
317 DEFINE !k(arg1 = !CHAREND('/')
318          /arg2 = !CHAREND('/'))
319 k(!arg1, !arg2)
320 !ENDDEFINE.],
321   [!k arg1.
322 !k arg1=.
323 !k arg1=x.
324 !k arg1=x/ arg2=y.],
325   [define.sps:6: error: DEBUG EXPAND: Found `.' while expecting `=' reading
326 argument !arg1 to macro !k.
327 note: unexpanded token "!k"
328 note: unexpanded token "arg1"
329 define.sps:7: error: DEBUG EXPAND: Unexpected end of command reading argument !
330 arg1 to macro !k.
331 note: unexpanded token "!k"
332 note: unexpanded token "arg1"
333 note: unexpanded token "="
334 define.sps:8: error: DEBUG EXPAND: Unexpected end of command reading argument !
335 arg1 to macro !k.
336 note: unexpanded token "!k"
337 note: unexpanded token "arg1"
338 note: unexpanded token "="
339 note: unexpanded token "x"
340 define.sps:9: error: DEBUG EXPAND: Unexpected end of command reading argument !
341 arg2 to macro !k.
342 note: unexpanded token "!k"
343 note: unexpanded token "arg1"
344 note: unexpanded token "="
345 note: unexpanded token "x"
346 note: unexpanded token "/"
347 note: unexpanded token "arg2"
348 note: unexpanded token "="
349 note: unexpanded token "y"])
350
351 PSPP_CHECK_MACRO_EXPANSION([default keyword arguments],
352   [DEFINE !k(arg1 = !DEFAULT(a b c) !CMDEND) k(!arg1) !ENDDEFINE],
353   [!k arg1=x.
354 !k],
355   [k(x)
356 k(a b c)])
357
358 dnl Keep this test in sync with the examples for !BLANKS in the manual.
359 PSPP_CHECK_MACRO_EXPANSION([!BLANKS],
360   [DEFINE !b()
361 !BLANKS(0).
362 !QUOTE(!BLANKS(0)).
363 !BLANKS(1).
364 !QUOTE(!BLANKS(1)).
365 !BLANKS(2).
366 !QUOTE(!BLANKS(2)).
367 !BLANKS(5).
368 !QUOTE(!BLANKS(5)).
369 !ENDDEFINE],
370   [!b.],
371   [.
372 ''.
373 .
374 ' '.
375 .
376 '  '.
377 .
378 '     '.])
379
380 dnl Keep this test in sync with the examples for !CONCAT in the manual.
381 PSPP_CHECK_MACRO_EXPANSION([!CONCAT],
382   [DEFINE !c()
383 !CONCAT(x, y).
384 !CONCAT('x', 'y').
385 !CONCAT(12, 34).
386 !CONCAT(!NULL, 123).
387 !ENDDEFINE],
388   [!c.],
389   [xy.
390 xy.
391 1234.
392 123.])
393
394 dnl