Move all command implementations into a single 'commands' directory.
[pspp] / tests / language / commands / 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
17 AT_BANNER([DATA LIST])
18
19 AT_SETUP([DATA LIST LIST with empty fields])
20 AT_DATA([data-list.pspp], [dnl
21 DATA LIST LIST NOTABLE /A B C (F1.0).
22 BEGIN DATA.
23 ,,
24 ,,3
25 ,2,
26 ,2,3
27 1,,
28 1,,3
29 1,2,
30 1,2,3
31 END DATA.
32
33 LIST.
34 ])
35 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
36 Table: Data List
37 A,B,C
38 .,.,.
39 .,.,3
40 .,2,.
41 .,2,3
42 1,.,.
43 1,.,3
44 1,2,.
45 1,2,3
46 ])
47 AT_CLEANUP
48
49
50 AT_SETUP([DATA LIST LIST with explicit delimiters])
51 AT_DATA([data-list.pspp], [dnl
52 data list list ('|','X') /A B C D.
53 begin data.
54 1|23X45|2.03x
55 2X22|34|23|
56 3|34|34X34
57 end data.
58
59 list.
60 ])
61 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
62 Table: Reading free-form data from INLINE.
63 Variable,Format
64 A,F8.0
65 B,F8.0
66 C,F8.0
67 D,F8.0
68
69 data-list.pspp:3.9-3.13: warning: Data for variable D is not valid as format F: Number followed by garbage.
70
71 Table: Data List
72 A,B,C,D
73 1.00,23.00,45.00,.  @&t@
74 2.00,22.00,34.00,23.00
75 3.00,34.00,34.00,34.00
76 ])
77 AT_CLEANUP
78
79 AT_SETUP([DATA LIST FREE with SKIP])
80 AT_DATA([data-list.pspp], [dnl
81 data list free skip=1/A B C D.
82 begin data.
83 # This record is ignored.
84 ,1,2,x
85 ,4,,5
86 6
87 7,
88 8 9
89 0,1 ,,,
90 ,,,,
91 2
92
93 3
94 4
95 5
96 end data.
97 list.
98 ])
99 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
100 data-list.pspp:4.6: warning: Data for variable D is not valid as format F: Field contents are not numeric.
101
102 Table: Data List
103 A,B,C,D
104 .  ,1.00,2.00,.  @&t@
105 .  ,4.00,.  ,5.00
106 6.00,7.00,8.00,9.00
107 .00,1.00,.  ,.  @&t@
108 .  ,.  ,.  ,.  @&t@
109 2.00,3.00,4.00,5.00
110 ])
111 AT_CLEANUP
112
113 AT_SETUP([DATA LIST LIST with SKIP and tab delimiter])
114 AT_DATA([data-list.pspp], [dnl
115 data list list (tab) notable skip=2/A B C D.
116 begin data.
117 # These records
118 # are skipped.
119 1       2       3       4
120 1       2       3       @&t@
121 1       2               4
122 1       2               @&t@
123 1               3       4
124 1               3       @&t@
125 1                       4
126 1                       @&t@
127         2       3       4
128         2       3       @&t@
129         2               4
130         2               @&t@
131                 3       4
132                 3       @&t@
133                         4
134                         @&t@
135 end data.
136 list.
137 ])
138 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
139 Table: Data List
140 A,B,C,D
141 1.00,2.00,3.00,4.00
142 1.00,2.00,3.00,.  @&t@
143 1.00,2.00,.  ,4.00
144 1.00,2.00,.  ,.  @&t@
145 1.00,.  ,3.00,4.00
146 1.00,.  ,3.00,.  @&t@
147 1.00,.  ,.  ,4.00
148 1.00,.  ,.  ,.  @&t@
149 .  ,2.00,3.00,4.00
150 .  ,2.00,3.00,.  @&t@
151 .  ,2.00,.  ,4.00
152 .  ,2.00,.  ,.  @&t@
153 .  ,.  ,3.00,4.00
154 .  ,.  ,3.00,.  @&t@
155 .  ,.  ,.  ,4.00
156 .  ,.  ,.  ,.  @&t@
157 ])
158 AT_CLEANUP
159
160 dnl Results of this test were confirmed with SPSS 21:
161 dnl http://lists.gnu.org/archive/html/pspp-dev/2013-09/msg00003.html
162 AT_SETUP([DATA LIST FREE with explicit delimiter at end of line])
163 AT_DATA([data-list.pspp], [dnl
164 DATA LIST FREE(',')/x y z.
165 BEGIN DATA.
166 1,2,3
167 4,5,6
168 7,8,9
169 END DATA.
170 LIST.
171
172 DATA LIST FREE(',')/x y z.
173 BEGIN DATA.
174 11,12,13,
175 14,15,16,
176 17,18,19,
177 END DATA.
178 LIST.
179
180 DATA LIST FREE(TAB)/x y z.
181 BEGIN DATA.
182 21      22      23
183 24      25      26
184 27      28      29
185 END DATA.
186 LIST.
187
188 DATA LIST FREE(TAB)/x y z.
189 BEGIN DATA.
190 31      32      33      @&t@
191 34      35      36      @&t@
192 37      38      39      @&t@
193 END DATA.
194 LIST.
195 ])
196 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
197 Table: Data List
198 x,y,z
199 1.00,2.00,3.00
200 4.00,5.00,6.00
201 7.00,8.00,9.00
202
203 Table: Data List
204 x,y,z
205 11.00,12.00,13.00
206 14.00,15.00,16.00
207 17.00,18.00,19.00
208
209 Table: Data List
210 x,y,z
211 21.00,22.00,23.00
212 24.00,25.00,26.00
213 27.00,28.00,29.00
214
215 Table: Data List
216 x,y,z
217 31.00,32.00,33.00
218 34.00,35.00,36.00
219 37.00,38.00,39.00
220 ])
221 AT_CLEANUP
222
223 AT_SETUP([DATA LIST FIXED with multiple records per case])
224 AT_DATA([data-list.pspp], [dnl
225 data list fixed notable
226         /1 start 1-20 (adate)
227         /2 end 1-20 (adate)
228         /3 count 1-3.
229 begin data.
230 07-22-2007
231 10-06-2007
232 x
233 07-14-1789
234 08-26-1789
235 xy
236 01-01-1972
237 12-31-1999
238 682
239 end data.
240 list.
241 ])
242 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
243 data-list.pspp:8.1-8.3: warning: Data for variable count is not valid as format F: Field contents are not numeric.
244
245 data-list.pspp:11.1-11.3: warning: Data for variable count is not valid as format F: Field contents are not numeric.
246
247 Table: Data List
248 start,end,count
249 07/22/2007,10/06/2007,.
250 07/14/1789,08/26/1789,.
251 01/01/1972,12/31/1999,682
252 ])
253 AT_CLEANUP
254
255 AT_SETUP([DATA LIST FIXED with empty trailing record])
256 AT_DATA([data-list.pspp], [dnl
257 data list fixed notable records=2/x 1 y 2.
258 begin data.
259 12
260
261 34
262
263 56
264
265 78
266
267 90
268
269 end data.
270 list.
271 ])
272 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
273 Table: Data List
274 x,y
275 1,2
276 3,4
277 5,6
278 7,8
279 9,0
280 ])
281 AT_CLEANUP
282
283 dnl Test that PSPP accepts LF and CR LF as line ends, but
284 dnl treats isolated CR as linear whitespace.
285 AT_SETUP([DATA LIST with various line-ends])
286 AT_DATA([data-list.sps], [dnl
287 data list list notable file='input.txt'/a b c.
288 list.
289 ])
290 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
291 dnl Make sure that input.txt actually received the data that we expect.
292 dnl It might not have, if we're running on a system that translates \n
293 dnl into some other sequence.
294 AT_CHECK([cksum input.txt], [0], [1732021750 50 input.txt
295 ])
296 AT_CHECK([pspp -o pspp.csv data-list.sps])
297 AT_CHECK([cat pspp.csv], [0], [dnl
298 Table: Data List
299 a,b,c
300 1.00,2.00,3.00
301 4.00,5.00,6.00
302 7.00,8.00,9.00
303 10.00,11.00,12.00
304 13.00,14.00,15.00
305 16.00,17.00,18.00
306 ])
307 AT_CLEANUP
308
309 AT_SETUP([DATA LIST properly expands tabs in input])
310 AT_DATA([data-list.sps], [dnl
311 data list notable /X 1-50 (a).
312 begin data.
313         1       12      123     1234    12345    .
314 end data.
315 print /x.
316 print outfile='print.txt' /x.
317 write outfile='write.txt' /x.
318 execute.
319 ])
320 AT_CHECK([sed -n '/12345/l' data-list.sps], [0], [dnl
321 \t1\t12\t123\t1234\t12345    .$
322 ])
323 AT_CHECK([pspp -o pspp.csv data-list.sps])
324 dnl The CSV driver drops leading spaces so they don't appear here:
325 AT_CHECK([cat pspp.csv], [0], [dnl
326 1       12      123     1234    12345    . @&t@
327 ])
328 dnl But they do appear in print.txt.  The PRINT command also puts a space
329 dnl at the beginning of the line and after the variable:
330 AT_CHECK([cat print.txt], [0], [dnl
331          1       12      123     1234    12345    . @&t@
332 ])
333 dnl WRITE doesn't add spaces at the beginning or end of lines:
334 AT_CHECK([cat write.txt], [0], [dnl
335         1       12      123     1234    12345    .
336 ])
337 AT_CLEANUP
338
339 AT_SETUP([DATA LIST FREE and LIST report missing delimiters])
340 AT_DATA([data-list.sps], [dnl
341 DATA LIST FREE NOTABLE/s (a10).
342 LIST.
343 BEGIN DATA.
344 'y'z
345 END DATA.
346 ])
347 AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
348 data-list.sps:4: warning: Missing delimiter following quoted string.
349
350 Table: Data List
351 s
352 y
353 z
354 ])
355 AT_CLEANUP
356
357 AT_SETUP([DATA LIST FREE and LIST assume a width if omitted])
358 AT_DATA([data-list.sps], [dnl
359 DATA LIST FREE TABLE/s (a) d (datetime) f (f).
360 ])
361 AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
362 Table: Reading free-form data from INLINE.
363 Variable,Format
364 s,A1
365 d,DATETIME17.0
366 f,F1.0
367 ])
368 AT_CLEANUP
369
370 AT_SETUP([DATA LIST Decimal comma])
371 AT_DATA([data-list.sps], [dnl
372 SET DECIMAL=COMMA.
373
374 DATA LIST NOTABLE LIST /A *.
375 BEGIN DATA
376 1
377 2
378 3
379 3,5
380 4
381 4,5
382 5
383 6
384 END DATA
385
386 LIST /FORMAT=NUMBERED.
387 ])
388
389 AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
390 Table: Data List
391 Case Number,A
392 1,"1,00"
393 2,"2,00"
394 3,"3,00"
395 4,"3,50"
396 5,"4,00"
397 6,"4,50"
398 7,"5,00"
399 8,"6,00"
400 ])
401
402 AT_CLEANUP
403
404 AT_SETUP([DATA LIST syntax errors])
405 AT_DATA([insert.sps], [dnl
406 INSERT FILE='data-list.sps' ERROR=IGNORE.
407 ])
408 AT_DATA([data-list.sps], [dnl
409 DATA LIST FILE=**.
410 DATA LIST ENCODING=**.
411 DATA LIST RECORDS=1 RECORDS=2.
412 DATA LIST RECORDS=0.
413 DATA LIST SKIP=-1.
414 DATA LIST END=**.
415 INPUT PROGRAM.
416 DATA LIST END=xyzzy END=xyzzy.
417 END INPUT PROGRAM.
418 INPUT PROGRAM.
419 DATA LIST END=**.
420 END INPUT PROGRAM.
421 DATA LIST XYZZY.
422 DATA LIST FREE LIST.
423 DATA LIST LIST (**).
424 DATA LIST **.
425 DATA LIST ENCODING='xyzzy'/x.
426 INPUT PROGRAM.
427 DATA LIST LIST END=xyzzy/x.
428 END INPUT PROGRAM.
429 DATA LIST FIXED/0.
430 DATA LIST FIXED/ **.
431 DATA LIST FIXED/x 1.5.
432 DATA LIST FIXED/x -1.
433 DATA LIST FIXED/x 5-3.
434 DATA LIST FIXED/x y 1-3.
435 DATA LIST FIXED/x 1-5 (xyzzy).
436 DATA LIST FIXED/x 1-5 (**).
437 DATA LIST FIXED/x 1 (F,5).
438 DATA LIST FIXED/x (2F8.0).
439 DATA LIST FIXED/x **.
440 DATA LIST FIXED/x 1 x 2.
441 INPUT PROGRAM.
442 DATA LIST FIXED/x 1.
443 DATA LIST FIXED/x 1 (a).
444 END INPUT PROGRAM.
445 INPUT PROGRAM.
446 DATA LIST FIXED/y 2 (a).
447 DATA LIST FIXED/y 3-4 (a).
448 END INPUT PROGRAM.
449 DATA LIST FIXED RECORDS=1/2 x 1-2.
450 ])
451
452 AT_CHECK([pspp --testing-mode -O format=csv insert.sps], [1], [dnl
453 "data-list.sps:1.16-1.17: error: DATA LIST: Syntax error expecting a file name or handle name.
454     1 | DATA LIST FILE=**.
455       |                ^~"
456
457 "data-list.sps:2.20-2.21: error: DATA LIST: Syntax error expecting string.
458     2 | DATA LIST ENCODING=**.
459       |                    ^~"
460
461 "data-list.sps:3.21-3.27: error: DATA LIST: Subcommand RECORDS may only be specified once.
462     3 | DATA LIST RECORDS=1 RECORDS=2.
463       |                     ^~~~~~~"
464
465 "data-list.sps:4.20: error: DATA LIST: Syntax error expecting one of the following: FILE, ENCODING, RECORDS, SKIP, END, NOTABLE, TABLE, FIXED, FREE, LIST.
466     4 | DATA LIST RECORDS=0.
467       |                    ^"
468
469 "data-list.sps:5.16-5.17: error: DATA LIST: Syntax error expecting non-negative integer for SKIP.
470     5 | DATA LIST SKIP=-1.
471       |                ^~"
472
473 "data-list.sps:6.11-6.13: error: DATA LIST: The END subcommand may only be used within INPUT PROGRAM.
474     6 | DATA LIST END=**.
475       |           ^~~"
476
477 "data-list.sps:8.21-8.23: error: DATA LIST: Subcommand END may only be specified once.
478     8 | DATA LIST END=xyzzy END=xyzzy.
479       |                     ^~~"
480
481 "data-list.sps:11.15-11.16: error: DATA LIST: Syntax error expecting identifier.
482    11 | DATA LIST END=**.
483       |               ^~"
484
485 "data-list.sps:13.11-13.15: error: DATA LIST: Syntax error expecting one of the following: FILE, ENCODING, RECORDS, SKIP, END, NOTABLE, TABLE, FIXED, FREE, LIST.
486    13 | DATA LIST XYZZY.
487       |           ^~~~~"
488
489 "data-list.sps:14.16-14.19: error: DATA LIST: Only one of FIXED, FREE, or LIST may be specified.
490    14 | DATA LIST FREE LIST.
491       |                ^~~~"
492
493 "data-list.sps:15.17-15.18: error: DATA LIST: Syntax error expecting TAB or delimiter string.
494    15 | DATA LIST LIST (**).
495       |                 ^~"
496
497 "data-list.sps:16.11-16.12: error: DATA LIST: Syntax error expecting one of the following: FILE, ENCODING, RECORDS, SKIP, END, NOTABLE, TABLE, FIXED, FREE, LIST.
498    16 | DATA LIST **.
499       |           ^~"
500
501 "data-list.sps:17.11-17.26: warning: DATA LIST: Encoding should not be specified for inline data. It will be ignored.
502    17 | DATA LIST ENCODING='xyzzy'/x.
503       |           ^~~~~~~~~~~~~~~~"
504
505 "data-list.sps:17.29: error: DATA LIST: SPSS-like or Fortran-like format specification expected after variable names.
506    17 | DATA LIST ENCODING='xyzzy'/x.
507       |                             ^"
508
509 "data-list.sps:19.16-19.24: error: DATA LIST: The END subcommand may be used only with DATA LIST FIXED.
510    19 | DATA LIST LIST END=xyzzy/x.
511       |                ^~~~~~~~~"
512
513 "data-list.sps:21.17: error: DATA LIST: Syntax error expecting positive integer.
514    21 | DATA LIST FIXED/0.
515       |                 ^"
516
517 "data-list.sps:22.18-22.19: error: DATA LIST: Syntax error expecting variable name.
518    22 | DATA LIST FIXED/ **.
519       |                  ^~"
520
521 "data-list.sps:23.19-23.21: error: DATA LIST: Syntax error expecting integer.
522    23 | DATA LIST FIXED/x 1.5.
523       |                   ^~~"
524
525 "data-list.sps:24.19-24.20: error: DATA LIST: Column positions for fields must be positive.
526    24 | DATA LIST FIXED/x -1.
527       |                   ^~"
528
529 "data-list.sps:25.19-25.21: error: DATA LIST: The ending column for a field must be greater than the starting column.
530    25 | DATA LIST FIXED/x 5-3.
531       |                   ^~~"
532
533 "data-list.sps:26.21-26.23: error: DATA LIST: The 3 columns 1-3 can't be evenly divided into 2 fields.
534    26 | DATA LIST FIXED/x y 1-3.
535       |                     ^~~"
536
537 "data-list.sps:27.24-27.28: error: DATA LIST: Unknown format type `xyzzy'.
538    27 | DATA LIST FIXED/x 1-5 (xyzzy).
539       |                        ^~~~~"
540
541 "data-list.sps:28.24-28.25: error: DATA LIST: Syntax error expecting `)'.
542    28 | DATA LIST FIXED/x 1-5 (**).
543       |                        ^~"
544
545 "data-list.sps:29.19-29.25: error: DATA LIST: Input format F1.5 specifies 5 decimal places, but width 1 allows at most 1 decimals.
546    29 | DATA LIST FIXED/x 1 (F,5).
547       |                   ^~~~~~~"
548
549 "data-list.sps:30.20-30.25: error: DATA LIST: Number of variables specified (1) differs from number of variable formats (2).
550    30 | DATA LIST FIXED/x (2F8.0).
551       |                    ^~~~~~"
552
553 "data-list.sps:31.19-31.20: error: DATA LIST: SPSS-like or Fortran-like format specification expected after variable names.
554    31 | DATA LIST FIXED/x **.
555       |                   ^~"
556
557 "data-list.sps:32.21: error: DATA LIST: x is a duplicate variable name.
558    32 | DATA LIST FIXED/x 1 x 2.
559       |                     ^"
560
561 Table: Reading 1 record from INLINE.
562 Variable,Record,Columns,Format
563 x,1,1-1,F1.0
564
565 "data-list.sps:35.17-35.23: error: DATA LIST: There is already a variable x of a different type.
566    35 | DATA LIST FIXED/x 1 (a).
567       |                 ^~~~~~~"
568
569 Table: Reading 1 record from INLINE.
570 Variable,Record,Columns,Format
571 y,1,2-2,A1
572
573 "data-list.sps:39.17-39.25: error: DATA LIST: There is already a string variable y of a different width.
574    39 | DATA LIST FIXED/y 3-4 (a).
575       |                 ^~~~~~~~~"
576
577 "data-list.sps:41.26-41.29: error: DATA LIST: Cannot place variable x on record 2 when RECORDS=1 is specified.
578    41 | DATA LIST FIXED RECORDS=1/2 x 1-2.
579       |                          ^~~~"
580 ])
581
582 AT_CLEANUP