b7e6eaf8d7499e2abc1829d598fec8ace060eb7c
[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,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
31 ad,1,,Scale,Input,8,Right,ADATE10,ADATE10,
32 dt,2,,Scale,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 format=csv value-labels.sps], [0], [dnl
56 Table: Variables
57 Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
58 x,1,,Scale,Input,8,Right,F8.2,F8.2,
59
60 Table: Value Labels
61 Variable,Value,Label
62 x,1.00,one
63 ,2.00,first line\nsecond line
64 ,3.00,three
65
66 Table: x
67 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
68 one,1.00,1,33.33,33.33,33.33
69 "first line
70 second line",2.00,1,33.33,33.33,66.67
71 three,3.00,1,33.33,33.33,100.00
72 Total,,3,100.0,100.0,
73 ])
74 AT_CLEANUP
75
76 AT_SETUP([VALUE LABELS with new-line in system file])
77 AT_DATA([save.sps], [dnl
78 DATA LIST LIST NOTABLE /x.
79 VALUE LABELS x 1 'one' 2 'first line\nsecond line' 3 'three'.
80 BEGIN DATA.
81 1
82 2
83 3
84 END DATA.
85 SAVE OUTFILE='value-labels.sav'.
86 ])
87 AT_CHECK([pspp -O format=csv save.sps])
88 AT_DATA([get.sps], [dnl
89 GET FILE='value-labels.sav'.
90 DISPLAY DICTIONARY.
91 FREQUENCIES x/STAT=NONE.
92 ])
93 AT_CHECK([pspp -O format=csv get.sps], [0], [dnl
94 Table: Variables
95 Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
96 x,1,,Scale,Input,8,Right,F8.2,F8.2,
97
98 Table: Value Labels
99 Variable,Value,Label
100 x,1.00,one
101 ,2.00,first line\nsecond line
102 ,3.00,three
103
104 Table: x
105 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
106 one,1.00,1,33.33,33.33,33.33
107 "first line
108 second line",2.00,1,33.33,33.33,66.67
109 three,3.00,1,33.33,33.33,100.00
110 Total,,3,100.0,100.0,
111 ])
112 AT_CLEANUP
113
114 dnl Tests for a bug which caused VALUE LABELS to 
115 dnl crash when given invalid syntax.
116 AT_SETUP([VALUE LABELS invalid syntax bug])
117 AT_DATA([value-labels.sps], [dnl
118 DATA LIST LIST NOTABLE /a * pref * .
119 BEGIN DATA.
120     1.00     1.00    
121     1.00     2.00    
122     2.00     1.00    
123     2.00     2.00    
124 END DATA.
125
126 VALUE LABELS /var=a 'label for a'.
127 ])
128 AT_CHECK([pspp -O format=csv value-labels.sps], [1], [dnl
129 value-labels.sps:9: error: VALUE LABELS: var is not a variable name.
130 ])
131 AT_CLEANUP
132
133 # Tests for a bug which caused a crash if VALUE LABELS had a trailing /.
134 AT_SETUP([VALUE LABELS trailing `/' bug])
135 AT_DATA([value-labels.sps], [dnl
136 DATA LIST LIST NOTABLE /X * .
137 BEGIN DATA.
138
139 2
140 3
141 4
142 END DATA.
143
144
145 VALUE LABELS X 1 'one' 2 'two' 3 'three'/
146
147
148 LIST VARIABLES=X.
149 ])
150 AT_CHECK([pspp -O format=csv value-labels.sps], [0], [dnl
151 Table: Data List
152 X
153 1.00
154 2.00
155 3.00
156 4.00
157 ])
158 AT_CLEANUP