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