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