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([GET DATA /TYPE=TXT])
18
19dnl These tests exercise features of GET DATA /TYPE=TXT that
20dnl it has in common with DATA LIST, using tests drawn from
21dnl DATA LIST.
22
23AT_SETUP([GET DATA /TYPE=TXT with explicit delimiters])
24AT_DATA([get-data.sps], [dnl
25get data /type=txt /file=inline /delimiters="|X"
26 /variables=A f7.2 B f7.2 C f7.2 D f7.2.
27begin data.
281|23X45|2.03
292X22|34|23|
303|34|34X34
31end data.
32
33list.
34])
35AT_CHECK([pspp -o pspp.csv get-data.sps])
36AT_CHECK([cat pspp.csv], [0], [dnl
37Table: Data List
38A,B,C,D
391.00,23.00,45.00,2.03
402.00,22.00,34.00,23.00
413.00,34.00,34.00,34.00
42])
43AT_CLEANUP
44
45AT_SETUP([GET DATA /TYPE=TXT with FIRSTCASE])
46AT_DATA([get-data.sps], [dnl
47get data /type=txt /file=inline /delimiters=', ' /delcase=variables 4
48 /firstcase=2 /variables=A f7.2 B f7.2 C f7.2 D f7.2.
49begin data.
50# This record is ignored.
51,1,2,3
52,4,,5
536
547,
55
568 9
570,1,,,
58
59,,,,
60
612
62
633
644
655
66end data.
67list.
68])
69AT_CHECK([pspp -o pspp.csv get-data.sps], [0], [ignore])
70AT_CHECK([cat pspp.csv], [0], [dnl
71Table: Data List
72A,B,C,D
73.  ,1.00,2.00,3.00
74.  ,4.00,.  ,5.00
756.00,7.00,.  ,8.00
769.00,.00,1.00,.  @&t@
77.  ,.  ,.  ,.  @&t@
78.  ,.  ,.  ,2.00
79.  ,3.00,4.00,5.00
80])
81AT_CLEANUP
82
83AT_SETUP([GET DATA /TYPE=TXT with FIRSTCASE and tab delimiter])
84AT_DATA([get-data.sps], [dnl
85get data /type=txt /file=inline /delimiters='\t' /delcase=variables 4
86 /firstcase=3 /variables=A f7.2 B f7.2 C f7.2 D f7.2.
87begin data.
88# These records
89# are skipped.
901	2	3	4
911	2	3	4	@&t@
921	2		4
931	2		4	@&t@
941		3	4
951		3	4	@&t@
961			4
971			4	@&t@
98	2	3	4
99	2	3	4	@&t@
100	2		4
101	2		4	@&t@
102		3	4
103		3	4	@&t@
104			4
105			4	@&t@
106end data.
107list.
108])
109AT_CHECK([pspp -o pspp.csv get-data.sps])
110AT_CHECK([cat pspp.csv], [0], [dnl
111Table: Data List
112A,B,C,D
1131.00,2.00,3.00,4.00
1141.00,2.00,3.00,4.00
1151.00,2.00,.  ,4.00
1161.00,2.00,.  ,4.00
1171.00,.  ,3.00,4.00
1181.00,.  ,3.00,4.00
1191.00,.  ,.  ,4.00
1201.00,.  ,.  ,4.00
121.  ,2.00,3.00,4.00
122.  ,2.00,3.00,4.00
123.  ,2.00,.  ,4.00
124.  ,2.00,.  ,4.00
125.  ,.  ,3.00,4.00
126.  ,.  ,3.00,4.00
127.  ,.  ,.  ,4.00
128.  ,.  ,.  ,4.00
129])
130AT_CLEANUP
131
132AT_SETUP([GET DATA /TYPE=TXT with multiple records per case])
133AT_DATA([get-data.sps], [dnl
134get data /type=txt /file=inline /arrangement=fixed /fixcase=3 /variables=
135	/1 start 0-19 adate8
136	/2 end 0-19 adate
137	/3 count 0-2 f.
138begin data.
13907-22-2007
14010-06-2007
141321
14207-14-1789
14308-26-1789
1444
14501-01-1972
14612-31-1999
147682
148end data.
149list.
150])
151AT_CHECK([pspp -o pspp.csv get-data.sps])
152AT_CHECK([cat pspp.csv], [0], [dnl
153Table: Data List
154start,end,count
15507/22/07,10/06/2007,321
156********,08/26/1789,4
15701/01/72,12/31/1999,682
158])
159AT_CLEANUP
160
161AT_SETUP([GET DATA /TYPE=TXT with empty trailing record])
162AT_DATA([get-data.sps], [dnl
163get data /type=txt /file=inline /arrangement=fixed /fixcase=2 /variables=
164	/1 x 0 f
165           y 1 f.
166begin data.
16712
168
16934
170
17156
172
17378
174
17590
176
177end data.
178list.
179])
180AT_CHECK([pspp -o pspp.csv get-data.sps])
181AT_CHECK([cat pspp.csv], [0], [dnl
182Table: Data List
183x,y
1841,2
1853,4
1865,6
1877,8
1889,0
189])
190AT_CLEANUP
191
192dnl This test is a copy of an example given in the manual
193dnl in doc/files.texi.
194AT_SETUP([GET DATA /TYPE=TXT password example])
195AT_DATA([passwd.data], [dnl
196root:$1$nyeSP5gD$pDq/:0:0:,,,:/root:/bin/bash
197blp:$1$BrP/pFg4$g7OG:1000:1000:Ben Pfaff,,,:/home/blp:/bin/bash
198john:$1$JBuq/Fioq$g4A:1001:1001:John Darrington,,,:/home/john:/bin/bash
199jhs:$1$D3li4hPL$88X1:1002:1002:Jason Stover,,,:/home/jhs:/bin/csh
200])
201AT_DATA([passwd.sps], [dnl
202GET DATA /TYPE=TXT /FILE='passwd.data' /DELIMITERS=':'
203        /VARIABLES=username A20
204                   password A40
205                   uid F10
206                   gid F10
207                   gecos A40
208                   home A40
209                   shell A40.
210LIST.
211])
212AT_CHECK([pspp -o pspp.csv passwd.sps])
213AT_CHECK([cat pspp.csv], [0], [dnl
214Table: Data List
215username,password,uid,gid,gecos,home,shell
216root,$1$nyeSP5gD$pDq/,0,0,",,,",/root,/bin/bash
217blp,$1$BrP/pFg4$g7OG,1000,1000,"Ben Pfaff,,,",/home/blp,/bin/bash
218john,$1$JBuq/Fioq$g4A,1001,1001,"John Darrington,,,",/home/john,/bin/bash
219jhs,$1$D3li4hPL$88X1,1002,1002,"Jason Stover,,,",/home/jhs,/bin/csh
220])
221AT_CLEANUP
222
223dnl This test is a copy of an example given in the manual
224dnl in doc/files.texi.
225AT_SETUP([GET DATA /TYPE=TXT cars example])
226AT_DATA([cars.data], [dnl
227model   year    mileage price   type    age
228Civic   2002    29883   15900   Si      2
229Civic   2003    13415   15900   EX      1
230Civic   1992    107000  3800    n/a     12
231Accord  2002    26613   17900   EX      1
232])
233AT_DATA([cars.sps], [dnl
234GET DATA /TYPE=TXT /FILE='cars.data' /DELIMITERS=' ' /FIRSTCASE=2
235        /VARIABLES=model A8
236                   year F4
237                   mileage F6
238                   price F5
239                   type A4
240                   age F2.
241LIST.
242
243GET DATA /TYPE=TXT /FILE='cars.data' /ARRANGEMENT=FIXED /FIRSTCASE=2
244        /VARIABLES=model 0-7 A
245                   year 8-15 F
246                   mileage 16-23 F
247                   price 24-31 F
248                   type 32-39 A
249                   age 40-47 F.
250LIST.
251])
252AT_CHECK([pspp -o pspp.csv cars.sps])
253AT_CHECK([cat pspp.csv], [0], [dnl
254Table: Data List
255model,year,mileage,price,type,age
256Civic,2002,29883,15900,Si,2
257Civic,2003,13415,15900,EX,1
258Civic,1992,107000,3800,n/a,12
259Accord,2002,26613,17900,EX,1
260
261Table: Data List
262model,year,mileage,price,type,age
263Civic,2002,29883,15900,Si,2
264Civic,2003,13415,15900,EX,1
265Civic,1992,107000,3800,n/a,12
266Accord,2002,26613,17900,EX,1
267])
268AT_CLEANUP
269
270dnl This test is a copy of an example given in the manual
271dnl in doc/files.texi.
272AT_SETUP([GET DATA /TYPE=TXT pets example])
273AT_DATA([pets.data], [dnl
274'Pet''s Name', "Age", "Color", "Date Received", "Price", "Height", "Type"
275, (Years), , , (Dollars), ,
276"Rover", 4.5, Brown, "12 Feb 2004", 80, '1''4"', "Dog"
277"Charlie", , Gold, "5 Apr 2007", 12.3, "3""", "Fish"
278"Molly", 2, Black, "12 Dec 2006", 25, '5"', "Cat"
279"Gilly", , White, "10 Apr 2007", 10, "3""", "Guinea Pig"
280])
281AT_DATA([pets.sps], [dnl
282GET DATA /TYPE=TXT /FILE='pets.data' /DELIMITERS=', ' /QUALIFIER='''"'
283        /FIRSTCASE=3
284        /VARIABLES=name A10
285                   age F3.1
286                   color A5
287                   received EDATE10
288                   price F5.2
289                   height a5
290                   type a10.
291LIST.
292])
293AT_CHECK([pspp -o pspp.csv pets.sps])
294AT_CHECK([cat pspp.csv], [0], [dnl
295Table: Data List
296name,age,color,received,price,height,type
297Rover,4.5,Brown,12.02.2004,80.00,"1'4""",Dog
298Charlie,. ,Gold,05.04.2007,12.30,"3""",Fish
299Molly,2.0,Black,12.12.2006,25.00,"5""",Cat
300Gilly,. ,White,10.04.2007,10.00,"3""",Guinea Pig
301])
302AT_CLEANUP
303dnl " (fixes Emacs highlighting)
304
305AT_SETUP([GET DATA /TYPE=TXT with IMPORTCASE])
306AT_CHECK([$PERL > test.data <<'EOF'
307for ($i = 1; $i <= 100; $i++) {
308    printf "%02d\n", $i;
309}
310EOF
311])
312AT_DATA([get-data.sps], [dnl
313get data /type=txt /file='test.data' /importcase=first 10 /variables x f8.0.
314get data /type=txt /file='test.data' /importcase=percent 1 /variables x f8.0.
315get data /type=txt /file='test.data' /importcase=percent 35 /variables x f8.0.
316get data /type=txt /file='test.data' /importcase=percent 95 /variables x f8.0.
317get data /type=txt /file='test.data' /importcase=percent 100 /variables x f8.0.
318])
319AT_CHECK([pspp -O format=csv get-data.sps], [0], [dnl
320get-data.sps:1: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.)
321
322get-data.sps:2: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.)
323
324get-data.sps:3: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.)
325
326get-data.sps:4: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.)
327
328get-data.sps:5: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.)
329])
330AT_CLEANUP
331
332AT_SETUP([GET DATA /TYPE=TXT with ENCODING subcommand])
333AT_CHECK([i18n-test supports_encodings UTF-8 ISO-8859-1])
334AT_DATA([get-data.sps], [dnl
335set locale='utf-8'
336get data /type=txt /file='data.txt' /encoding='iso-8859-1'
337  /delimiters="," /variables=s a8.
338list.
339])
340printf '\351' > data.txt	# é in ISO-8859-1.
341AT_CHECK([pspp -o pspp.csv get-data.sps])
342AT_CHECK([cat pspp.csv], [0], [dnl
343Table: Data List
344s
345é
346])
347AT_CLEANUP
348
349
350AT_SETUP([GET DATA /TYPE= truncated])
351
352AT_DATA([x.sps], [dnl
353GET DATA /TYPE=
354.
355])
356
357AT_CHECK([pspp -o pspp.csv x.sps], [1], [ignore])
358
359AT_CLEANUP
360
361
362
363AT_SETUP([GET DATA /TYPE=txt bug])
364
365
366AT_DATA([thing.txt], [dnl
367foo, title, last
3681, this, 1
3692, that, 2
3703, other, 3
371])
372
373AT_DATA([x.sps], [dnl
374GET DATA
375  /TYPE=TXT
376  /FILE="thing.txt"
377  /ARRANGEMENT=DELIMITED
378  /DELCASE=LINE
379  /FIRSTCASE=2
380  /DELIMITERS=","
381  /VARIABLES=foo F1.0
382    title A8
383    last F2.0.
384
385list.
386])
387
388AT_CHECK([pspp -O format=csv x.sps], [0], [dnl
389Table: Data List
390foo,title,last
3911,this,1
3922,that,2
3933,other,3
394])
395
396AT_CLEANUP
397
398
399
400AT_SETUP([GET DATA /TYPE=txt another bug])
401
402AT_DATA([crash.sps], [dnl
403get data /type=txt /file=inline /variables=C f7.2 D f7>2.
404begin data.
4053 2
4064 2
4075 2
408end data.
409])
410
411AT_CHECK([pspp -O format=csv crash.sps], [1], [ignore])
412
413AT_CLEANUP
414
415
416
417
418
419
420