Remove unneeded #includes.
[pspp] / tests / language / data-io / get-data-txt.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([GET DATA /TYPE=TXT])
18
19 dnl These tests exercise features of GET DATA /TYPE=TXT that
20 dnl it has in common with DATA LIST, using tests drawn from
21 dnl DATA LIST.
22
23 AT_SETUP([GET DATA /TYPE=TXT with explicit delimiters])
24 AT_DATA([get-data.sps], [dnl
25 get data /type=txt /file=inline /delimiters="|X"
26  /variables=A f7.2 B f7.2 C f7.2 D f7.2.
27 begin data.
28 1|23X45|2.03
29 2X22|34|23|
30 3|34|34X34
31 end data.
32
33 list.
34 ])
35 AT_CHECK([pspp -o pspp.csv get-data.sps])
36 AT_CHECK([cat pspp.csv], [0], [dnl
37 Table: Data List
38 A,B,C,D
39 1.00,23.00,45.00,2.03
40 2.00,22.00,34.00,23.00
41 3.00,34.00,34.00,34.00
42 ])
43 AT_CLEANUP
44
45 AT_SETUP([GET DATA /TYPE=TXT with FIRSTCASE])
46 AT_DATA([get-data.sps], [dnl
47 get 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.
49 begin data.
50 # This record is ignored.
51 ,1,2,3
52 ,4,,5
53 6
54 7,
55
56 8 9
57 0,1,,,
58
59 ,,,,
60
61 2
62
63 3
64 4
65 5
66 end data.
67 list.
68 ])
69 AT_CHECK([pspp -o pspp.csv get-data.sps], [0], [ignore])
70 AT_CHECK([cat pspp.csv], [0], [dnl
71 Table: Data List
72 A,B,C,D
73 .  ,1.00,2.00,3.00
74 .  ,4.00,.  ,5.00
75 6.00,7.00,.  ,8.00
76 9.00,.00,1.00,.  @&t@
77 .  ,.  ,.  ,.  @&t@
78 .  ,.  ,.  ,2.00
79 .  ,3.00,4.00,5.00
80 ])
81 AT_CLEANUP
82
83 AT_SETUP([GET DATA /TYPE=TXT with FIRSTCASE and tab delimiter])
84 AT_DATA([get-data.sps], [dnl
85 get 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.
87 begin data.
88 # These records
89 # are skipped.
90 1       2       3       4
91 1       2       3       4       @&t@
92 1       2               4
93 1       2               4       @&t@
94 1               3       4
95 1               3       4       @&t@
96 1                       4
97 1                       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@
106 end data.
107 list.
108 ])
109 AT_CHECK([pspp -o pspp.csv get-data.sps])
110 AT_CHECK([cat pspp.csv], [0], [dnl
111 Table: Data List
112 A,B,C,D
113 1.00,2.00,3.00,4.00
114 1.00,2.00,3.00,4.00
115 1.00,2.00,.  ,4.00
116 1.00,2.00,.  ,4.00
117 1.00,.  ,3.00,4.00
118 1.00,.  ,3.00,4.00
119 1.00,.  ,.  ,4.00
120 1.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 ])
130 AT_CLEANUP
131
132 AT_SETUP([GET DATA /TYPE=TXT with multiple records per case])
133 AT_DATA([get-data.sps], [dnl
134 get 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.
138 begin data.
139 07-22-2007
140 10-06-2007
141 321
142 07-14-1789
143 08-26-1789
144 4
145 01-01-1972
146 12-31-1999
147 682
148 end data.
149 list.
150 ])
151 AT_CHECK([pspp -o pspp.csv get-data.sps])
152 AT_CHECK([cat pspp.csv], [0], [dnl
153 Table: Data List
154 start,end,count
155 07/22/07,10/06/2007,321
156 ********,08/26/1789,4
157 01/01/72,12/31/1999,682
158 ])
159 AT_CLEANUP
160
161 AT_SETUP([GET DATA /TYPE=TXT with empty trailing record])
162 AT_DATA([get-data.sps], [dnl
163 get data /type=txt /file=inline /arrangement=fixed /fixcase=2 /variables=
164         /1 x 0 f
165            y 1 f.
166 begin data.
167 12
168
169 34
170
171 56
172
173 78
174
175 90
176
177 end data.
178 list.
179 ])
180 AT_CHECK([pspp -o pspp.csv get-data.sps])
181 AT_CHECK([cat pspp.csv], [0], [dnl
182 Table: Data List
183 x,y
184 1,2
185 3,4
186 5,6
187 7,8
188 9,0
189 ])
190 AT_CLEANUP
191
192 dnl This test is a copy of an example given in the manual
193 dnl in doc/files.texi.
194 AT_SETUP([GET DATA /TYPE=TXT password example])
195 AT_DATA([passwd.data], [dnl
196 root:$1$nyeSP5gD$pDq/:0:0:,,,:/root:/bin/bash
197 blp:$1$BrP/pFg4$g7OG:1000:1000:Ben Pfaff,,,:/home/blp:/bin/bash
198 john:$1$JBuq/Fioq$g4A:1001:1001:John Darrington,,,:/home/john:/bin/bash
199 jhs:$1$D3li4hPL$88X1:1002:1002:Jason Stover,,,:/home/jhs:/bin/csh
200 ])
201 AT_DATA([passwd.sps], [dnl
202 GET 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.
210 LIST.
211 ])
212 AT_CHECK([pspp -o pspp.csv passwd.sps])
213 AT_CHECK([cat pspp.csv], [0], [dnl
214 Table: Data List
215 username,password,uid,gid,gecos,home,shell
216 root,$1$nyeSP5gD$pDq/,0,0,",,,",/root,/bin/bash
217 blp,$1$BrP/pFg4$g7OG,1000,1000,"Ben Pfaff,,,",/home/blp,/bin/bash
218 john,$1$JBuq/Fioq$g4A,1001,1001,"John Darrington,,,",/home/john,/bin/bash
219 jhs,$1$D3li4hPL$88X1,1002,1002,"Jason Stover,,,",/home/jhs,/bin/csh
220 ])
221 AT_CLEANUP
222
223 dnl This test is a copy of an example given in the manual
224 dnl in doc/files.texi.
225 AT_SETUP([GET DATA /TYPE=TXT cars example])
226 AT_DATA([cars.data], [dnl
227 model   year    mileage price   type    age
228 Civic   2002    29883   15900   Si      2
229 Civic   2003    13415   15900   EX      1
230 Civic   1992    107000  3800    n/a     12
231 Accord  2002    26613   17900   EX      1
232 ])
233 AT_DATA([cars.sps], [dnl
234 GET 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.
241 LIST.
242
243 GET 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.
250 LIST.
251 ])
252 AT_CHECK([pspp -o pspp.csv cars.sps])
253 AT_CHECK([cat pspp.csv], [0], [dnl
254 Table: Data List
255 model,year,mileage,price,type,age
256 Civic,2002,29883,15900,Si,2
257 Civic,2003,13415,15900,EX,1
258 Civic,1992,107000,3800,n/a,12
259 Accord,2002,26613,17900,EX,1
260
261 Table: Data List
262 model,year,mileage,price,type,age
263 Civic,2002,29883,15900,Si,2
264 Civic,2003,13415,15900,EX,1
265 Civic,1992,107000,3800,n/a,12
266 Accord,2002,26613,17900,EX,1
267 ])
268 AT_CLEANUP
269
270 dnl This test is a copy of an example given in the manual
271 dnl in doc/files.texi.
272 AT_SETUP([GET DATA /TYPE=TXT pets example])
273 AT_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 ])
281 AT_DATA([pets.sps], [dnl
282 GET 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.
291 LIST.
292 ])
293 AT_CHECK([pspp -o pspp.csv pets.sps])
294 AT_CHECK([cat pspp.csv], [0], [dnl
295 Table: Data List
296 name,age,color,received,price,height,type
297 Rover,4.5,Brown,12.02.2004,80.00,"1'4""",Dog
298 Charlie,. ,Gold,05.04.2007,12.30,"3""",Fish
299 Molly,2.0,Black,12.12.2006,25.00,"5""",Cat
300 Gilly,. ,White,10.04.2007,10.00,"3""",Guinea Pig
301 ])
302 AT_CLEANUP
303 dnl " (fixes Emacs highlighting)
304
305 AT_SETUP([GET DATA /TYPE=TXT with IMPORTCASE])
306 AT_CHECK([$PYTHON3 > test.data -c '
307 for i in range(1, 101):
308     print("%02d" % i)
309 '])
310 AT_DATA([get-data.sps], [dnl
311 get data /type=txt /file='test.data' /importcase=first 10 /variables x f8.0.
312 get data /type=txt /file='test.data' /importcase=percent 1 /variables x f8.0.
313 get data /type=txt /file='test.data' /importcase=percent 35 /variables x f8.0.
314 get data /type=txt /file='test.data' /importcase=percent 95 /variables x f8.0.
315 get data /type=txt /file='test.data' /importcase=percent 100 /variables x f8.0.
316 ])
317 AT_CHECK([pspp -O format=csv get-data.sps], [0], [dnl
318 "get-data.sps:1.39-1.57: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.).
319     1 | get data /type=txt /file='test.data' /importcase=first 10 /variables x f8.0.
320       |                                       ^~~~~~~~~~~~~~~~~~~"
321
322 "get-data.sps:2.39-2.58: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.).
323     2 | get data /type=txt /file='test.data' /importcase=percent 1 /variables x f8.0.
324       |                                       ^~~~~~~~~~~~~~~~~~~~"
325
326 "get-data.sps:3.39-3.59: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.).
327     3 | get data /type=txt /file='test.data' /importcase=percent 35 /variables x f8.0.
328       |                                       ^~~~~~~~~~~~~~~~~~~~~"
329
330 "get-data.sps:4.39-4.59: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.).
331     4 | get data /type=txt /file='test.data' /importcase=percent 95 /variables x f8.0.
332       |                                       ^~~~~~~~~~~~~~~~~~~~~"
333
334 "get-data.sps:5.39-5.60: warning: GET DATA: Ignoring obsolete IMPORTCASES subcommand.  (N OF CASES or SAMPLE may be used to substitute.).
335     5 | get data /type=txt /file='test.data' /importcase=percent 100 /variables x f8.0.
336       |                                       ^~~~~~~~~~~~~~~~~~~~~~"
337 ])
338 AT_CLEANUP
339
340 AT_SETUP([GET DATA /TYPE=TXT with ENCODING subcommand])
341 AT_CHECK([i18n-test supports_encodings UTF-8 ISO-8859-1])
342 AT_DATA([get-data.sps], [dnl
343 set locale='utf-8'
344 get data /type=txt /file='data.txt' /encoding='iso-8859-1'
345   /delimiters="," /variables=s a8.
346 list.
347 ])
348 printf '\351' > data.txt        # é in ISO-8859-1.
349 AT_CHECK([pspp -o pspp.csv get-data.sps])
350 AT_CHECK([cat pspp.csv], [0], [dnl
351 Table: Data List
352 s
353 é
354 ])
355 AT_CLEANUP
356
357
358 AT_SETUP([GET DATA /TYPE= truncated])
359
360 AT_DATA([x.sps], [dnl
361 GET DATA /TYPE=
362 .
363 ])
364
365 AT_CHECK([pspp -o pspp.csv x.sps], [1], [ignore])
366
367 AT_CLEANUP
368
369
370
371 AT_SETUP([GET DATA /TYPE=txt bug])
372
373
374 AT_DATA([thing.txt], [dnl
375 foo, title, last
376 1, this, 1
377 2, that, 2
378 3, other, 3
379 ])
380
381 AT_DATA([x.sps], [dnl
382 GET DATA
383   /TYPE=TXT
384   /FILE="thing.txt"
385   /ARRANGEMENT=DELIMITED
386   /DELCASE=LINE
387   /FIRSTCASE=2
388   /DELIMITERS=","
389   /VARIABLES=foo F1.0
390     title A8
391     last F2.0.
392
393 list.
394 ])
395
396 AT_CHECK([pspp -O format=csv x.sps], [0], [dnl
397 Table: Data List
398 foo,title,last
399 1,this,1
400 2,that,2
401 3,other,3
402 ])
403
404 AT_CLEANUP
405
406
407
408 AT_SETUP([GET DATA /TYPE=txt another bug])
409
410 AT_DATA([crash.sps], [dnl
411 get data /type=txt /file=inline /variables=C f7.2 D f7>2.
412 begin data.
413 3 2
414 4 2
415 5 2
416 end data.
417 ])
418
419 AT_CHECK([pspp -O format=csv crash.sps], [1], [ignore])
420
421 AT_CLEANUP
422
423
424
425
426
427