1dnl PSPP - a program for statistical analysis.
2dnl Copyright (C) 2017 Free Software Foundation, Inc.
3dnl
4dnl This program is free software: you can redistribute it and/or modify
5dnl it under the terms of the GNU General Public License as published by
6dnl the Free Software Foundation, either version 3 of the License, or
7dnl (at your option) any later version.
8dnl
9dnl This program is distributed in the hope that it will be useful,
10dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12dnl GNU General Public License for more details.
13dnl
14dnl You should have received a copy of the GNU General Public License
15dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16dnl
17AT_BANNER([DATA LIST])
18
19AT_SETUP([DATA LIST LIST with empty fields])
20AT_DATA([data-list.pspp], [dnl
21DATA LIST LIST NOTABLE /A B C (F1.0).
22BEGIN DATA.
23,,
24,,3
25,2,
26,2,3
271,,
281,,3
291,2,
301,2,3
31END DATA.
32
33LIST.
34])
35AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
36Table: Data List
37A,B,C
38.,.,.
39.,.,3
40.,2,.
41.,2,3
421,.,.
431,.,3
441,2,.
451,2,3
46])
47AT_CLEANUP
48
49
50AT_SETUP([DATA LIST LIST with explicit delimiters])
51AT_DATA([data-list.pspp], [dnl
52data list list ('|','X') /A B C D.
53begin data.
541|23X45|2.03x
552X22|34|23|
563|34|34X34
57end data.
58
59list.
60])
61AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
62Table: Reading free-form data from INLINE.
63Variable,Format
64A,F8.0
65B,F8.0
66C,F8.0
67D,F8.0
68
69data-list.pspp:3.9-3.13: warning: Data for variable D is not valid as format F: Number followed by garbage.
70
71Table: Data List
72A,B,C,D
731.00,23.00,45.00,.  @&t@
742.00,22.00,34.00,23.00
753.00,34.00,34.00,34.00
76])
77AT_CLEANUP
78
79AT_SETUP([DATA LIST FREE with SKIP])
80AT_DATA([data-list.pspp], [dnl
81data list free skip=1/A B C D.
82begin data.
83# This record is ignored.
84,1,2,x
85,4,,5
866
877,
888 9
890,1 ,,,
90,,,,
912
92
933
944
955
96end data.
97list.
98])
99AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
100data-list.pspp:4.6: warning: Data for variable D is not valid as format F: Field contents are not numeric.
101
102Table: Data List
103A,B,C,D
104.  ,1.00,2.00,.  @&t@
105.  ,4.00,.  ,5.00
1066.00,7.00,8.00,9.00
107.00,1.00,.  ,.  @&t@
108.  ,.  ,.  ,.  @&t@
1092.00,3.00,4.00,5.00
110])
111AT_CLEANUP
112
113AT_SETUP([DATA LIST LIST with SKIP and tab delimiter])
114AT_DATA([data-list.pspp], [dnl
115data list list (tab) notable skip=2/A B C D.
116begin data.
117# These records
118# are skipped.
1191	2	3	4
1201	2	3	@&t@
1211	2		4
1221	2		@&t@
1231		3	4
1241		3	@&t@
1251			4
1261			@&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@
135end data.
136list.
137])
138AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
139Table: Data List
140A,B,C,D
1411.00,2.00,3.00,4.00
1421.00,2.00,3.00,.  @&t@
1431.00,2.00,.  ,4.00
1441.00,2.00,.  ,.  @&t@
1451.00,.  ,3.00,4.00
1461.00,.  ,3.00,.  @&t@
1471.00,.  ,.  ,4.00
1481.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])
158AT_CLEANUP
159
160dnl Results of this test were confirmed with SPSS 21:
161dnl http://lists.gnu.org/archive/html/pspp-dev/2013-09/msg00003.html
162AT_SETUP([DATA LIST FREE with explicit delimiter at end of line])
163AT_DATA([data-list.pspp], [dnl
164DATA LIST FREE(',')/x y z.
165BEGIN DATA.
1661,2,3
1674,5,6
1687,8,9
169END DATA.
170LIST.
171
172DATA LIST FREE(',')/x y z.
173BEGIN DATA.
17411,12,13,
17514,15,16,
17617,18,19,
177END DATA.
178LIST.
179
180DATA LIST FREE(TAB)/x y z.
181BEGIN DATA.
18221	22	23
18324	25	26
18427	28	29
185END DATA.
186LIST.
187
188DATA LIST FREE(TAB)/x y z.
189BEGIN DATA.
19031	32	33	@&t@
19134	35	36	@&t@
19237	38	39	@&t@
193END DATA.
194LIST.
195])
196AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
197Table: Data List
198x,y,z
1991.00,2.00,3.00
2004.00,5.00,6.00
2017.00,8.00,9.00
202
203Table: Data List
204x,y,z
20511.00,12.00,13.00
20614.00,15.00,16.00
20717.00,18.00,19.00
208
209Table: Data List
210x,y,z
21121.00,22.00,23.00
21224.00,25.00,26.00
21327.00,28.00,29.00
214
215Table: Data List
216x,y,z
21731.00,32.00,33.00
21834.00,35.00,36.00
21937.00,38.00,39.00
220])
221AT_CLEANUP
222
223AT_SETUP([DATA LIST FIXED with multiple records per case])
224AT_DATA([data-list.pspp], [dnl
225data list fixed notable
226        /1 start 1-20 (adate)
227        /2 end 1-20 (adate)
228        /3 count 1-3.
229begin data.
23007-22-2007
23110-06-2007
232x
23307-14-1789
23408-26-1789
235xy
23601-01-1972
23712-31-1999
238682
239end data.
240list.
241])
242AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
243data-list.pspp:8.1-8.3: warning: Data for variable count is not valid as format F: Field contents are not numeric.
244
245data-list.pspp:11.1-11.3: warning: Data for variable count is not valid as format F: Field contents are not numeric.
246
247Table: Data List
248start,end,count
24907/22/2007,10/06/2007,.
25007/14/1789,08/26/1789,.
25101/01/1972,12/31/1999,682
252])
253AT_CLEANUP
254
255AT_SETUP([DATA LIST FIXED with empty trailing record])
256AT_DATA([data-list.pspp], [dnl
257data list fixed notable records=2/x 1 y 2.
258begin data.
25912
260
26134
262
26356
264
26578
266
26790
268
269end data.
270list.
271])
272AT_CHECK([pspp -O format=csv data-list.pspp], [0], [dnl
273Table: Data List
274x,y
2751,2
2763,4
2775,6
2787,8
2799,0
280])
281AT_CLEANUP
282
283dnl Test that PSPP accepts LF and CR LF as line ends, but
284dnl treats isolated CR as linear whitespace.
285AT_SETUP([DATA LIST with various line-ends])
286AT_DATA([data-list.sps], [dnl
287data list list notable file='input.txt'/a b c.
288list.
289])
290printf '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
291dnl Make sure that input.txt actually received the data that we expect.
292dnl It might not have, if we're running on a system that translates \n
293dnl into some other sequence.
294AT_CHECK([cksum input.txt], [0], [1732021750 50 input.txt
295])
296AT_CHECK([pspp -o pspp.csv data-list.sps])
297AT_CHECK([cat pspp.csv], [0], [dnl
298Table: Data List
299a,b,c
3001.00,2.00,3.00
3014.00,5.00,6.00
3027.00,8.00,9.00
30310.00,11.00,12.00
30413.00,14.00,15.00
30516.00,17.00,18.00
306])
307AT_CLEANUP
308
309AT_SETUP([DATA LIST properly expands tabs in input])
310AT_DATA([data-list.sps], [dnl
311data list notable /X 1-50 (a).
312begin data.
313	1	12	123	1234	12345    .
314end data.
315print /x.
316print outfile='print.txt' /x.
317write outfile='write.txt' /x.
318execute.
319])
320AT_CHECK([sed -n '/12345/l' data-list.sps], [0], [dnl
321\t1\t12\t123\t1234\t12345    .$
322])
323AT_CHECK([pspp -o pspp.csv data-list.sps])
324dnl The CSV driver drops leading spaces so they don't appear here:
325AT_CHECK([cat pspp.csv], [0], [dnl
3261       12      123     1234    12345    . @&t@
327])
328dnl But they do appear in print.txt.  The PRINT command also puts a space
329dnl at the beginning of the line and after the variable:
330AT_CHECK([cat print.txt], [0], [dnl
331         1       12      123     1234    12345    . @&t@
332])
333dnl WRITE doesn't add spaces at the beginning or end of lines:
334AT_CHECK([cat write.txt], [0], [dnl
335        1       12      123     1234    12345    .
336])
337AT_CLEANUP
338
339AT_SETUP([DATA LIST FREE and LIST report missing delimiters])
340AT_DATA([data-list.sps], [dnl
341DATA LIST FREE NOTABLE/s (a10).
342LIST.
343BEGIN DATA.
344'y'z
345END DATA.
346])
347AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
348data-list.sps:4: warning: Missing delimiter following quoted string.
349
350Table: Data List
351s
352y
353z
354])
355AT_CLEANUP
356
357AT_SETUP([DATA LIST FREE and LIST assume a width if omitted])
358AT_DATA([data-list.sps], [dnl
359DATA LIST FREE TABLE/s (a) d (datetime) f (f).
360])
361AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
362Table: Reading free-form data from INLINE.
363Variable,Format
364s,A1
365d,DATETIME17.0
366f,F1.0
367])
368AT_CLEANUP
369
370AT_SETUP([DATA LIST Decimal comma])
371AT_DATA([data-list.sps], [dnl
372SET DECIMAL=COMMA.
373
374DATA LIST NOTABLE LIST /A *.
375BEGIN DATA
3761
3772
3783
3793,5
3804
3814,5
3825
3836
384END DATA
385
386LIST /FORMAT=NUMBERED.
387])
388
389AT_CHECK([pspp -O format=csv data-list.sps], [0], [dnl
390Table: Data List
391Case Number,A
3921,"1,00"
3932,"2,00"
3943,"3,00"
3954,"3,50"
3965,"4,00"
3976,"4,50"
3987,"5,00"
3998,"6,00"
400])
401
402AT_CLEANUP
403
404
405AT_SETUP([DATA LIST - Negative SKIP])
406AT_DATA([data-list.sps], [dnl
407DATA LIST LIST FILE='f.in' NOTABLE SKIP=-1 /a b c d.
408
409EXECUTE.
410])
411
412AT_CHECK([pspp -O format=csv data-list.sps], [1], [dnl
413data-list.sps:1: error: DATA LIST: The SKIP value must be non-negative.
414
415data-list.sps:3: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
416])
417
418AT_CLEANUP
419
420
421AT_SETUP([DATA LIST - Negative RECORDS])
422AT_DATA([data-list.sps], [dnl
423DATA LIST LIST FILE='f.in' NOTABLE RECORDS=-1 /a b c d.
424
425EXECUTE.
426])
427
428AT_CHECK([pspp -O format=csv data-list.sps], [1], [dnl
429data-list.sps:1: error: DATA LIST: The RECORDS value must be non-negative.
430
431data-list.sps:3: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
432])
433
434AT_CLEANUP
435
436