204ed2efd37f1b183f263923b530777a9dfe1436
[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 nGeneral 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 AT_SETUP([simple macro expansion])
20 AT_DATA([define.sps], [dnl
21 DEFINE !macro()
22 a b c d
23 e f g h.
24 i j k l
25 1,2,3,4.
26 5+6+7.
27 m(n,o).
28 "a" "b" "c" 'a' 'b' 'c'.
29 "x "" y".
30 !ENDDEFINE.
31 DEBUG EXPAND.
32 !macro
33 ])
34 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
35 a b c d e f g h.
36 i j k l 1, 2, 3, 4.
37 5 + 6 + 7.
38 m(n, o).
39 "a" "b" "c" 'a' 'b' 'c'.
40 "x "" y".
41 ])
42 AT_CLEANUP
43
44 AT_SETUP([macro expansion - one !TOKENS(1) positional argument])
45 AT_KEYWORDS([TOKENS])
46 AT_DATA([define.sps], [dnl
47 DEFINE !t1(!positional=!tokens(1)) t1 (!1) !ENDDEFINE.
48 DEBUG EXPAND.
49 !t1 a.
50 !t1 b.
51 !t1 a b.
52 ])
53 AT_CAPTURE_FILE([define.sps])
54 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
55 t1(a)
56
57 t1(b)
58
59 t1(a)
60
61 note: unexpanded token "b"
62 ])
63 AT_CLEANUP
64
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, )
173
174 note: unexpanded token "7"
175
176 "Three !TOKENS(1) arguments."
177
178 p(a, b, c) (a b c)
179
180 p(1, -2, -3) (1 -2 -3)
181 ])
182 AT_CLEANUP
183
184 AT_SETUP([macro call missing positional !TOKENS arguments])
185 AT_KEYWORDS([TOKENS])
186 AT_DATA([define.sps], [dnl
187 DEFINE !p(!positional !tokens(1) !default(x)
188          /!positional !tokens(1) !default(y)
189          /!positional !tokens(1) !default(z))
190 (!1, !2, !3)
191 !ENDDEFINE.
192 DEBUG EXPAND.
193 !p a b c.
194 !p a b.
195 !p a.
196 !p.
197 ])
198 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
199 (a, b, c)
200
201 (a, b, z)
202
203 (a, y, z)
204
205 (x, y, z)
206 ])
207 AT_CLEANUP
208
209 AT_SETUP([macro call incomplete positional !TOKENS arguments])
210 AT_KEYWORDS([TOKENS])
211 AT_DATA([define.sps], [dnl
212 DEFINE !p(!positional !tokens(2) !default(x)
213          /!positional !tokens(2) !default(y)
214          /!positional !tokens(2) !default(z))
215 (!1, !2, !3)
216 !ENDDEFINE.
217 DEBUG EXPAND.
218 !p a1 a2 b1 b2 c1 c2.
219 !p a1 a2 b1 b2 c1.
220 !p a1 a2 b1 b2.
221 !p a1 a2 b1.
222 !p a1 a2.
223 !p a1.
224 !p.
225 ])
226 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
227 (a1 a2, b1 b2, c1 c2)
228
229 define.sps:8.18: error: DEBUG EXPAND: Reached end of command expecting 1 more
230 token in argument !3 to macro !p.
231
232 (a1 a2, b1 b2, c1)
233
234 (a1 a2, b1 b2, z)
235
236 define.sps:10.12: error: DEBUG EXPAND: Reached end of command expecting 1 more
237 token in argument !2 to macro !p.
238
239 (a1 a2, b1, z)
240
241 (a1 a2, y, z)
242
243 define.sps:12.6: error: DEBUG EXPAND: Reached end of command expecting 1 more
244 token in argument !1 to macro !p.
245
246 (a1, y, z)
247
248 (x, y, z)
249 ])
250 AT_CLEANUP
251
252 AT_SETUP([macro call empty positional !CHAREND arguments])
253 AT_KEYWORDS([CHAREND])
254 AT_DATA([define.sps], [dnl
255 DEFINE !p(!positional !charend(',') !default(x)
256          /!positional !charend(';') !default(y)
257          /!positional !charend(':') !default(z))
258 (!1, !2, !3)
259 !ENDDEFINE.
260 DEBUG EXPAND.
261 !p a,b;c:.
262 !p a,b;:.
263 !p a,;c:.
264 !p a,;:.
265 !p,b;c:.
266 !p,b;:.
267 !p,;c:.
268 !p,;:.
269 ])
270 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
271 (a, b, c)
272
273 (a, b, )
274
275 (a, , c)
276
277 (a, , )
278
279 (, b, c)
280
281 (, b, )
282
283 (, , c)
284
285 (, , )
286 ])
287 AT_CLEANUP
288
289 AT_SETUP([macro call missing positional !CHAREND arguments])
290 AT_DATA([define.sps], [dnl
291 DEFINE !p(!positional !charend(',') !default(x)
292          /!positional !charend(';') !default(y)
293          /!positional !charend(':') !default(z))
294 (!1, !2, !3)
295 !ENDDEFINE.
296 DEBUG EXPAND.
297 !p a,b;c:.
298 !p a,b;.
299 !p a,;.
300 !p ,b;.
301 !p ,;.
302
303 !p a,.
304 !p ,.
305
306 !p.
307 ])
308 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
309 (a, b, c)
310
311 (a, b, z)
312
313 (a, , z)
314
315 (, b, z)
316
317 (, , z)
318
319 (a, y, z)
320
321 (, y, z)
322
323 (x, y, z)
324 ])
325 AT_CLEANUP
326
327 AT_SETUP([macro call incomplete positional !CHAREND arguments])
328 AT_KEYWORDS([CHAREND])
329 AT_DATA([define.sps], [dnl
330 DEFINE !p(!positional !charend(',') !default(x)
331          /!positional !charend(';') !default(y)
332          /!positional !charend(':') !default(z))
333 (!1, !2, !3)
334 !ENDDEFINE.
335 DEBUG EXPAND.
336 !p a,b;c:.
337 !p a,b;c.
338 !p a,b;.
339 !p a,b.
340 !p a,.
341 !p a.
342 !p.
343 ])
344 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
345 (a, b, c)
346
347 define.sps:8.9: error: DEBUG EXPAND: Reached end of command expecting ":" in
348 argument !3 to macro !p.
349
350 (a, b, c)
351
352 (a, b, z)
353
354 define.sps:10.7: error: DEBUG EXPAND: Reached end of command expecting ";" in
355 argument !2 to macro !p.
356
357 (a, b, z)
358
359 (a, y, z)
360
361 define.sps:12.5: error: DEBUG EXPAND: Reached end of command expecting "," in
362 argument !1 to macro !p.
363
364 (a, y, z)
365
366 (x, y, z)
367 ])
368 AT_CLEANUP
369
370 AT_SETUP([macro call missing positional !ENCLOSE arguments])
371 AT_KEYWORDS([ENCLOSE])
372 AT_DATA([define.sps], [dnl
373 DEFINE !p(!positional !enclose('(',')') !default(x)
374          /!positional !enclose('<','>') !default(y)
375          /!positional !enclose('{','}') !default(z))
376 (!1, !2, !3)
377 !ENDDEFINE.
378 DEBUG EXPAND.
379 !p (a)<b>{c}.
380 !p (a)<b>.
381 !p (a).
382 !p.
383 ])
384 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
385 (a, b, c)
386
387 (a, b, z)
388
389 (a, y, z)
390
391 (x, y, z)
392 ])
393 AT_CLEANUP
394
395 AT_SETUP([macro call incomplete positional !ENCLOSE arguments])
396 AT_KEYWORDS([ENCLOSE])
397 AT_DATA([define.sps], [dnl
398 DEFINE !p(!positional !enclose('(',')') !default(x)
399          /!positional !enclose('<','>') !default(y)
400          /!positional !enclose('{','}') !default(z))
401 (!1, !2, !3)
402 !ENDDEFINE.
403 DEBUG EXPAND.
404 !p (a)<b>{c}.
405 !p (a)<b>{c.
406 !p (a)<b>{.
407 !p (a)<b>.
408 !p (a)<b.
409 !p (a)<.
410 !p (a).
411 !p (a.
412 !p (.
413 !p.
414 ])
415 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
416 (a, b, c)
417
418 define.sps:8.12: error: DEBUG EXPAND: Reached end of command expecting "}" in
419 argument !3 to macro !p.
420
421 (a, b, c)
422
423 define.sps:9.11: error: DEBUG EXPAND: Reached end of command expecting "}" in
424 argument !3 to macro !p.
425
426 (a, b, )
427
428 (a, b, z)
429
430 define.sps:11.9: error: DEBUG EXPAND: Reached end of command expecting ">" in
431 argument !2 to macro !p.
432
433 (a, b, z)
434
435 define.sps:12.8: error: DEBUG EXPAND: Reached end of command expecting ">" in
436 argument !2 to macro !p.
437
438 (a, , z)
439
440 (a, y, z)
441
442 define.sps:14.6: error: DEBUG EXPAND: Reached end of command expecting ")" in
443 argument !1 to macro !p.
444
445 (a, y, z)
446
447 define.sps:15.5: error: DEBUG EXPAND: Reached end of command expecting ")" in
448 argument !1 to macro !p.
449
450 (, y, z)
451
452 (x, y, z)
453 ])
454 AT_CLEANUP
455
456 AT_SETUP([keyword macro argument name with ! prefix])
457 AT_DATA([define.sps], [dnl
458 DEFINE !macro(!x !TOKENS(1).
459 ])
460 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
461 "define.sps:1.15-1.16: error: DEFINE: Syntax error at `!x': Keyword macro parameter must be named in definition without ""!"" prefix."
462 ])
463 AT_CLEANUP
464
465 AT_SETUP([reserved macro keyword argument name])
466 AT_DATA([define.sps], [dnl
467 DEFINE !macro(if=!TOKENS(1).
468 ])
469 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
470 "define.sps:1.15-1.16: error: DEFINE: Syntax error at `if': Cannot use macro keyword ""if"" as an argument name."
471 ])
472 AT_CLEANUP
473
474 AT_SETUP([macro expansion - one !TOKENS(1) keyword argument])
475 AT_KEYWORDS([TOKENS])
476 AT_DATA([define.sps], [dnl
477 DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.
478 DEBUG EXPAND.
479 !k arg1=x.
480 !k arg1=x y.
481 !k.
482 ])
483 AT_CAPTURE_FILE([define.sps])
484 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
485 k(x)
486
487 k(x)
488
489 note: unexpanded token "y"
490
491 k( )
492 ])
493 AT_CLEANUP
494
495 AT_SETUP([macro expansion - one !TOKENS(1) keyword argument - negative])
496 AT_KEYWORDS([TOKENS])
497 AT_DATA([define.sps], [dnl
498 DEFINE !k(arg1 !TOKENS(1)) k(!arg1) !ENDDEFINE.
499 DEBUG EXPAND.
500 !k arg1.
501 !k arg1=.
502 ])
503 AT_CAPTURE_FILE([define.sps])
504 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
505 define.sps:3.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
506 argument !arg1 to macro !k.
507
508 k( )
509
510 define.sps:4.9: error: DEBUG EXPAND: Reached end of command expecting 1 more
511 token in argument !arg1 to macro !k.
512
513 k( )
514 ])
515 AT_CLEANUP
516
517 AT_SETUP([macro expansion - !CHAREND keyword arguments])
518 AT_KEYWORDS([CHAREND])
519 AT_DATA([define.sps], [dnl
520 DEFINE !k(arg1 = !CHAREND('/')
521          /arg2 = !CHAREND('/'))
522 k(!arg1, !arg2)
523 !ENDDEFINE.
524 DEBUG EXPAND.
525 !k arg1=x/ arg2=y/.
526 !k arg1=x/.
527 !k arg2=y/.
528 !k.
529 ])
530 AT_CAPTURE_FILE([define.sps])
531 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
532 k(x, y)
533
534 k(x, )
535
536 k(, y)
537
538 k(, )
539 ])
540 AT_CLEANUP
541
542 AT_SETUP([macro expansion - !CHAREND keyword arguments - negative])
543 AT_KEYWORDS([CHAREND])
544 AT_DATA([define.sps], [dnl
545 DEFINE !k(arg1 = !CHAREND('/')
546          /arg2 = !CHAREND('/'))
547 k(!arg1, !arg2)
548 !ENDDEFINE.
549 DEBUG EXPAND.
550 !k arg1.
551 !k arg1=.
552 !k arg1=x.
553 !k arg1=x/ arg2=y.
554 ])
555 AT_CAPTURE_FILE([define.sps])
556 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
557 define.sps:6.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
558 argument !arg1 to macro !k.
559
560 k(, )
561
562 define.sps:7.9: error: DEBUG EXPAND: Reached end of command expecting "/" in
563 argument !arg1 to macro !k.
564
565 k(, )
566
567 define.sps:8.10: error: DEBUG EXPAND: Reached end of command expecting "/" in
568 argument !arg1 to macro !k.
569
570 k(x, )
571
572 define.sps:9.18: error: DEBUG EXPAND: Reached end of command expecting "/" in
573 argument !arg2 to macro !k.
574
575 k(x, y)
576 ])
577 AT_CLEANUP
578
579 AT_SETUP([macro expansion - !ENCLOSE keyword arguments])
580 AT_KEYWORDS([ENCLOSE])
581 AT_DATA([define.sps], [dnl
582 DEFINE !k(arg1 = !ENCLOSE('(',')')
583          /arg2 = !ENCLOSE('{','}'))
584 k(!arg1, !arg2)
585 !ENDDEFINE.
586 DEBUG EXPAND.
587 !k arg1=(x) arg2={y}.
588 !k arg1=(x).
589 !k arg2={y}.
590 !k.
591 ])
592 AT_CAPTURE_FILE([define.sps])
593 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
594 k(x, y)
595
596 k(x, )
597
598 k(, y)
599
600 k(, )
601 ])
602 AT_CLEANUP
603
604 AT_SETUP([macro expansion - !ENCLOSE keyword arguments - negative])
605 AT_KEYWORDS([ENCLOSE])
606 AT_DATA([define.sps], [dnl
607 DEFINE !k(arg1 = !ENCLOSE('(',')')
608          /arg2 = !ENCLOSE('{','}'))
609 k(!arg1, !arg2)
610 !ENDDEFINE.
611 DEBUG EXPAND.
612 !k arg1.
613 !k arg1=.
614 !k arg1=x.
615 !k arg1=(x.
616 !k arg1=(x) arg2.
617 !k arg1=(x) arg2=.
618 !k arg1=(x) arg2=y.
619 !k arg1=(x) arg2=(y.
620 ])
621 AT_CAPTURE_FILE([define.sps])
622 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
623 define.sps:6.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
624 argument !arg1 to macro !k.
625
626 k(, )
627
628 define.sps:7.9: error: DEBUG EXPAND: Found `.' while expecting `@{:@' reading
629 argument !arg1 to macro !k.
630
631 k(, )
632
633 define.sps:8.9: error: DEBUG EXPAND: Found `x' while expecting `@{:@' reading
634 argument !arg1 to macro !k.
635
636 k(, )
637
638 note: unexpanded token "x"
639
640 define.sps:9.11: error: DEBUG EXPAND: Reached end of command expecting "@:}@" in
641 argument !arg1 to macro !k.
642
643 k(x, )
644
645 define.sps:10.17: error: DEBUG EXPAND: Found `.' while expecting `=' reading
646 argument !arg2 to macro !k.
647
648 k(x, )
649
650 define.sps:11.18: error: DEBUG EXPAND: Found `.' while expecting `{' reading
651 argument !arg2 to macro !k.
652
653 k(x, )
654
655 define.sps:12.18: error: DEBUG EXPAND: Found `y' while expecting `{' reading
656 argument !arg2 to macro !k.
657
658 k(x, )
659
660 note: unexpanded token "y"
661
662 define.sps:13.18: error: DEBUG EXPAND: Found `@{:@' while expecting `{' reading
663 argument !arg2 to macro !k.
664
665 k(x, )
666
667 note: unexpanded token "@{:@"
668
669 note: unexpanded token "y"
670 ])
671 AT_CLEANUP
672
673 dnl Keep this test in sync with the examples for !BLANKS in the manual.
674 AT_SETUP([macro expansion - !BLANKS])
675 AT_KEYWORDS([BLANKS])
676 AT_DATA([define.sps], [dnl
677 DEFINE !b()
678 !BLANKS(0).
679 !QUOTE(!BLANKS(0)).
680 !BLANKS(1).
681 !QUOTE(!BLANKS(1)).
682 !BLANKS(2).
683 !QUOTE(!BLANKS(2)).
684 !BLANKS(5).
685 !QUOTE(!BLANKS(5)).
686 !ENDDEFINE.
687 DEBUG EXPAND.
688 !b.
689 ])
690 AT_CAPTURE_FILE([define.sps])
691 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
692 .
693 ''.
694 .
695 ' '.
696 .
697 '  '.
698 .
699 '     '.
700 ])
701 AT_CLEANUP
702
703 dnl Keep this test in sync with the examples for !CONCAT in the manual.
704 AT_SETUP([macro expansion - !CONCAT])
705 AT_KEYWORDS([CONCAT])
706 AT_DATA([define.sps], [dnl
707 DEFINE !c()
708 !CONCAT(x, y).
709 !CONCAT('x', 'y').
710 !CONCAT(12, 34).
711 !CONCAT(!NULL, 123).
712 !CONCAT(x, 0).
713 !CONCAT(x, 0, y).
714 !CONCAT(0, x).
715 !CONCAT(0, x, y).
716 !ENDDEFINE.
717 DEBUG EXPAND.
718 !c
719 ])
720 AT_CAPTURE_FILE([define.sps])
721 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
722 xy.
723 xy.
724 1234.
725 123.
726 x0.
727 x0y.
728 0 x.
729 0 xy.
730 ])
731 AT_CLEANUP
732
733 dnl Keep this test in sync with the examples for !EVAL in the manual.
734 AT_SETUP([macro expansion - !EVAL])
735 AT_KEYWORDS([EVAL])
736 AT_DATA([define.sps], [dnl
737 DEFINE !vars() a b c !ENDDEFINE.
738
739 DEFINE !e()
740 !vars.
741 !QUOTE(!vars).
742 !EVAL(!vars).
743 !QUOTE(!EVAL(!vars)).
744 !ENDDEFINE
745
746 DEFINE !e2(!positional !enclose('(',')'))
747 !1.
748 !QUOTE(!1).
749 !EVAL(!1).
750 !QUOTE(!EVAL(!1)).
751 !ENDDEFINE.
752 DEBUG EXPAND.
753 !e.
754 !e2(!vars).
755 ])
756 AT_CAPTURE_FILE([define.sps])
757 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
758 a b c.
759 '!vars'.
760 a b c.
761 'a b c'.
762
763 a b c.
764 '!vars'.
765 a b c.
766 'a b c'.
767 ])
768 AT_CLEANUP
769
770 dnl Keep this test in sync with the examples for !HEAD in the manual.
771 AT_SETUP([macro expansion - !HEAD])
772 AT_KEYWORDS([HEAD])
773 AT_DATA([define.sps], [dnl
774 DEFINE !h()
775 !HEAD('a b c').
776 !HEAD('a').
777 !HEAD(!NULL).
778 !HEAD('').
779 !ENDDEFINE.
780 DEBUG EXPAND.
781 !h.
782 ])
783 AT_CAPTURE_FILE([define.sps])
784 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
785 a.
786 a.
787 .
788 .
789 ])
790 AT_CLEANUP
791
792 dnl Keep this test in sync with the examples for !TAIL in the manual.
793 AT_SETUP([macro expansion - !TAIL])
794 AT_KEYWORDS([TAIL])
795 AT_DATA([define.sps], [dnl
796 DEFINE !t()
797 !TAIL('a b c').
798 !TAIL('a').
799 !TAIL(!NULL).
800 !TAIL('').
801 !ENDDEFINE.
802 DEBUG EXPAND.
803 !t.
804 ])
805 AT_CAPTURE_FILE([define.sps])
806 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
807 b c.
808 .
809 .
810 .
811 ])
812 AT_CLEANUP
813
814 dnl Keep this test in sync with the examples for !INDEX in the manual.
815 AT_SETUP([macro expansion - !INDEX])
816 AT_KEYWORDS([INDEX])
817 AT_DATA([define.sps], [dnl
818 DEFINE !i()
819 !INDEX(banana, an).
820 !INDEX(banana, nan).
821 !INDEX(banana, apple).
822 !INDEX("banana", nan).
823 !INDEX("banana", "nan").
824 !INDEX(!UNQUOTE("banana"), !UNQUOTE("nan")).
825 !ENDDEFINE.
826 DEBUG EXPAND.
827 !i.
828 ])
829 AT_CAPTURE_FILE([define.sps])
830 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
831 2.
832 3.
833 0.
834 4.
835 0.
836 3.
837 ])
838 AT_CLEANUP
839
840 dnl Keep this test in sync with the examples for !LENGTH in the manual.
841 AT_SETUP([macro expansion - !LENGTH])
842 AT_KEYWORDS([LENGTH])
843 AT_DATA([define.sps], [dnl
844 DEFINE !l()
845 !LENGTH(123).
846 !LENGTH(123.00).
847 !LENGTH( 123 ).
848 !LENGTH("123").
849 !LENGTH(xyzzy).
850 !LENGTH("xyzzy").
851 !LENGTH("xy""zzy").
852 !LENGTH(!UNQUOTE("xyzzy")).
853 !LENGTH(!UNQUOTE("xy""zzy")).
854 !LENGTH(!NULL).
855 !ENDDEFINE.
856 DEFINE !la(!positional !enclose('(',')'))
857 !LENGTH(!1).
858 !ENDDEFINE.
859 DEBUG EXPAND.
860 !l.
861 !la(a b c).
862 !la().
863 ])
864 AT_CAPTURE_FILE([define.sps])
865 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
866 3.
867 6.
868 3.
869 5.
870 5.
871 7.
872 9.
873 5.
874 6.
875 0.
876
877 5.
878
879 0.
880 ])
881 AT_CLEANUP
882
883 dnl Keep this test in sync with the examples for !NULL in the manual.
884 AT_SETUP([macro expansion - !NULL])
885 AT_KEYWORDS([NULL])
886 AT_DATA([define.sps], [dnl
887 DEFINE !n()
888 !NULL.
889 !QUOTE(!NULL).
890 !ENDDEFINE.
891 DEBUG EXPAND.
892 !n.
893 ])
894 AT_CAPTURE_FILE([define.sps])
895 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
896 .
897 ''.
898 ])
899 AT_CLEANUP
900
901 dnl Keep this test in sync with the examples for !QUOTE and !UNQUOTE in the manual.
902 AT_SETUP([macro expansion - !QUOTE and !UNQUOTE])
903 AT_KEYWORDS([QUOTE UNQUOTE])
904 AT_DATA([define.sps], [dnl
905 DEFINE !q(!POS !CMDEND)
906 !QUOTE(123.0).
907 !QUOTE( 123 ).
908 !QUOTE('a b c').
909 !QUOTE("a b c").
910 !QUOTE(!1).
911
912 !UNQUOTE(123.0).
913 !UNQUOTE( 123 ).
914 !UNQUOTE('a b c').
915 !UNQUOTE("a b c").
916 !UNQUOTE(!1).
917
918 !QUOTE(!UNQUOTE(123.0)).
919 !QUOTE(!UNQUOTE( 123 )).
920 !QUOTE(!UNQUOTE('a b c')).
921 !QUOTE(!UNQUOTE("a b c")).
922 !QUOTE(!UNQUOTE(!1)).
923 !ENDDEFINE.
924 DEBUG EXPAND.
925 !q a 'b' c.
926 ])
927 AT_CAPTURE_FILE([define.sps])
928 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
929 '123.0'.
930 '123'.
931 'a b c'.
932 "a b c".
933 'a ''b'' c'.
934
935 123.0.
936 123.
937 a b c.
938 a b c.
939 a 'b' c.
940
941 '123.0'.
942 '123'.
943 'a b c'.
944 'a b c'.
945 'a ''b'' c'.
946 ])
947 AT_CLEANUP
948
949 dnl Keep this test in sync with the examples for !SUBSTR in the manual.
950 AT_SETUP([macro expansion - !SUBSTR])
951 AT_KEYWORDS([SUBSTR])
952 AT_DATA([define.sps], [dnl
953 DEFINE !s()
954 !SUBSTR(banana, 3).
955 !SUBSTR(banana, 3, 3).
956 !SUBSTR("banana", 1, 3).
957 !SUBSTR(!UNQUOTE("banana"), 3).
958 !SUBSTR("banana", 3, 3).
959 !SUBSTR(banana, 3, 0).
960 !SUBSTR(banana, 3, 10).
961 !SUBSTR(banana, 10, 3).
962 !ENDDEFINE.
963 DEBUG EXPAND.
964 !s.
965 ])
966 AT_CAPTURE_FILE([define.sps])
967 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
968 define.sps:1-10: At `"ba' in the expansion of `!s',dnl "
969
970 define.sps:12.1-12.2: error: DEBUG EXPAND: Unterminated string constant.
971
972 nana.
973 nan.
974 .
975 nana.
976 ana.
977 .
978 nana.
979 .
980 ])
981 AT_CLEANUP
982
983 dnl Keep this test in sync with the examples for !UPCASE in the manual.
984 AT_SETUP([macro expansion - !UPCASE])
985 AT_KEYWORDS([UPCASE])
986 AT_DATA([define.sps], [dnl
987 DEFINE !u()
988 !UPCASE(freckle).
989 !UPCASE('freckle').
990 !UPCASE('a b c').
991 !UPCASE('A B C').
992 !ENDDEFINE.
993 DEBUG EXPAND.
994 !u.
995 ])
996 AT_CAPTURE_FILE([define.sps])
997 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
998 FRECKLE.
999 FRECKLE.
1000 A B C.
1001 A B C.
1002 ])
1003 AT_CLEANUP
1004
1005 dnl !* is implemented separately inside and outside function arguments
1006 dnl so this test makes sure to include both.
1007 AT_SETUP([macro expansion - !*])
1008 AT_DATA([define.sps], [dnl
1009 DEFINE !m(!POSITIONAL !TOKENS(1)
1010          /!POSITIONAL !TOKENS(1))
1011 !*/
1012 !LENGTH(!*)/
1013 !SUBSTR(!*, 3)/
1014 !QUOTE(!*).
1015 !ENDDEFINE.
1016 DEBUG EXPAND.
1017 !m 123 b
1018 !m 2 3
1019 !m '' 'b'.
1020 ])
1021 AT_CAPTURE_FILE([define.sps])
1022 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1023 123 b / 5 / 3 b / '123 b'.
1024
1025 2 3 / 3 / 3 / '2 3'.
1026
1027 '' 'b' / 6 / 'b' / ''''' ''b'''.
1028 ])
1029 AT_CLEANUP
1030
1031 AT_SETUP([macro maximum nesting level (MNEST)])
1032 AT_KEYWORDS([MNEST])
1033 AT_DATA([define.sps], [dnl
1034 DEFINE !macro()
1035 !macro
1036 !ENDDEFINE.
1037 !macro.
1038 ])
1039 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
1040 "define.sps:1-3: In the expansion of `!macro',
1041 define.sps:1-3: inside the expansion of `!macro',
1042 define.sps:1-3: inside the expansion of `!macro',
1043 define.sps:1-3: inside the expansion of `!macro',
1044 define.sps:1-3: inside the expansion of `!macro',
1045 define.sps:1-3: inside the expansion of `!macro',
1046 define.sps:1-3: inside the expansion of `!macro',
1047 define.sps:1-3: inside the expansion of `!macro',
1048 define.sps:1-3: inside the expansion of `!macro',
1049 define.sps:1-3: inside the expansion of `!macro',
1050 define.sps:1-3: inside the expansion of `!macro',
1051 define.sps:1-3: inside the expansion of `!macro',
1052 define.sps:1-3: inside the expansion of `!macro',
1053 define.sps:1-3: inside the expansion of `!macro',
1054 define.sps:1-3: inside the expansion of `!macro',
1055 define.sps:1-3: inside the expansion of `!macro',
1056 define.sps:1-3: inside the expansion of `!macro',
1057 define.sps:1-3: inside the expansion of `!macro',
1058 define.sps:1-3: inside the expansion of `!macro',
1059 define.sps:1-3: inside the expansion of `!macro',
1060 define.sps:1-3: inside the expansion of `!macro',
1061 define.sps:1-3: inside the expansion of `!macro',
1062 define.sps:1-3: inside the expansion of `!macro',
1063 define.sps:1-3: inside the expansion of `!macro',
1064 define.sps:1-3: inside the expansion of `!macro',
1065 define.sps:1-3: inside the expansion of `!macro',
1066 define.sps:1-3: inside the expansion of `!macro',
1067 define.sps:1-3: inside the expansion of `!macro',
1068 define.sps:1-3: inside the expansion of `!macro',
1069 define.sps:1-3: inside the expansion of `!macro',
1070 define.sps:1-3: inside the expansion of `!macro',
1071 define.sps:1-3: inside the expansion of `!macro',
1072 define.sps:1-3: inside the expansion of `!macro',
1073 define.sps:1-3: inside the expansion of `!macro',
1074 define.sps:1-3: inside the expansion of `!macro',
1075 define.sps:1-3: inside the expansion of `!macro',
1076 define.sps:1-3: inside the expansion of `!macro',
1077 define.sps:1-3: inside the expansion of `!macro',
1078 define.sps:1-3: inside the expansion of `!macro',
1079 define.sps:1-3: inside the expansion of `!macro',
1080 define.sps:1-3: inside the expansion of `!macro',
1081 define.sps:1-3: inside the expansion of `!macro',
1082 define.sps:1-3: inside the expansion of `!macro',
1083 define.sps:1-3: inside the expansion of `!macro',
1084 define.sps:1-3: inside the expansion of `!macro',
1085 define.sps:1-3: inside the expansion of `!macro',
1086 define.sps:1-3: inside the expansion of `!macro',
1087 define.sps:1-3: inside the expansion of `!macro',
1088 define.sps:1-3: inside the expansion of `!macro',
1089 define.sps:1-3: inside the expansion of `!macro',
1090 define.sps:1-3: inside the expansion of `!macro',
1091 define.sps:4.1-4.6: error: DEFINE: Maximum nesting level 50 exceeded.  (Use SET MNEST to change the limit.)"
1092
1093 define.sps:4.1-4.6: error: Syntax error at `!macro' (in expansion of `!macro'): expecting command name.
1094 ])
1095 AT_CLEANUP
1096
1097 AT_SETUP([macro !IF condition])
1098 AT_KEYWORDS([if])
1099 for operators in \
1100     '!eq !ne !lt !gt !le !ge' \
1101     '  =  <>   <   >  <=  >='
1102 do
1103     set $operators
1104     AS_BOX([$operators])
1105     cat > define.sps <<EOF
1106 DEFINE !test(!positional !tokens(1))
1107 !if (!1 $1 1) !then true !else false !ifend
1108 !if (!1 $2 1) !then true !else false !ifend
1109 !if (!1 $3 1) !then true !else false !ifend
1110 !if (!1 $4 1) !then true !else false !ifend
1111 !if (!1 $5 1) !then true !else false !ifend
1112 !if (!1 $6 1) !then true !else false !ifend.
1113 !ENDDEFINE.
1114 DEBUG EXPAND.
1115 !test 0
1116 !test 1
1117 !test 2
1118 !test '1'
1119 !test 1.0
1120 EOF
1121     AT_CAPTURE_FILE([define.sps])
1122     AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1123 false true true false true false.
1124
1125 true false false false true true.
1126
1127 false true false true false true.
1128
1129 true false false false true true.
1130
1131 false true false true false true.
1132 ])
1133 done
1134 AT_CLEANUP
1135
1136 AT_SETUP([macro !IF condition -- case sensitivity])
1137 AT_KEYWORDS([if])
1138 for operators in \
1139     '!eq !ne !lt !gt !le !ge' \
1140     '  =  <>   <   >  <=  >='
1141 do
1142     set $operators
1143     AS_BOX([$operators])
1144     cat > define.sps <<EOF
1145 DEFINE !test(!positional !tokens(1))
1146 !if (!1 $1 a) !then true !else false !ifend
1147 !if (!1 $1 A) !then true !else false !ifend
1148 !if (!1 $2 a) !then true !else false !ifend
1149 !if (!1 $2 A) !then true !else false !ifend
1150 !if (!1 $3 a) !then true !else false !ifend
1151 !if (!1 $3 A) !then true !else false !ifend
1152 !if (!1 $4 a) !then true !else false !ifend
1153 !if (!1 $4 A) !then true !else false !ifend
1154 !if (!1 $5 a) !then true !else false !ifend
1155 !if (!1 $5 A) !then true !else false !ifend
1156 !if (!1 $6 a) !then true !else false !ifend
1157 !if (!1 $6 A) !then true !else false !ifend
1158 !if (!1 $1 !null) !then true !else false !ifend
1159 !if (!1 $2 !null) !then true !else false !ifend.
1160 !ENDDEFINE.
1161 DEBUG EXPAND.
1162 !test a
1163 !test A
1164 !test b
1165 !test B
1166 EOF
1167     AT_CAPTURE_FILE([define.sps])
1168     AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1169 true false false true false false false true true false true true false true.
1170
1171 false true true false true false false false true true false true false true.
1172
1173 false false true true false false true true false false true true false true.
1174
1175 false false true true true false false true true false false true false true.
1176 ])
1177 done
1178 AT_CLEANUP
1179
1180 AT_SETUP([macro !IF condition -- logical operators])
1181 AT_KEYWORDS([if])
1182 for operators in \
1183     '!and !or !not' \
1184     '   &   |    ~'
1185 do
1186     set $operators
1187     AS_BOX([$operators])
1188     cat > define.sps <<EOF
1189 DEFINE !test_binary(!positional !tokens(1)/!positional !tokens(1))
1190 !if !1 $1 !2 !then true !else false !ifend
1191 !if !1 $2 !2 !then true !else false !ifend.
1192 !ENDDEFINE.
1193
1194 DEFINE !test_unary(!positional !tokens(1))
1195 !if $3 !1 !then true !else false !ifend.
1196 !ENDDEFINE.
1197
1198 * These are:
1199   ((not A) and B) or C
1200   not (A and B) or C
1201   not A and (B or C)
1202 DEFINE !test_prec(!pos !tokens(1)/!pos !tokens(1)/!pos !tokens(1))
1203 !if $3 !1 $1 !2 $2 !3 !then true !else false !ifend
1204 !if $3 (!1 $1 !2) $2 !3 !then true !else false !ifend
1205 !if $3 !1 $1 (!2 $2 !3) !then true !else false !ifend
1206 !ENDDEFINE.
1207
1208 DEBUG EXPAND.
1209 !test_binary 0 0
1210 !test_binary 0 1
1211 !test_binary 1 0
1212 !test_binary 1 1
1213 !test_unary 0
1214 !test_unary 1
1215 !test_prec 0 0 0 !test_prec 0 0 1 !test_prec 0 1 0 !test_prec 0 1 1.
1216 !test_prec 1 0 0 !test_prec 1 0 1 !test_prec 1 1 0 !test_prec 1 1 1.
1217 EOF
1218     AT_CAPTURE_FILE([define.sps])
1219     AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1220 false false.
1221
1222 false true.
1223
1224 false true.
1225
1226 true true.
1227
1228 true.
1229
1230 false.
1231
1232 false true false
1233 true true true
1234 true true true
1235 true true true
1236
1237 false true false
1238 true true false
1239 false false false
1240 true true false
1241 ])
1242 done
1243 AT_CLEANUP
1244
1245 AT_SETUP([macro !LET])
1246 AT_KEYWORDS([let])
1247 AT_DATA([define.sps], [dnl
1248 DEFINE !macro(!POS !CMDEND)
1249 !LET !v1 = !CONCAT('x',!1,'y')
1250 !LET !v2 = !QUOTE(!v1)
1251 !LET !v3 = (!LENGTH(!1) = 1)
1252 !LET !v4 = (!SUBSTR(!1, 3) = !NULL)
1253 v1=!v1.
1254 v2=!v2.
1255 v3=!v3.
1256 v4=!v4.
1257 !ENDDEFINE.
1258 DEBUG EXPAND.
1259 !macro 0.
1260 !macro.
1261 !macro xyzzy.
1262 ])
1263 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1264 v1 = x0y.
1265 v2 = x0y.
1266 v3 = 1.
1267 v4 = 1.
1268
1269 v1 = xy.
1270 v2 = xy.
1271 v3 = 0.
1272 v4 = 1.
1273
1274 v1 = xxyzzyy.
1275 v2 = xxyzzyy.
1276 v3 = 0.
1277 v4 = 0.
1278 ])
1279 AT_CLEANUP
1280
1281 AT_SETUP([macro indexed !DO])
1282 AT_KEYWORDS([index do])
1283 AT_DATA([define.sps], [dnl
1284 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1285
1286 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
1287 !DO !var = !1 !TO !2 !var !DOEND.
1288 !ENDDEFINE.
1289
1290 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1291 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
1292 !ENDDEFINE.
1293
1294 DEBUG EXPAND.
1295 !title "increasing".
1296 !for 1 5.
1297 !forby 1 5 1.
1298 !forby 1 5 2.
1299 !forby 1 5 2.5.
1300 !forby 1 5 -1.
1301
1302 !title "decreasing".
1303 !for 5 1.
1304 !forby 5 1 1.
1305 !forby 5 1 -1.
1306 !forby 5 1 -2.
1307 !forby 5 1 -3.
1308
1309 !title "non-integer".
1310 !for 1.5 3.5.
1311 ])
1312 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1313 "increasing".
1314
1315 1 2 3 4 5.
1316
1317 1 2 3 4 5.
1318
1319 1 3 5.
1320
1321 1 3.5.
1322
1323 .
1324
1325 "decreasing".
1326
1327 .
1328
1329 .
1330
1331 5 4 3 2 1.
1332
1333 5 3 1.
1334
1335 5 2.
1336
1337 "non-integer".
1338
1339 1.5 2.5 3.5.
1340 ])
1341 AT_CLEANUP
1342
1343 AT_SETUP([macro !DO invalid variable names])
1344 AT_KEYWORDS([index do])
1345 AT_DATA([define.sps], [dnl
1346 DEFINE !for(x=!TOKENS(1) / y=!TOKENS(1))
1347 !DO !x = !x !TO !y !var !DOEND.
1348 !ENDDEFINE.
1349
1350 DEFINE !for2(x=!TOKENS(1) / y=!TOKENS(1))
1351 !DO !noexpand = !x !TO !y !var !DOEND.
1352 !ENDDEFINE.
1353
1354 DEBUG EXPAND.
1355 !for x=1 y=5.
1356 !for2 x=1 y=5.
1357 ])
1358 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1359 define.sps:1-3: At `!x' in the expansion of `!for',
1360 define.sps:10.1-10.12: error: DEBUG EXPAND: Cannot use argument name or macro
1361 keyword as !DO variable.
1362
1363 !DO 1 = 1 !TO 5 !var !DOEND.
1364
1365 define.sps:5-7: At `!noexpand' in the expansion of `!for2',
1366 define.sps:11.1-11.13: error: DEBUG EXPAND: Cannot use argument name or macro
1367 keyword as !DO variable.
1368
1369 !DO !noexpand = 1 !TO 5 !var !DOEND.
1370 ])
1371 AT_CLEANUP
1372
1373 AT_SETUP([macro indexed !DO reaches MITERATE])
1374 AT_KEYWORDS([index do])
1375 AT_DATA([define.sps], [dnl
1376 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1377
1378 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1))
1379 !DO !var = !1 !TO !2 !var !DOEND.
1380 !ENDDEFINE.
1381
1382 DEFINE !forby(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1383 !DO !var = !1 !TO !2 !BY !3 !var !DOEND.
1384 !ENDDEFINE.
1385
1386 SET MITERATE=3.
1387 DEBUG EXPAND.
1388 !title "increasing".
1389 !for 1 5.
1390 !forby 1 5 1.
1391 !forby 1 5 2.
1392 !forby 1 5 2.5.
1393 !forby 1 5 -1.
1394
1395 !title "decreasing".
1396 !for 5 1.
1397 !forby 5 1 1.
1398 !forby 5 1 -1.
1399 !forby 5 1 -2.
1400 !forby 5 1 -3.
1401
1402 !title "non-integer".
1403 !for 1.5 3.5.
1404 ])
1405 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1406 "increasing".
1407
1408 In the expansion of `!DO',
1409 define.sps:3-5: inside the expansion of `!for',
1410 define.sps:14.1-14.8: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum
1411 number of iterations 3.  (Use SET MITERATE to change the limit.)
1412
1413 1 2 3 4.
1414
1415 In the expansion of `!DO',
1416 define.sps:7-9: inside the expansion of `!forby',
1417 define.sps:15.1-15.12: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum
1418 number of iterations 3.  (Use SET MITERATE to change the limit.)
1419
1420 1 2 3 4.
1421
1422 1 3 5.
1423
1424 1 3.5.
1425
1426 .
1427
1428 "decreasing".
1429
1430 .
1431
1432 .
1433
1434 In the expansion of `!DO',
1435 define.sps:7-9: inside the expansion of `!forby',
1436 define.sps:23.1-23.13: error: DEBUG EXPAND: Numerical !DO loop exceeded maximum
1437 number of iterations 3.  (Use SET MITERATE to change the limit.)
1438
1439 5 4 3 2.
1440
1441 5 3 1.
1442
1443 5 2.
1444
1445 "non-integer".
1446
1447 1.5 2.5 3.5.
1448 ])
1449 AT_CLEANUP
1450
1451 AT_SETUP([!BREAK with macro indexed !DO])
1452 AT_KEYWORDS([index do break])
1453 AT_DATA([define.sps], [dnl
1454 DEFINE !title(!POS !TOKENS(1)) !1. !ENDDEFINE.
1455
1456 DEFINE !for(!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1))
1457 !DO !var = !1 !TO !2
1458   !var
1459   !IF 1 !THEN
1460     !IF !var = !3 !THEN
1461       x
1462       !BREAK
1463       y
1464     !IFEND
1465     ,
1466   !IFEND
1467 !DOEND.
1468 !ENDDEFINE.
1469
1470 DEBUG EXPAND.
1471 !for 1 5 4.
1472 ])
1473 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1474 1, 2, 3, 4 x.
1475 ])
1476 AT_CLEANUP
1477
1478 AT_SETUP([macro list !DO])
1479 AT_KEYWORDS([index do])
1480 AT_DATA([define.sps], [dnl
1481 DEFINE !for(!POS !CMDEND)
1482 (!DO !i !IN (!1) (!i) !DOEND).
1483 !ENDDEFINE.
1484
1485 DEBUG EXPAND.
1486 !for a b c.
1487 !for 'foo bar baz quux'.
1488 !for.
1489 ])
1490 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1491 ( (a) (b) (c) ).
1492
1493 ( (foo) (bar) (baz) (quux) ).
1494
1495 ( ).
1496 ])
1497 AT_CLEANUP
1498
1499 AT_SETUP([macro list !DO reaches MITERATE])
1500 AT_KEYWORDS([index do])
1501 AT_DATA([define.sps], [dnl
1502 DEFINE !for(!POS !CMDEND)
1503 (!DO !i !IN (!1) (!i) !DOEND).
1504 !ENDDEFINE.
1505
1506 SET MITERATE=2.
1507 DEBUG EXPAND.
1508 !for a b c.
1509 !for 'foo bar baz quux'.
1510 !for.
1511 ])
1512 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1513 In the expansion of `!DO',
1514 define.sps:1-3: inside the expansion of `!for',
1515 define.sps:7.1-7.10: error: DEBUG EXPAND: !DO loop over list exceeded maximum
1516 number of iterations 2.  (Use SET MITERATE to change the limit.)
1517
1518 ( (a) (b) ).
1519
1520 In the expansion of `!DO',
1521 define.sps:1-3: inside the expansion of `!for',
1522 define.sps:8.1-8.23: error: DEBUG EXPAND: !DO loop over list exceeded maximum
1523 number of iterations 2.  (Use SET MITERATE to change the limit.)
1524
1525 ( (foo) (bar) ).
1526
1527 ( ).
1528 ])
1529 AT_CLEANUP
1530
1531 AT_SETUP([!BREAK with macro list !DO])
1532 AT_KEYWORDS([index break do])
1533 AT_DATA([define.sps], [dnl
1534 DEFINE !for(!POS !TOKENS(1) / !POS !CMDEND)
1535 (!DO !i !IN (!2)
1536   (!i)
1537   !IF 1 !THEN
1538     !IF !i = !1 !THEN
1539       x
1540       !BREAK
1541       y
1542     !IFEND
1543     ,
1544   !IFEND
1545 !DOEND).
1546 !ENDDEFINE.
1547
1548 DEBUG EXPAND.
1549 !for d a b c.
1550 !for baz 'foo bar baz quux'.
1551 !for e.
1552 ])
1553 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
1554 ( (a), (b), (c), ).
1555
1556 ( (foo), (bar), (baz)x).
1557
1558 ( ).
1559 ])
1560 AT_CLEANUP
1561
1562 AT_SETUP([macro !LET])
1563 AT_DATA([define.sps], [dnl
1564 DEFINE !macro(!pos !enclose('(',')'))
1565 !LET !x=!1
1566 !LET !y=!QUOTE(!1)
1567 !LET !z=(!y="abc")
1568 !y !z
1569 !ENDDEFINE.
1570
1571 DEBUG EXPAND.
1572 !macro(1+2).
1573 !macro(abc).
1574 ])
1575 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [0], [dnl
1576 1 + 2 0
1577
1578 abc 1
1579 ])
1580 AT_CLEANUP
1581
1582 AT_SETUP([macro !LET invalid variable names])
1583 AT_DATA([define.sps], [dnl
1584 DEFINE !macro(x=!tokens(1))
1585 !LET !x=!x
1586 !ENDDEFINE.
1587
1588 DEFINE !macro2()
1589 !LET !do=x
1590 !ENDDEFINE.
1591
1592 DEBUG EXPAND.
1593 !macro x=1.
1594 !macro2.
1595 ])
1596 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [1], [dnl
1597 "define.sps:1-3: At `!x' in the expansion of `!macro',
1598 define.sps:10.1-10.10: error: DEBUG EXPAND: Cannot use argument name or macro keyword ""!x"" as !LET variable."
1599
1600 !LET 1 = 1
1601
1602 "define.sps:5-7: At `!do' in the expansion of `!macro2',
1603 define.sps:11.1-11.7: error: DEBUG EXPAND: Cannot use argument name or macro keyword ""!do"" as !LET variable."
1604
1605 "define.sps:5-7: At `=' in the expansion of `!macro2',
1606 define.sps:11.1-11.7: error: DEBUG EXPAND: Expected macro variable name following !DO."
1607
1608 !LET !do = x
1609 ])
1610 AT_CLEANUP
1611
1612 AT_SETUP([BEGIN DATA inside a macro])
1613 AT_DATA([define.sps], [dnl
1614 DEFINE !macro()
1615 DATA LIST NOTABLE /x 1.
1616 BEGIN DATA
1617 1
1618 2
1619 3
1620 END DATA.
1621 LIST.
1622 !ENDDEFINE.
1623
1624 !macro
1625 ])
1626 AT_CHECK([pspp define.sps -O format=csv], [0], [dnl
1627 Table: Data List
1628 x
1629 1
1630 2
1631 3
1632 ])
1633 AT_CLEANUP
1634
1635 AT_SETUP([TITLE and SUBTITLE with macros])
1636 AT_KEYWORDS([macro])
1637 for command in TITLE SUBTITLE; do
1638     cat >title.sps <<EOF
1639 DEFINE !paste(!POS !TOKENS(1) / !POS !TOKENS(1))
1640 !CONCAT(!1,!2)
1641 !ENDDEFINE.
1642 $command prefix !paste foo bar suffix.
1643 SHOW $command.
1644 EOF
1645     cat >expout <<EOF
1646 title.sps:5: note: SHOW: $command is prefix foobar suffix.
1647 EOF
1648     AT_CHECK([pspp -O format=csv title.sps], [0], [expout])
1649 done
1650 AT_CLEANUP
1651
1652 AT_SETUP([error message within macro expansion])
1653 AT_DATA([define.sps], [dnl
1654 DEFINE !vars(!POS !TOKENS(1)) a b C !ENDDEFINE.
1655 DATA LIST NOTABLE /a b 1-2.
1656 COMPUTE x = !vars x.
1657 ])
1658 AT_CHECK([pspp -O format=csv define.sps], [1], [dnl
1659 define.sps:3.13-3.19: error: COMPUTE: Syntax error at `b' (in expansion of `!vars x'): expecting end of command.
1660 ])
1661 AT_CLEANUP
1662
1663 dnl A macro with keyword arguments needs a token of lookahead
1664 dnl to find out whether another keyword is present.  Test that
1665 dnl this special case works OK.
1666 AT_SETUP([macro calls in each others' lookahead])
1667 AT_DATA([define.sps], [dnl
1668 DEFINE !k(x=!DEFAULT(0) !TOKENS(1)/y=!DEFAULT(0) !TOKENS(1))
1669 (x=!x)(y=!y)
1670 !ENDDEFINE.
1671 DEBUG EXPAND.
1672 !k
1673 !k x=1
1674 !k y=2
1675 !k y=2 x=1
1676 !k x=1 y=2.
1677 ])
1678 AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
1679 (x = 0) (y = 0)
1680
1681 (x = 1) (y = 0)
1682
1683 (x = 0) (y = 2)
1684 (x = 1) (y = 2)
1685
1686 (x = 1) (y = 2)
1687 ])
1688 AT_CLEANUP
1689
1690 AT_SETUP([bad token in macro body])
1691 AT_DATA([define.sps], [dnl
1692 DEFINE !x()
1693 x'123'
1694 !ENDDEFINE.
1695 ])
1696 AT_CHECK([pspp define.sps], [1], [dnl
1697 define.sps:3: error: DEFINE: String of hex digits has 3 characters, which is
1698 not a multiple of 2.
1699 ])
1700 AT_CLEANUP
1701
1702 AT_SETUP([macro name overlaps with macro function name])
1703 dnl !len is short for macro function !LENGTH.  PSPP used to
1704 dnl reject the following with "`(' expected following !LENGTH".
1705 dnl Now PSPP only consider macro functions when the name is
1706 dnl followed by '('.
1707 AT_DATA([define.sps], [dnl
1708 DEFINE !len() 5 !ENDDEFINE.
1709 DEFINE !x() !eval(!len) !ENDDEFINE.
1710 DEBUG EXPAND.
1711 !x
1712 ])
1713 AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
1714 5
1715 ])
1716 AT_CLEANUP
1717
1718 AT_SETUP([generic macro function syntax errors])
1719 AT_DATA([define.sps], [dnl
1720
1721
1722 DEFINE !c() !SUBSTR(1x) !ENDDEFINE.
1723 DEFINE !d() !SUBSTR(1 !ENDDEFINE.
1724 DEFINE !narg_blanks() !BLANKS() !ENDDEFINE.
1725 DEFINE !narg_concat() !CONCAT() !ENDDEFINE.
1726 DEFINE !narg_eval() !EVAL() !ENDDEFINE.
1727 DEFINE !narg_head() !HEAD() !ENDDEFINE.
1728 DEFINE !narg_index() !INDEX() !ENDDEFINE.
1729 DEFINE !narg_length() !LENGTH() !ENDDEFINE.
1730 DEFINE !narg_null() !NULL() !ENDDEFINE.
1731 DEFINE !narg_quote() !QUOTE() !ENDDEFINE.
1732 DEFINE !narg_substr() !SUBSTR() !ENDDEFINE.
1733 DEFINE !narg_tail() !TAIL() !ENDDEFINE.
1734 DEFINE !narg_unquote() !UNQUOTE() !ENDDEFINE.
1735 DEFINE !narg_upcase() !UPCASE() !ENDDEFINE.
1736 dnl )
1737 DEBUG EXPAND.
1738
1739
1740 !c.
1741 !d.
1742 !narg_blanks.
1743 !narg_concat.
1744 !narg_eval.
1745 !narg_head.
1746 !narg_index.
1747 !narg_length.
1748 !narg_null.
1749 !narg_quote.
1750 !narg_substr.
1751 !narg_tail.
1752 !narg_unquote.
1753 !narg_upcase.
1754 ])
1755 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1756 define.sps:3: At `x' in the expansion of `!c',
1757 define.sps:20.1-20.2: error: DEBUG EXPAND: `,' or `@:}@' expected in call to macro
1758 function !SUBSTR.
1759
1760 !SUBSTR(1 x)
1761
1762 define.sps:4: In the expansion of `!d',
1763 define.sps:21.1-21.2: error: DEBUG EXPAND: Missing `@:}@' in call to macro
1764 function !SUBSTR.
1765
1766 !SUBSTR@{:@1
1767
1768 define.sps:5: In the expansion of `!narg_blanks',
1769 define.sps:22.1-22.12: error: DEBUG EXPAND: Macro function !BLANKS takes one
1770 argument (not 0).
1771
1772 !BLANKS( )
1773
1774 define.sps:6: In the expansion of `!narg_concat',
1775 define.sps:23.1-23.12: error: DEBUG EXPAND: Macro function !CONCAT needs at
1776 least one argument.
1777
1778 !CONCAT( )
1779
1780 define.sps:7: In the expansion of `!narg_eval',
1781 define.sps:24.1-24.10: error: DEBUG EXPAND: Macro function !EVAL takes one
1782 argument (not 0).
1783
1784 !EVAL( )
1785
1786 define.sps:8: In the expansion of `!narg_head',
1787 define.sps:25.1-25.10: error: DEBUG EXPAND: Macro function !HEAD takes one
1788 argument (not 0).
1789
1790 !HEAD( )
1791
1792 define.sps:9: In the expansion of `!narg_index',
1793 define.sps:26.1-26.11: error: DEBUG EXPAND: Macro function !INDEX takes two
1794 arguments (not 0).
1795
1796 !INDEX( )
1797
1798 define.sps:10: In the expansion of `!narg_length',
1799 define.sps:27.1-27.12: error: DEBUG EXPAND: Macro function !LENGTH takes one
1800 argument (not 0).
1801
1802 !LENGTH( )
1803
1804 ( )
1805
1806 define.sps:12: In the expansion of `!narg_quote',
1807 define.sps:29.1-29.11: error: DEBUG EXPAND: Macro function !QUOTE takes one
1808 argument (not 0).
1809
1810 !QUOTE( )
1811
1812 define.sps:13: In the expansion of `!narg_substr',
1813 define.sps:30.1-30.12: error: DEBUG EXPAND: Macro function !SUBSTR takes two or
1814 three arguments (not 0).
1815
1816 !SUBSTR( )
1817
1818 define.sps:14: In the expansion of `!narg_tail',
1819 define.sps:31.1-31.10: error: DEBUG EXPAND: Macro function !TAIL takes one
1820 argument (not 0).
1821
1822 !TAIL( )
1823
1824 define.sps:15: In the expansion of `!narg_unquote',
1825 define.sps:32.1-32.13: error: DEBUG EXPAND: Macro function !UNQUOTE takes one
1826 argument (not 0).
1827
1828 !UNQUOTE( )
1829
1830 define.sps:16: In the expansion of `!narg_upcase',
1831 define.sps:33.1-33.12: error: DEBUG EXPAND: Macro function !UPCASE takes one
1832 argument (not 0).
1833
1834 !UPCASE( )
1835 ])
1836 AT_CLEANUP
1837
1838 AT_SETUP([specific macro function syntax errors])
1839 AT_DATA([define.sps], [dnl
1840 DEFINE !a() !BLANKS(x). !ENDDEFINE.
1841 DEFINE !b() !SUBSTR(x, y). !ENDDEFINE.
1842 DEFINE !c() !SUBSTR(x, 1, z). !ENDDEFINE.
1843 DEBUG EXPAND.
1844 !a.
1845 !b.
1846 !c.
1847 ])
1848 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1849 define.sps:1: In the expansion of `!a',
1850 define.sps:5.1-5.2: error: DEBUG EXPAND: Argument to !BLANKS must be non-
1851 negative integer (not "x").
1852
1853 !BLANKS(x).
1854
1855 define.sps:2: In the expansion of `!b',
1856 define.sps:6.1-6.2: error: DEBUG EXPAND: Second argument of !SUBSTR must be
1857 positive integer (not "y").
1858
1859 !SUBSTR(x, y).
1860
1861 define.sps:3: In the expansion of `!c',
1862 define.sps:7.1-7.2: error: DEBUG EXPAND: Third argument of !SUBSTR must be non-
1863 negative integer (not "z").
1864
1865 !SUBSTR(x, 1, z).
1866 ])
1867 AT_CLEANUP
1868
1869 AT_SETUP([macro expression errors])
1870 AT_DATA([define.sps], [dnl
1871 DEFINE !a() !LET !x = (1. !ENDDEFINE dnl )
1872
1873 DEFINE !b() !DO !x = x. !ENDDEFINE.
1874 DEFINE !c() !LET !x = (). !ENDDEFINE.
1875 DEBUG EXPAND.
1876 !a.
1877 !b.
1878 !c.
1879 ])
1880 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1881 define.sps:1-2: At `.' in the expansion of `!a',
1882 define.sps:5.1-5.2: error: DEBUG EXPAND: Expecting ')' in macro expression.
1883
1884 !LET !x = (1.
1885
1886 At `x' in the expansion of `!DO',
1887 define.sps:2: inside the expansion of `!b',
1888 define.sps:6.1-6.2: error: DEBUG EXPAND: Macro expression must evaluate to a
1889 number (not "x").
1890
1891 !DO !x = x.
1892
1893 define.sps:3: At `)' in the expansion of `!c',
1894 define.sps:7.1-7.2: error: DEBUG EXPAND: Expecting literal or function
1895 invocation in macro expression.
1896
1897 !LET !x = ( ).
1898 ])
1899 AT_CLEANUP
1900
1901 AT_SETUP([macro !IF errors])
1902 AT_KEYWORDS([IF])
1903 AT_DATA([define.sps], [dnl
1904 DEFINE !a() !IF 1 !ENDDEFINE.
1905 DEFINE !b() !IF 1 !THEN !ENDDEFINE.
1906 DEFINE !c() !IF 1 !THEN !ELSE !ENDDEFINE.
1907 DEBUG EXPAND.
1908 !a.
1909 !b.
1910 !c.
1911 ])
1912 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1913 define.sps:1: In the expansion of `!a',
1914 define.sps:5.1-5.2: error: DEBUG EXPAND: !THEN expected in macro !IF construct.
1915
1916 !IF 1
1917
1918 define.sps:2: In the expansion of `!b',
1919 define.sps:6.1-6.2: error: DEBUG EXPAND: !ELSE or !IFEND expected in macro !IF
1920 construct.
1921
1922 !IF 1 !THEN
1923
1924 define.sps:3: In the expansion of `!c',
1925 define.sps:7.1-7.2: error: DEBUG EXPAND: !IFEND expected in macro !IF
1926 construct.
1927
1928 !IF 1 !THEN !ELSE
1929 ])
1930 AT_CLEANUP
1931
1932 AT_SETUP([macro !LET errors])
1933 AT_KEYWORDS([LET])
1934 AT_DATA([define.sps], [dnl
1935 DEFINE !a() !LET !ENDDEFINE.
1936 DEFINE !b() !LET 0 !ENDDEFINE.
1937 DEFINE !c() !LET !x !ENDDEFINE.
1938 DEFINE !d() !LET !x y !ENDDEFINE.
1939 DEBUG EXPAND.
1940 !a.
1941 !b.
1942 !c.
1943 !d.
1944 ])
1945 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1946 define.sps:1: In the expansion of `!a',
1947 define.sps:6.1-6.2: error: DEBUG EXPAND: Expected macro variable name following
1948 !LET.
1949
1950 !LET
1951
1952 define.sps:2: At `0' in the expansion of `!b',
1953 define.sps:7.1-7.2: error: DEBUG EXPAND: Expected macro variable name following
1954 !LET.
1955
1956 !LET 0
1957
1958 define.sps:3: In the expansion of `!c',
1959 define.sps:8.1-8.2: error: DEBUG EXPAND: Expected `=' following !LET.
1960
1961 !LET !x
1962
1963 define.sps:4: At `y' in the expansion of `!d',
1964 define.sps:9.1-9.2: error: DEBUG EXPAND: Expected `=' following !LET.
1965
1966 !LET !x y
1967 ])
1968 AT_CLEANUP
1969
1970 AT_SETUP([macro !DO errors])
1971 AT_KEYWORDS([DO])
1972 AT_DATA([define.sps], [dnl
1973 DEFINE !a() !DO !ENDDEFINE.
1974 DEFINE !b() !DO 0 !ENDDEFINE.
1975 DEFINE !c() !DO !x !ENDDEFINE.
1976 DEFINE !d() !DO !x !in (x) !ENDDEFINE.
1977 DEFINE !e() !DO !x = x. !ENDDEFINE.
1978 DEFINE !f() !DO !x = 5 x !ENDDEFINE.
1979 DEFINE !g() !DO !x = 5 !TO 6 !BY 0 !ENDDEFINE.
1980 DEFINE !h() !DO !x !ENDDEFINE.
1981 DEFINE !i() !DO !x 0 !ENDDEFINE.
1982 DEFINE !j() !BREAK !ENDDEFINE.
1983 DEBUG EXPAND.
1984 !a.
1985 !b.
1986 !c.
1987 !d.
1988 !e.
1989 !f.
1990 !g.
1991 !h.
1992 !i.
1993 !j.
1994 ])
1995 AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
1996 define.sps:1: In the expansion of `!a',
1997 define.sps:12.1-12.2: error: DEBUG EXPAND: Expected macro variable name
1998 following !DO.
1999
2000 !DO
2001
2002 define.sps:2: At `0' in the expansion of `!b',
2003 define.sps:13.1-13.2: error: DEBUG EXPAND: Expected macro variable name
2004 following !DO.
2005
2006 !DO 0
2007
2008 define.sps:3: In the expansion of `!c',
2009 define.sps:14.1-14.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
2010
2011 !DO !x
2012
2013 In the expansion of `!DO',
2014 define.sps:4: inside the expansion of `!d',
2015 define.sps:15.1-15.2: error: DEBUG EXPAND: Missing !DOEND.
2016
2017 !DO !x !in(x)
2018
2019 At `x' in the expansion of `!DO',
2020 define.sps:5: inside the expansion of `!e',
2021 define.sps:16.1-16.2: error: DEBUG EXPAND: Macro expression must evaluate to a
2022 number (not "x").
2023
2024 !DO !x = x.
2025
2026 At `x' in the expansion of `!DO',
2027 define.sps:6: inside the expansion of `!f',
2028 define.sps:17.1-17.2: error: DEBUG EXPAND: Expected !TO in numerical !DO loop.
2029
2030 !DO !x = 5 x
2031
2032 In the expansion of `!DO',
2033 define.sps:7: inside the expansion of `!g',
2034 define.sps:18.1-18.2: error: DEBUG EXPAND: !BY value cannot be zero.
2035
2036 !DO !x = 5 !TO 6 !BY 0
2037
2038 define.sps:8: In the expansion of `!h',
2039 define.sps:19.1-19.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
2040
2041 !DO !x
2042
2043 define.sps:9: At `0' in the expansion of `!i',
2044 define.sps:20.1-20.2: error: DEBUG EXPAND: Expected `=' or !IN in !DO loop.
2045
2046 !DO !x 0
2047
2048 define.sps:10: At `!BREAK' in the expansion of `!j',
2049 define.sps:21.1-21.2: error: DEBUG EXPAND: !BREAK outside !DO.
2050
2051 ])
2052 AT_CLEANUP
2053
2054 AT_SETUP([macros in comments])
2055 AT_KEYWORDS([macro])
2056 AT_DATA([define.sps], [dnl
2057 DEFINE !macro() x y z !ENDDEFINE.
2058 /* !macro.
2059 *!macro.
2060 DEBUG EXPAND.
2061 !macro.
2062 ])
2063 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
2064 x y z
2065 ])
2066 AT_CLEANUP
2067
2068 AT_SETUP([DEFINE syntax errors])
2069 AT_KEYWORDS([macro])
2070 AT_DATA([define.sps], [dnl
2071 DEFINE !macro(!POSITIONAL !CHAREND('x y')) !ENDDEFINE.
2072 DEFINE !macro(a=!TOKENS(1)/!POSITIONAL !TOKENS(1)) !ENDDEFINE.
2073 DEFINE !macro(!a=!TOKENS(1)) !ENDDEFINE.
2074 DEFINE !macro(do=!TOKENS(1)) !ENDDEFINE.
2075 DEFINE 0() !ENDDEFINE.
2076 DEFINE x y () !ENDDEFINE.
2077 DEFINE !macro(1) !ENDDEFINE.
2078 DEFINE !macro(x 2) !ENDDEFINE.
2079 DEFINE !macro(x=!DEFAULT 3) !ENDDEFINE.
2080 DEFINE !macro(x=!TOKENS 4) !ENDDEFINE.
2081 DEFINE !macro(x=!TOKENS(x)) !ENDDEFINE.
2082 DEFINE !macro(x=!TOKENS(1 5)) !ENDDEFINE.
2083 DEFINE !macro(x=!ENCLOSE 6) !ENDDEFINE.
2084 DEFINE !macro(x=!ENCLOSE('x' y)) !ENDDEFINE.
2085 DEFINE !macro(x=!ENCLOSE('x',y)) !ENDDEFINE.
2086 DEFINE !macro(x=!ENCLOSE('x','y' z)) !ENDDEFINE.
2087 DEFINE !macro(x=!CHAREND 7) !ENDDEFINE.
2088 DEFINE !macro(x=!CHAREND(8)) !ENDDEFINE.
2089 DEFINE !macro(x=!CHAREND('x' 9)) !ENDDEFINE.
2090 DEFINE !macro(x=!WTF) !ENDDEFINE.
2091 DEFINE !macro(x=!TOKENS(1) x) !ENDDEFINE.
2092 DEFINE !macro(x=!DEFAULT() !DEFAULT()) !ENDDEFINE.
2093 DEFINE !macro(x=!TOKENS(1) !CMDEND) !ENDDEFINE.
2094 DEFINE !macro()
2095 ])
2096 AT_CHECK([pspp define.sps], [1], [dnl
2097 define.sps:1.36-1.40: error: DEFINE: Syntax error at `'x y'': String must
2098 contain exactly one token.
2099
2100 define.sps:2.40-2.46: error: DEFINE: Syntax error at `!TOKENS': Positional
2101 parameters must precede keyword parameters.
2102
2103 define.sps:3.15-3.16: error: DEFINE: Syntax error at `!a': Keyword macro
2104 parameter must be named in definition without "!" prefix.
2105
2106 define.sps:4.15-4.16: error: DEFINE: Syntax error at `do': Cannot use macro
2107 keyword "do" as an argument name.
2108
2109 define.sps:5.8: error: DEFINE: Syntax error at `0': expecting identifier.
2110
2111 define.sps:6.10: error: DEFINE: Syntax error at `y': expecting `@{:@'.
2112
2113 define.sps:7.15: error: DEFINE: Syntax error at `1': expecting identifier.
2114
2115 define.sps:8.17: error: DEFINE: Syntax error at `2': expecting !TOKENS, !
2116 CHAREND, !ENCLOSE, or !CMDEND.
2117
2118 define.sps:9.26: error: DEFINE: Syntax error at `3': expecting `@{:@'.
2119
2120 define.sps:10.25: error: DEFINE: Syntax error at `4': expecting `('.
2121
2122 define.sps:11.25: error: DEFINE: Syntax error at `x': Expected positive integer
2123 for !TOKENS.
2124
2125 define.sps:12.27: error: DEFINE: Syntax error at `5': expecting `)'.
2126
2127 define.sps:13.26: error: DEFINE: Syntax error at `6': expecting `('.
2128
2129 define.sps:14.30: error: DEFINE: Syntax error at `y': expecting `,'.
2130
2131 define.sps:15.30: error: DEFINE: Syntax error at `y': expecting string.
2132
2133 define.sps:16.34: error: DEFINE: Syntax error at `z': expecting `)'.
2134
2135 define.sps:17.26: error: DEFINE: Syntax error at `7': expecting `('.
2136
2137 define.sps:18.26: error: DEFINE: Syntax error at `8': expecting string.
2138
2139 define.sps:19.30: error: DEFINE: Syntax error at `9': expecting `)'.
2140
2141 define.sps:20.17-20.20: error: DEFINE: Syntax error at `!WTF': expecting !
2142 TOKENS, !CHAREND, !ENCLOSE, or !CMDEND.
2143
2144 define.sps:21.28: error: DEFINE: Syntax error at `x': expecting `/'.
2145
2146 define.sps:22.36: error: DEFINE: Syntax error at `(': !DEFAULT is allowed only
2147 once per argument.
2148
2149 define.sps:23.35: error: DEFINE: Syntax error at `)': Only one of !TOKENS, !
2150 CHAREND, !ENCLOSE, or !CMDEND is allowed.
2151
2152 define.sps:25.1: error: DEFINE: Syntax error at end of command: Expecting macro
2153 body or !ENDDEFINE.
2154 ])
2155 AT_CLEANUP
2156
2157 AT_SETUP([macro expansion with token merging])
2158 AT_DATA([define.sps], [dnl
2159 DEFINE !foo() "foo" !ENDDEFINE.
2160 DEFINE !bar() "bar" !ENDDEFINE.
2161 DEFINE !plus() + !ENDDEFINE.
2162 DEFINE !minus() - !ENDDEFINE.
2163 DEFINE !one() 1 !ENDDEFINE.
2164 ECHO "foo" + "bar".
2165 ECHO !foo.
2166 ECHO !bar.
2167 ECHO !foo + "quux".
2168 ECHO "baz" + !bar.
2169 ECHO !foo + !bar.
2170 ECHO !foo !plus !bar.
2171 ECHO "two" "strings".
2172 N OF CASES -/**/1.
2173 N OF CASES !minus 1.
2174 N OF CASES - !one.
2175 N OF CASES !minus !one.
2176 ])
2177 AT_CHECK([pspp define.sps], [1], [dnl
2178 foobar
2179
2180 foo
2181
2182 bar
2183
2184 fooquux
2185
2186 bazbar
2187
2188 foobar
2189
2190 foobar
2191
2192 two
2193
2194 define.sps:13.12-13.20: error: ECHO: Syntax error at `"strings"': expecting end
2195 of command.
2196
2197 define.sps:14.12-14.17: error: N OF CASES: Syntax error at `-/**/1': Expected
2198 positive integer for N OF CASES.
2199
2200 define.sps:15.12-15.19: error: N OF CASES: Syntax error at `!minus 1': Expected
2201 positive integer for N OF CASES.
2202
2203 define.sps:16.12-16.17: error: N OF CASES: Syntax error at `- !one': Expected
2204 positive integer for N OF CASES.
2205
2206 define.sps:17.12-17.22: error: N OF CASES: Syntax error at `!minus !one':
2207 Expected positive integer for N OF CASES.
2208 ])
2209 AT_CLEANUP
2210
2211 AT_SETUP([one macro calls another])
2212 AT_DATA([define.sps], [dnl
2213 DEFINE !a(!pos !enclose('(',')')) [[!1]] !ENDDEFINE.
2214 DEFINE !b(!pos !enclose('{','}')) !a(x !1 z) !ENDDEFINE.
2215 DEFINE !c(!pos !enclose('{','}')) !let !tmp=!quote(!concat('<',!1,'>')) !a(!tmp) !ENDDEFINE.
2216 DEBUG EXPAND.
2217 !b{y}.
2218 !c{y}.
2219 ])
2220 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
2221 [[x y z]]
2222
2223 [[ < y > ]]
2224 ])
2225 AT_CLEANUP