SAVE TRANSLATE: Allow variable names with space, etc. in output.
[pspp] / tests / language / data-io / save-translate.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([SAVE TRANSLATE /TYPE=CSV])
18
19 m4_define([PREPARE_SAVE_TRANSLATE_CSV], [dnl
20 AT_KEYWORDS([SAVE TRANSLATE])
21 AT_DATA([data.txt], [dnl
22 0 '1 9:30:05' 1/2/2003 "25/8/1995 15:30:00" "'a,b,c'",0
23 , '-0 5:17' 10/31/2010 "9/4/2008 9:29:00" " xxx ",1
24 1.625,'0 12:00',,,xyzzy,1
25 ])
26 AT_DATA([save-translate.pspp], [dnl
27 SET DECIMAL=DOT.
28 DATA LIST LIST NOTABLE FILE="data.txt"
29     /number(F8.3) time(DTIME10) date(ADATE10) datetime(DATETIME20) string(A8)
30      filter(F1.0).
31 MISSING VALUES number(0) time('0 12:00') string('xyzzy').
32 FILTER BY filter.
33 SAVE TRANSLATE /OUTFILE="data.csv" /TYPE=m4_if([$2], [], [CSV], [$2])
34     $1.
35 ])
36 AT_CHECK([pspp -O format=csv save-translate.pspp], [0])
37 ])
38
39 AT_SETUP([CSV output -- defaults])
40 PREPARE_SAVE_TRANSLATE_CSV
41 AT_CHECK([cat data.csv], [0], [dnl
42 0,33:30:05,01/02/2003,08/25/1995 15:30:00,"'a,b,c'",0
43  ,-05:17:00,10/31/2010,04/09/2008 09:29:00, xxx,1
44 1.625,12:00:00, , ,xyzzy,1
45 ])
46 AT_CLEANUP
47
48 AT_SETUP([CSV output -- recode missing, delete unselected])
49 PREPARE_SAVE_TRANSLATE_CSV([/MISSING=RECODE /UNSELECTED=DELETE])
50 AT_CHECK([cat data.csv], [0], [dnl
51  ,-05:17:00,10/31/2010,04/09/2008 09:29:00, xxx,1
52 1.625, , , ,,1
53 ])
54 AT_CLEANUP
55
56 AT_SETUP([CSV output -- var names, formats])
57 PREPARE_SAVE_TRANSLATE_CSV(
58   [/FIELDNAMES /TEXTOPTIONS FORMAT=VARIABLE /UNSELECTED=RETAIN])
59 AT_CHECK([cat data.csv], [0], [dnl
60 number,time,date,datetime,string,filter
61 .000,1 09:30:05,01/02/2003,25-AUG-1995 15:30:00,"'a,b,c'",0
62  ,-0 05:17,10/31/2010,09-APR-2008 09:29:00, xxx,1
63 1.625,0 12:00:00, , ,xyzzy,1
64 ])
65 AT_CLEANUP
66
67 AT_SETUP([CSV output -- comma as decimal point])
68 PREPARE_SAVE_TRANSLATE_CSV([/FIELDNAMES /TEXTOPTIONS DECIMAL=COMMA])
69 AT_CHECK([cat data.csv], [0], [dnl
70 number;time;date;datetime;string;filter
71 0;33:30:05;01/02/2003;08/25/1995 15:30:00;'a,b,c';0
72  ;-05:17:00;10/31/2010;04/09/2008 09:29:00; xxx;1
73 1,625;12:00:00; ; ;xyzzy;1
74 ])
75 AT_CLEANUP
76
77 AT_SETUP([CSV output -- custom delimiter, qualifier])
78 PREPARE_SAVE_TRANSLATE_CSV(
79   [/FIELDNAMES /TEXTOPTIONS DELIMITER=':' QUALIFIER="'"])
80 AT_CHECK([cat data.csv], [0], [dnl
81 number:time:date:datetime:string:filter
82 0:'33:30:05':01/02/2003:'08/25/1995 15:30:00':'''a,b,c''':0
83  :'-05:17:00':10/31/2010:'04/09/2008 09:29:00': xxx:1
84 1.625:'12:00:00': : :xyzzy:1
85 ])
86 AT_CLEANUP
87
88 AT_SETUP([CSV output -- KEEP, RENAME])
89 PREPARE_SAVE_TRANSLATE_CSV(
90   [/FIELDNAMES /KEEP=time string /RENAME string='long name with spaces' /UNSELECTED=DELETE])
91 AT_CHECK([cat data.csv], [0], [dnl
92 time,long name with spaces
93 -05:17:00, xxx
94 12:00:00,xyzzy
95 ])
96 AT_CLEANUP
97
98 AT_BANNER([SAVE TRANSLATE /TYPE=TAB])
99
100 AT_SETUP([TAB output])
101 PREPARE_SAVE_TRANSLATE_CSV([/FIELDNAMES], [TAB])
102 AT_CHECK([cat data.csv], [0], [dnl
103 number  time    date    datetime        string  filter
104 0       33:30:05        01/02/2003      08/25/1995 15:30:00     'a,b,c' 0
105         -05:17:00       10/31/2010      04/09/2008 09:29:00      xxx    1
106 1.625   12:00:00                        xyzzy   1
107 ])
108 AT_CLEANUP