0211c71785511c75f647ebe47fec7ac5c7ee2a7b
[pspp] / tests / language / control / define.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([DEFINE])
18
19 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 with arguments])
45 AT_DATA([define.sps], [dnl
46 DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
47 DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.
48 DEFINE !t2(!positional !tokens(2)) t2 (!1) !ENDDEFINE.
49
50 DEFINE !ce(!positional !charend('/')) ce (!1) !ENDDEFINE.
51 DEFINE !ce2(!positional !charend('(')
52            /!positional !charend(')'))
53 ce2 (!1, !2)
54 !ENDDEFINE.
55
56 DEFINE !e(!positional !enclose('{','}')) e (!1) !ENDDEFINE.
57
58 DEFINE !cmd(!positional !cmdend) cmd(!1) !ENDDEFINE.
59 DEFINE !cmd2(!positional !cmdend
60             /!positional !tokens(1))
61 cmd2(!1, !2)
62 !ENDDEFINE.
63
64 DEBUG EXPAND.
65 !title "!TOKENS(1) argument."
66 !t1 a.
67 !t1 b.
68 !t1 a b.
69
70 !title "!TOKENS(2) argument."
71 !t2 a b.
72 !t2 b c d.
73
74 !title "!CHAREND argument."
75 !ce/.
76 !ce x/.
77 !ce x y/.
78 !ce x y z/.
79
80 !title "Two !CHAREND arguments."
81 !ce2 x(y).
82 !ce2 1 2 3 4().
83
84 !title "!ENCLOSE argument."
85 !e {}.
86 !e {a}.
87 !e {a b}.
88
89 !title "!CMDEND argument."
90 !cmd 1 2 3 4.
91 !cmd2 5 6.
92 7.
93 ])
94 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
95 "!TOKENS(1) argument."
96
97 t1(a)
98
99 t1(b)
100
101 t1(a)
102
103 note: unexpanded token "b"
104
105 "!TOKENS(2) argument."
106
107 t2(a b)
108
109 t2(b c)
110
111 note: unexpanded token "d"
112
113 "!CHAREND argument."
114
115 ce( )
116
117 ce(x)
118
119 ce(x y)
120
121 ce(x y z)
122
123 "Two !CHAREND arguments."
124
125 ce2(x, y)
126
127 ce2(1 2 3 4, )
128
129 "!ENCLOSE argument."
130
131 e( )
132
133 e(a)
134
135 e(a b)
136
137 "!CMDEND argument."
138
139 cmd(1 2 3 4)
140
141 cmd2(5 6, 7)
142 ])
143 AT_CLEANUP