Automatically infer variables' measurement level from format and data.
[pspp] / tests / language / dictionary / value-labels.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([VALUE LABELS])
18
19 AT_SETUP([VALUE LABELS date formats])
20 AT_DATA([value-labels.sps], [dnl
21 DATA LIST LIST NOTABLE /ad (adate10) dt (datetime20).
22 VALUE LABELS ad 'july 10, 1982' 'label 1'
23                 '1-2-93' 'label 2'
24                 '5-4-2003' 'label 3'
25             /dt '12 Apr 2011 06:09:56' 'label 4'.
26 DISPLAY DICTIONARY.
27 ])
28 AT_CHECK([pspp -O format=csv value-labels.sps], [0], [dnl
29 Table: Variables
30 Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
31 ad,1,Unknown,Input,8,Right,ADATE10,ADATE10
32 dt,2,Unknown,Input,8,Right,DATETIME20.0,DATETIME20.0
33
34 Table: Value Labels
35 Variable Value,,Label
36 ad,07/10/1982,label 1
37 ,01/02/1993,label 2
38 ,05/04/2003,label 3
39 dt,12-APR-2011 06:09:56,label 4
40 ])
41 AT_CLEANUP
42
43 AT_SETUP([VALUE LABELS with new-line])
44 AT_DATA([value-labels.sps], [dnl
45 DATA LIST LIST NOTABLE /x.
46 VALUE LABELS x 1 'one' 2 'first line\nsecond line' 3 'three'.
47 BEGIN DATA.
48 1
49 2
50 3
51 END DATA.
52 DISPLAY DICTIONARY.
53 FREQUENCIES x/STAT=NONE.
54 ])
55 AT_CHECK([pspp -o pspp.csv -o pspp.txt value-labels.sps])
56 AT_CHECK([cat pspp.csv], [0], [dnl
57 Table: Variables
58 Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
59 x,1,Nominal,Input,8,Right,F8.2,F8.2
60
61 Table: Value Labels
62 Variable Value,,Label
63 x,1.00,one
64 ,2.00,first line\nsecond line
65 ,3.00,three
66
67 Table: x
68 ,,Frequency,Percent,Valid Percent,Cumulative Percent
69 Valid,one,1,33.3%,33.3%,33.3%
70 ,"first line
71 second line",1,33.3%,33.3%,66.7%
72 ,three,1,33.3%,33.3%,100.0%
73 Total,,3,100.0%,,
74 ])
75 AT_CLEANUP
76
77 AT_SETUP([VALUE LABELS with new-line in system file])
78 AT_DATA([save.sps], [dnl
79 DATA LIST LIST NOTABLE /x.
80 VALUE LABELS x 1 'one' 2 'first line\nsecond line' 3 'three'.
81 BEGIN DATA.
82 1
83 2
84 3
85 END DATA.
86 SAVE OUTFILE='value-labels.sav'.
87 ])
88 AT_CHECK([pspp -O format=csv save.sps])
89 AT_DATA([get.sps], [dnl
90 GET FILE='value-labels.sav'.
91 DISPLAY DICTIONARY.
92 FREQUENCIES x/STAT=NONE.
93 ])
94 AT_CHECK([pspp -o pspp.csv -o pspp.txt get.sps])
95 AT_CHECK([cat pspp.csv], [0], [dnl
96 Table: Variables
97 Name,Position,Measurement Level,Role,Width,Alignment,Print Format,Write Format
98 x,1,Nominal,Input,8,Right,F8.2,F8.2
99
100 Table: Value Labels
101 Variable Value,,Label
102 x,1.00,one
103 ,2.00,first line\nsecond line
104 ,3.00,three
105
106 Table: x
107 ,,Frequency,Percent,Valid Percent,Cumulative Percent
108 Valid,one,1,33.3%,33.3%,33.3%
109 ,"first line
110 second line",1,33.3%,33.3%,66.7%
111 ,three,1,33.3%,33.3%,100.0%
112 Total,,3,100.0%,,
113 ])
114 AT_CLEANUP
115
116 dnl Tests for a bug which caused VALUE LABELS to
117 dnl crash when given invalid syntax.
118 AT_SETUP([VALUE LABELS invalid syntax bug])
119 AT_DATA([value-labels.sps], [dnl
120 DATA LIST LIST NOTABLE /a * pref * .
121 BEGIN DATA.
122     1.00     1.00
123     1.00     2.00
124     2.00     1.00
125     2.00     2.00
126 END DATA.
127
128 VALUE LABELS /var=a 'label for a'.
129 ])
130 AT_CHECK([pspp -O format=csv value-labels.sps], [1], [dnl
131 value-labels.sps:9: error: VALUE LABELS: var is not a variable name.
132 ])
133 AT_CLEANUP
134
135 # Tests for a bug which caused a crash if VALUE LABELS had a trailing /.
136 AT_SETUP([VALUE LABELS trailing `/' bug])
137 AT_DATA([value-labels.sps], [dnl
138 DATA LIST LIST NOTABLE /X * .
139 BEGIN DATA.
140 1
141 2
142 3
143 4
144 END DATA.
145
146
147 VALUE LABELS X 1 'one' 2 'two' 3 'three'/
148
149
150 LIST VARIABLES=X.
151 ])
152 AT_CHECK([pspp -O format=csv value-labels.sps], [0], [dnl
153 Table: Data List
154 X
155 1.00
156 2.00
157 3.00
158 4.00
159 ])
160 AT_CLEANUP