1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
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.
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.
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/>.
17 AT_BANNER([DATA LIST])
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).
35 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
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.
61 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
62 Table: Reading free-form data from INLINE.
69 data-list.pspp:3.9-3.13: warning: Data for variable D is not valid as format F: Number followed by garbage.
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
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.
83 # This record is ignored.
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.
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.
138 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
142 1.00,2.00,3.00,. @&t@
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.
172 DATA LIST FREE(',')/x y z.
180 DATA LIST FREE(TAB)/x y z.
188 DATA LIST FREE(TAB)/x y z.
196 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
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)
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.
245 data-list.pspp:11.1-11.3: warning: Data for variable count is not valid as format F: Field contents are not numeric.
249 07/22/2007,10/06/2007,.
250 07/14/1789,08/26/1789,.
251 01/01/1972,12/31/1999,682
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.
272 AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
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.
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
296 AT_CHECK([pspp -o pspp.csv data-list.sps])
297 AT_CHECK([cat pspp.csv], [0], [dnl
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).
313 1 12 123 1234 12345 .
316 print outfile='print.txt' /x.
317 write outfile='write.txt' /x.
320 AT_CHECK([sed -n '/12345/l' data-list.sps], [0], [dnl
321 \t1\t12\t123\t1234\t12345 .$
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@
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@
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 .
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).
347 AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
348 data-list.sps:4: warning: Missing delimiter following quoted string.
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).
361 AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
362 Table: Reading free-form data from INLINE.
370 AT_SETUP([DATA LIST Decimal comma])
371 AT_DATA([data-list.sps], [dnl
374 DATA LIST NOTABLE LIST /A *.
386 LIST /FORMAT=NUMBERED.
389 AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
404 AT_SETUP([DATA LIST syntax errors])
405 AT_DATA([insert.sps], [dnl
406 INSERT FILE='data-list.sps' ERROR=IGNORE.
408 AT_DATA([data-list.sps], [dnl
410 DATA LIST ENCODING=**.
411 DATA LIST RECORDS=1 RECORDS=2.
416 DATA LIST END=xyzzy END=xyzzy.
425 DATA LIST ENCODING='xyzzy'/x.
427 DATA LIST LIST END=xyzzy/x.
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.
443 DATA LIST FIXED/x 1 (a).
446 DATA LIST FIXED/y 2 (a).
447 DATA LIST FIXED/y 3-4 (a).
449 DATA LIST FIXED RECORDS=1/x y(F2/F3).
450 DATA LIST FIXED RECORDS=1//.
451 DATA LIST FIXED RECORDS=1/.
454 AT_CHECK([pspp --testing-mode -O format=csv insert.sps], [1], [dnl
455 "data-list.sps:1.16-1.17: error: DATA LIST: Syntax error expecting a file name or handle name.
456 1 | DATA LIST FILE=**.
459 "data-list.sps:2.20-2.21: error: DATA LIST: Syntax error expecting string.
460 2 | DATA LIST ENCODING=**.
463 "data-list.sps:3.21-3.27: error: DATA LIST: Subcommand RECORDS may only be specified once.
464 3 | DATA LIST RECORDS=1 RECORDS=2.
467 "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.
468 4 | DATA LIST RECORDS=0.
471 "data-list.sps:5.16-5.17: error: DATA LIST: Syntax error expecting non-negative integer for SKIP.
472 5 | DATA LIST SKIP=-1.
475 "data-list.sps:6.11-6.13: error: DATA LIST: The END subcommand may only be used within INPUT PROGRAM.
476 6 | DATA LIST END=**.
479 "data-list.sps:8.21-8.23: error: DATA LIST: Subcommand END may only be specified once.
480 8 | DATA LIST END=xyzzy END=xyzzy.
483 "data-list.sps:11.15-11.16: error: DATA LIST: Syntax error expecting identifier.
484 11 | DATA LIST END=**.
487 "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.
488 13 | DATA LIST XYZZY.
491 "data-list.sps:14.16-14.19: error: DATA LIST: Only one of FIXED, FREE, or LIST may be specified.
492 14 | DATA LIST FREE LIST.
495 "data-list.sps:15.17-15.18: error: DATA LIST: Syntax error expecting TAB or delimiter string.
496 15 | DATA LIST LIST (**).
499 "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.
503 "data-list.sps:17.11-17.26: warning: DATA LIST: Encoding should not be specified for inline data. It will be ignored.
504 17 | DATA LIST ENCODING='xyzzy'/x.
507 "data-list.sps:17.29: error: DATA LIST: SPSS-like or Fortran-like format specification expected after variable names.
508 17 | DATA LIST ENCODING='xyzzy'/x.
511 "data-list.sps:19.16-19.24: error: DATA LIST: The END subcommand may be used only with DATA LIST FIXED.
512 19 | DATA LIST LIST END=xyzzy/x.
515 "data-list.sps:21.17: error: DATA LIST: Syntax error expecting positive integer.
516 21 | DATA LIST FIXED/0.
519 "data-list.sps:22.18-22.19: error: DATA LIST: Syntax error expecting variable name.
520 22 | DATA LIST FIXED/ **.
523 "data-list.sps:23.19-23.21: error: DATA LIST: Syntax error expecting integer.
524 23 | DATA LIST FIXED/x 1.5.
527 "data-list.sps:24.19-24.20: error: DATA LIST: Column positions for fields must be positive.
528 24 | DATA LIST FIXED/x -1.
531 "data-list.sps:25.19-25.21: error: DATA LIST: The ending column for a field must be greater than the starting column.
532 25 | DATA LIST FIXED/x 5-3.
535 "data-list.sps:26.21-26.23: error: DATA LIST: The 3 columns 1-3 can't be evenly divided into 2 fields.
536 26 | DATA LIST FIXED/x y 1-3.
539 "data-list.sps:27.24-27.28: error: DATA LIST: Unknown format type `xyzzy'.
540 27 | DATA LIST FIXED/x 1-5 (xyzzy).
543 "data-list.sps:28.24-28.25: error: DATA LIST: Syntax error expecting `)'.
544 28 | DATA LIST FIXED/x 1-5 (**).
547 "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.
548 29 | DATA LIST FIXED/x 1 (F,5).
551 "data-list.sps:30.20-30.25: error: DATA LIST: Number of variables specified (1) differs from number of variable formats (2).
552 30 | DATA LIST FIXED/x (2F8.0).
555 "data-list.sps:31.19-31.20: error: DATA LIST: SPSS-like or Fortran-like format specification expected after variable names.
556 31 | DATA LIST FIXED/x **.
559 "data-list.sps:32.21: error: DATA LIST: x is a duplicate variable name.
560 32 | DATA LIST FIXED/x 1 x 2.
563 Table: Reading 1 record from INLINE.
564 Variable,Record,Columns,Format
567 "data-list.sps:35.17-35.23: error: DATA LIST: There is already a variable x of a different type.
568 35 | DATA LIST FIXED/x 1 (a).
571 Table: Reading 1 record from INLINE.
572 Variable,Record,Columns,Format
575 "data-list.sps:39.17-39.25: error: DATA LIST: There is already a string variable y of a different width.
576 39 | DATA LIST FIXED/y 3-4 (a).
579 "data-list.sps:41.27-41.36: error: DATA LIST: Cannot place variable y on record 2 when RECORDS=1 is specified.
580 41 | DATA LIST FIXED RECORDS=1/x y(F2/F3).
583 "data-list.sps:42.27: error: DATA LIST: Cannot advance to record 2 when RECORDS=1 is specified.
584 42 | DATA LIST FIXED RECORDS=1//.
587 "data-list.sps:43.26: error: DATA LIST: No fields were specified. At least one is required.
588 43 | DATA LIST FIXED RECORDS=1/.
593 AT_SETUP([DATA LIST FIXED manual example 1])
594 AT_DATA([data-list.sps], [dnl
595 DATA LIST TABLE /NAME 1-10 (A) INFO1 TO INFO3 12-17 (1).
605 AT_CHECK([pspp data-list.sps -O box=unicode], [0], [dnl
606 Reading 1 record from INLINE.
607 ╭────────┬──────┬───────┬──────╮
608 │Variable│Record│Columns│Format│
609 ├────────┼──────┼───────┼──────┤
610 │NAME │ 1│1-10 │A10 │
611 │INFO1 │ 1│12-13 │F2.1 │
612 │INFO2 │ 1│14-15 │F2.1 │
613 │INFO3 │ 1│16-17 │F2.1 │
614 ╰────────┴──────┴───────┴──────╯
617 ╭──────────┬─────┬─────┬─────╮
618 │ NAME │INFO1│INFO2│INFO3│
619 ├──────────┼─────┼─────┼─────┤
620 │John Smith│ 1.0│ 2.3│ 1.1│
621 │Bob Arnold│ 1.2│ 2.0│ 1.5│
622 │Bill Yates│ .9│ 1.8│ .6│
623 ╰──────────┴─────┴─────┴─────╯
627 AT_SETUP([DATA LIST FIXED manual example 2])
628 AT_DATA([data-list.sps], [dnl
630 /ID 1-5 NAME 7-36 (A) SURNAME 38-67 (A) MINITIAL 69 (A)
634 AT_CHECK([pspp data-list.sps -O box=unicode], [0], [dnl
635 Reading 3 records from INLINE.
636 ╭────────┬──────┬───────┬──────╮
637 │Variable│Record│Columns│Format│
638 ├────────┼──────┼───────┼──────┤
640 │NAME │ 1│7-36 │A30 │
641 │SURNAME │ 1│38-67 │A30 │
642 │MINITIAL│ 1│69-69 │A1 │
646 │Q04 │ 2│10-10 │F1.0 │
647 │Q05 │ 2│11-11 │F1.0 │
648 │Q06 │ 2│12-12 │F1.0 │
649 │Q07 │ 2│13-13 │F1.0 │
650 │Q08 │ 2│14-14 │F1.0 │
651 │Q09 │ 2│15-15 │F1.0 │
652 │Q10 │ 2│16-16 │F1.0 │
653 │Q11 │ 2│17-17 │F1.0 │
654 │Q12 │ 2│18-18 │F1.0 │
655 │Q13 │ 2│19-19 │F1.0 │
656 │Q14 │ 2│20-20 │F1.0 │
657 │Q15 │ 2│21-21 │F1.0 │
658 │Q16 │ 2│22-22 │F1.0 │
659 │Q17 │ 2│23-23 │F1.0 │
660 │Q18 │ 2│24-24 │F1.0 │
661 │Q19 │ 2│25-25 │F1.0 │
662 │Q20 │ 2│26-26 │F1.0 │
663 │Q21 │ 2│27-27 │F1.0 │
664 │Q22 │ 2│28-28 │F1.0 │
665 │Q23 │ 2│29-29 │F1.0 │
666 │Q24 │ 2│30-30 │F1.0 │
667 │Q25 │ 2│31-31 │F1.0 │
668 │Q26 │ 2│32-32 │F1.0 │
669 │Q27 │ 2│33-33 │F1.0 │
670 │Q28 │ 2│34-34 │F1.0 │
671 │Q29 │ 2│35-35 │F1.0 │
672 │Q30 │ 2│36-36 │F1.0 │
673 │Q31 │ 2│37-37 │F1.0 │
674 │Q32 │ 2│38-38 │F1.0 │
675 │Q33 │ 2│39-39 │F1.0 │
676 │Q34 │ 2│40-40 │F1.0 │
677 │Q35 │ 2│41-41 │F1.0 │
678 │Q36 │ 2│42-42 │F1.0 │
679 │Q37 │ 2│43-43 │F1.0 │
680 │Q38 │ 2│44-44 │F1.0 │
681 │Q39 │ 2│45-45 │F1.0 │
682 │Q40 │ 2│46-46 │F1.0 │
683 │Q41 │ 2│47-47 │F1.0 │
684 │Q42 │ 2│48-48 │F1.0 │
685 │Q43 │ 2│49-49 │F1.0 │
686 │Q44 │ 2│50-50 │F1.0 │
687 │Q45 │ 2│51-51 │F1.0 │
688 │Q46 │ 2│52-52 │F1.0 │
689 │Q47 │ 2│53-53 │F1.0 │
690 │Q48 │ 2│54-54 │F1.0 │
691 │Q49 │ 2│55-55 │F1.0 │
692 │Q50 │ 2│56-56 │F1.0 │
693 ╰────────┴──────┴───────┴──────╯