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