22ffaa90a5f5c2c5ccd75f6f9096855e30ed2c92
[pspp] / tests / language / control / do-repeat.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([DO REPEAT])
18
19 AT_SETUP([DO REPEAT -- simple])
20 AT_DATA([do-repeat.sps], [dnl
21 INPUT PROGRAM.
22 STRING y(A1).
23 DO REPEAT xval = 1 2 3 / yval = 'a' 'b' 'c' / var = a b c.
24 COMPUTE x=xval.
25 COMPUTE y=yval.
26 COMPUTE var=xval.
27 END CASE.
28 END REPEAT.
29 END FILE.
30 END INPUT PROGRAM.
31 LIST.
32 ])
33 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
34 AT_CHECK([cat pspp.csv], [0], [dnl
35 Table: Data List
36 y,x,a,b,c
37 a,1.00,1.00,.  ,.  @&t@
38 b,2.00,.  ,2.00,.  @&t@
39 c,3.00,.  ,.  ,3.00
40 ])
41 AT_CLEANUP
42
43 AT_SETUP([DO REPEAT -- containing BEGIN DATA])
44 AT_DATA([do-repeat.sps], [dnl
45 DO REPEAT offset = 1 2 3.
46 DATA LIST NOTABLE /x 1-2.
47 BEGIN DATA.
48 10
49 20
50 30
51 END DATA.
52 COMPUTE x = x + offset.
53 LIST.
54 END REPEAT.
55 ])
56 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
57 AT_CHECK([cat pspp.csv], [0], [dnl
58 Table: Data List
59 x
60 11
61 21
62 31
63
64 Table: Data List
65 x
66 12
67 22
68 32
69
70 Table: Data List
71 x
72 13
73 23
74 33
75 ])
76 AT_CLEANUP
77
78 AT_SETUP([DO REPEAT -- dummy vars not expanded in include files])
79 AT_DATA([include.sps], [dnl
80 COMPUTE y = y + x + 10.
81 ])
82 AT_DATA([do-repeat.sps], [dnl
83 INPUT PROGRAM.
84 COMPUTE x = 0.
85 COMPUTE y = 0.
86 END CASE.
87 END FILE.
88 END INPUT PROGRAM.
89
90 DO REPEAT x = 1 2 3.
91 INCLUDE include.sps.
92 END REPEAT.
93
94 LIST.
95 ])
96 AT_CHECK([pspp -o pspp.csv do-repeat.sps], [0], [dnl
97 do-repeat.sps:8.11: warning: DO REPEAT: Dummy variable name `x' hides dictionary variable `x'.
98     8 | DO REPEAT x = 1 2 3.
99       |           ^
100 ])
101 AT_CHECK([cat pspp.csv], [0], [dnl
102 "do-repeat.sps:8.11: warning: DO REPEAT: Dummy variable name `x' hides dictionary variable `x'.
103     8 | DO REPEAT x = 1 2 3.
104       |           ^"
105
106 Table: Data List
107 x,y
108 .00,30.00
109 ])
110 AT_CLEANUP
111
112 AT_SETUP([DO REPEAT -- nested])
113 AT_DATA([do-repeat.sps], [dnl
114 DATA LIST NOTABLE /a 1.
115 BEGIN DATA.
116 0
117 END DATA.
118
119 DO REPEAT h = h0 TO h3 / x = 0 TO 3 / y = 8, 7.5, 6, 5.
120         COMPUTE h = x + y.
121 END REPEAT.
122
123 VECTOR v(6).
124 COMPUTE #idx = 0.
125 DO REPEAT i = 1 TO 2.
126         DO REPEAT j = 3 TO 5.
127                 COMPUTE #x = i + j.
128                 COMPUTE #idx = #idx + 1.
129                 COMPUTE v(#idx) = #x.
130         END REPEAT.
131 END REPEAT.
132
133 LIST.
134 ])
135 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
136 AT_CHECK([cat pspp.csv], [0], [dnl
137 Table: Data List
138 a,h0,h1,h2,h3,v1,v2,v3,v4,v5,v6
139 0,8.00,8.50,8.00,8.00,4.00,5.00,6.00,5.00,6.00,7.00
140 ])
141 AT_CLEANUP
142
143 dnl This program tests for a bug that crashed PSPP given an empty DO
144 dnl REPEAT...END REPEAT block.  See bug #18407.
145 AT_SETUP([DO REPEAT -- empty])
146 AT_DATA([do-repeat.sps], [dnl
147 DATA LIST NOTABLE /a 1.
148 BEGIN DATA.
149 0
150 END DATA.
151
152 DO REPEAT h = a.
153 END REPEAT.
154 ])
155 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
156 AT_CHECK([cat pspp.csv], [0], [dnl
157 ])
158 AT_CLEANUP
159
160 dnl This program tests for a bug that crashed PSPP when END REPEAT
161 dnl was missing.  See bug #31016.
162 AT_SETUP([DO REPEAT -- missing END REPEAT])
163 AT_DATA([do-repeat.sps], [dnl
164 DATA LIST NOTABLE /x 1.
165 DO REPEAT y = 1 TO 10.
166 ])
167 AT_CHECK([pspp -O format=csv do-repeat.sps], [1], [dnl
168 error: DO REPEAT: At end of input: Syntax error expecting END.
169 ])
170 AT_CLEANUP