Add copyright and licence notices to files which lack them.
[pspp] / tests / language / data-io / data-list.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 AT_BANNER([DATA LIST])
17
18 AT_SETUP([DATA LIST LIST with empty fields])
19 AT_DATA([data-list.pspp], [dnl
20 DATA LIST LIST NOTABLE /A B C (F1.0).
21 BEGIN DATA.
22 ,,
23 ,,3
24 ,2,
25 ,2,3
26 1,,
27 1,,3
28 1,2,
29 1,2,3
30 END DATA.
31
32 LIST.
33 ])
34 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
35 Table: Data List
36 A,B,C
37 .,.,.
38 .,.,3
39 .,2,.
40 .,2,3
41 1,.,.
42 1,.,3
43 1,2,.
44 1,2,3
45 ])
46 AT_CLEANUP
47
48
49 AT_SETUP([DATA LIST LIST with explicit delimiters])
50 AT_DATA([data-list.pspp], [dnl
51 data list list ('|','X') /A B C D.
52 begin data.
53 1|23X45|2.03x
54 2X22|34|23|
55 3|34|34X34
56 end data.
57
58 list.
59 ])
60 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
61 Table: Reading free-form data from INLINE.
62 Variable,Format
63 A,F8.0
64 B,F8.0
65 C,F8.0
66 D,F8.0
67
68 data-list.pspp:3.9-3.13: warning: Data for variable D is not valid as format F: Number followed by garbage.
69
70 Table: Data List
71 A,B,C,D
72 1.00,23.00,45.00,.  @&t@
73 2.00,22.00,34.00,23.00
74 3.00,34.00,34.00,34.00
75 ])
76 AT_CLEANUP
77
78 AT_SETUP([DATA LIST FREE with SKIP])
79 AT_DATA([data-list.pspp], [dnl
80 data list free skip=1/A B C D.
81 begin data.
82 # This record is ignored.
83 ,1,2,x
84 ,4,,5
85 6
86 7,
87 8 9
88 0,1 ,,,
89 ,,,,
90 2
91
92 3
93 4
94 5
95 end data.
96 list.
97 ])
98 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
99 data-list.pspp:4.6: warning: Data for variable D is not valid as format F: Field contents are not numeric.
100
101 Table: Data List
102 A,B,C,D
103 .  ,1.00,2.00,.  @&t@
104 .  ,4.00,.  ,5.00
105 6.00,7.00,8.00,9.00
106 .00,1.00,.  ,.  @&t@
107 .  ,.  ,.  ,.  @&t@
108 2.00,3.00,4.00,5.00
109 ])
110 AT_CLEANUP
111
112 AT_SETUP([DATA LIST LIST with SKIP and tab delimiter])
113 AT_DATA([data-list.pspp], [dnl
114 data list list (tab) notable skip=2/A B C D.
115 begin data.
116 # These records
117 # are skipped.
118 1       2       3       4
119 1       2       3       @&t@
120 1       2               4
121 1       2               @&t@
122 1               3       4
123 1               3       @&t@
124 1                       4
125 1                       @&t@
126         2       3       4
127         2       3       @&t@
128         2               4
129         2               @&t@
130                 3       4
131                 3       @&t@
132                         4
133                         @&t@
134 end data.
135 list.
136 ])
137 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
138 Table: Data List
139 A,B,C,D
140 1.00,2.00,3.00,4.00
141 1.00,2.00,3.00,.  @&t@
142 1.00,2.00,.  ,4.00
143 1.00,2.00,.  ,.  @&t@
144 1.00,.  ,3.00,4.00
145 1.00,.  ,3.00,.  @&t@
146 1.00,.  ,.  ,4.00
147 1.00,.  ,.  ,.  @&t@
148 .  ,2.00,3.00,4.00
149 .  ,2.00,3.00,.  @&t@
150 .  ,2.00,.  ,4.00
151 .  ,2.00,.  ,.  @&t@
152 .  ,.  ,3.00,4.00
153 .  ,.  ,3.00,.  @&t@
154 .  ,.  ,.  ,4.00
155 .  ,.  ,.  ,.  @&t@
156 ])
157 AT_CLEANUP
158
159 dnl Results of this test were confirmed with SPSS 21:
160 dnl http://lists.gnu.org/archive/html/pspp-dev/2013-09/msg00003.html
161 AT_SETUP([DATA LIST FREE with explicit delimiter at end of line])
162 AT_DATA([data-list.pspp], [dnl
163 DATA LIST FREE(',')/x y z.
164 BEGIN DATA.
165 1,2,3
166 4,5,6
167 7,8,9
168 END DATA.
169 LIST.
170
171 DATA LIST FREE(',')/x y z.
172 BEGIN DATA.
173 11,12,13,
174 14,15,16,
175 17,18,19,
176 END DATA.
177 LIST.
178
179 DATA LIST FREE(TAB)/x y z.
180 BEGIN DATA.
181 21      22      23
182 24      25      26
183 27      28      29
184 END DATA.
185 LIST.
186
187 DATA LIST FREE(TAB)/x y z.
188 BEGIN DATA.
189 31      32      33      @&t@
190 34      35      36      @&t@
191 37      38      39      @&t@
192 END DATA.
193 LIST.
194 ])
195 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
196 Table: Data List
197 x,y,z
198 1.00,2.00,3.00
199 4.00,5.00,6.00
200 7.00,8.00,9.00
201
202 Table: Data List
203 x,y,z
204 11.00,12.00,13.00
205 14.00,15.00,16.00
206 17.00,18.00,19.00
207
208 Table: Data List
209 x,y,z
210 21.00,22.00,23.00
211 24.00,25.00,26.00
212 27.00,28.00,29.00
213
214 Table: Data List
215 x,y,z
216 31.00,32.00,33.00
217 34.00,35.00,36.00
218 37.00,38.00,39.00
219 ])
220 AT_CLEANUP
221
222 AT_SETUP([DATA LIST FIXED with multiple records per case])
223 AT_DATA([data-list.pspp], [dnl
224 data list fixed notable
225         /1 start 1-20 (adate)
226         /2 end 1-20 (adate)
227         /3 count 1-3.
228 begin data.
229 07-22-2007
230 10-06-2007
231 x
232 07-14-1789
233 08-26-1789
234 xy
235 01-01-1972
236 12-31-1999
237 682
238 end data.
239 list.
240 ])
241 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
242 data-list.pspp:8.1-8.3: warning: Data for variable count is not valid as format F: Field contents are not numeric.
243
244 data-list.pspp:11.1-11.3: warning: Data for variable count is not valid as format F: Field contents are not numeric.
245
246 Table: Data List
247 start,end,count
248 07/22/2007,10/06/2007,.
249 07/14/1789,08/26/1789,.
250 01/01/1972,12/31/1999,682
251 ])
252 AT_CLEANUP
253
254 AT_SETUP([DATA LIST FIXED with empty trailing record])
255 AT_DATA([data-list.pspp], [dnl
256 data list fixed notable records=2/x 1 y 2.
257 begin data.
258 12
259
260 34
261
262 56
263
264 78
265
266 90
267
268 end data.
269 list.
270 ])
271 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
272 Table: Data List
273 x,y
274 1,2
275 3,4
276 5,6
277 7,8
278 9,0
279 ])
280 AT_CLEANUP
281
282 dnl Test that PSPP accepts LF and CR LF as line ends, but
283 dnl treats isolated CR as linear whitespace.
284 AT_SETUP([DATA LIST with various line-ends])
285 AT_DATA([data-list.sps], [dnl
286 data list list notable file='input.txt'/a b c.
287 list.
288 ])
289 printf '1 2 3\n4 5 6\r\n7\r8\r9\r\n10 11 12\n13 14 15 \r\n16\r\r17\r18\n' > input.txt
290 dnl Make sure that input.txt actually received the data that we expect.
291 dnl It might not have, if we're running on a system that translates \n
292 dnl into some other sequence.
293 AT_CHECK([cksum input.txt], [0], [1732021750 50 input.txt
294 ])
295 AT_CHECK([pspp -o pspp.csv data-list.sps])
296 AT_CHECK([cat pspp.csv], [0], [dnl
297 Table: Data List
298 a,b,c
299 1.00,2.00,3.00
300 4.00,5.00,6.00
301 7.00,8.00,9.00
302 10.00,11.00,12.00
303 13.00,14.00,15.00
304 16.00,17.00,18.00
305 ])
306 AT_CLEANUP
307
308 AT_SETUP([DATA LIST properly expands tabs in input])
309 AT_DATA([data-list.sps], [dnl
310 data list notable /X 1-50 (a).
311 begin data.
312         1       12      123     1234    12345    .
313 end data.
314 print /x.
315 print outfile='print.txt' /x.
316 write outfile='write.txt' /x.
317 execute.
318 ])
319 AT_CHECK([sed -n '/12345/l' data-list.sps], [0], [dnl
320 \t1\t12\t123\t1234\t12345    .$
321 ])
322 AT_CHECK([pspp -o pspp.csv data-list.sps])
323 dnl The CSV driver drops leading spaces so they don't appear here:
324 AT_CHECK([cat pspp.csv], [0], [dnl
325 1       12      123     1234    12345    . @&t@
326 ])
327 dnl But they do appear in print.txt.  The PRINT command also puts a space
328 dnl at the beginning of the line and after the variable:
329 AT_CHECK([cat print.txt], [0], [dnl
330          1       12      123     1234    12345    . @&t@
331 ])
332 dnl WRITE doesn't add spaces at the beginning or end of lines:
333 AT_CHECK([cat write.txt], [0], [dnl
334         1       12      123     1234    12345    .
335 ])
336 AT_CLEANUP
337
338 AT_SETUP([DATA LIST FREE and LIST report missing delimiters])
339 AT_DATA([data-list.sps], [dnl
340 DATA LIST FREE NOTABLE/s (a10).
341 LIST.
342 BEGIN DATA.
343 'y'z
344 END DATA.
345 ])
346 AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
347 data-list.sps:4: warning: Missing delimiter following quoted string.
348
349 Table: Data List
350 s
351 y         @&t@
352 z         @&t@
353 ])
354 AT_CLEANUP
355
356 AT_SETUP([DATA LIST FREE and LIST assume a width if omitted])
357 AT_DATA([data-list.sps], [dnl
358 DATA LIST FREE TABLE/s (a) d (datetime) f (f).
359 ])
360 AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
361 Table: Reading free-form data from INLINE.
362 Variable,Format
363 s,A1
364 d,DATETIME17.0
365 f,F1.0
366 ])
367 AT_CLEANUP
368
369 AT_SETUP([DATA LIST Decimal comma])
370 AT_DATA([data-list.sps], [dnl
371 SET DECIMAL=COMMA.
372
373 DATA LIST NOTABLE LIST /A *.
374 BEGIN DATA
375 1
376 2
377 3
378 3,5
379 4
380 4,5
381 5
382 6
383 END DATA
384
385 LIST /FORMAT=NUMBERED.
386 ])
387
388 AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
389 Table: Data List
390 Case Number,A
391 1,"1,00"
392 2,"2,00"
393 3,"3,00"
394 4,"3,50"
395 5,"4,00"
396 6,"4,50"
397 7,"5,00"
398 8,"6,00"
399 ])
400
401 AT_CLEANUP
402
403
404 AT_SETUP([DATA LIST - Negative SKIP])
405 AT_DATA([data-list.sps], [dnl
406 DATA LIST LIST FILE='f.in' NOTABLE SKIP=-1 /a b c d.
407
408 EXECUTE.
409 ])
410
411 AT_CHECK([pspp -O format=csv data-list.sps], [1], [dnl
412 data-list.sps:1: error: DATA LIST: The SKIP value must be nonnegative.
413
414 data-list.sps:3: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
415 ])
416
417 AT_CLEANUP
418
419
420 AT_SETUP([DATA LIST - Negative RECORDS])
421 AT_DATA([data-list.sps], [dnl
422 DATA LIST LIST FILE='f.in' NOTABLE RECORDS=-1 /a b c d.
423
424 EXECUTE.
425 ])
426
427 AT_CHECK([pspp -O format=csv data-list.sps], [1], [dnl
428 data-list.sps:1: error: DATA LIST: The RECORDS value must be nonnegative.
429
430 data-list.sps:3: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
431 ])
432
433 AT_CLEANUP
434