1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
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.
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.
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/>.
17 AT_BANNER([SORT VARIABLES])
19 AT_SETUP([SORT VARIABLES])
20 # This reverses the order of its input lines.
21 # From the GNU sed manual.
29 cat > sort-variables.sps <<EOF
37 AT_CHECK_UNQUOTED([pspp -O format=csv sort-variables.sps], [0],
40 `for var in $4; do echo $var; done`
44 `for var in $4; do echo $var; done | tac`
48 test_sort 'x100 c b x99 a y400 y5' '' NAME 'a b c x99 x100 y5 y400'
49 test_sort 'c(a10) a(a5) b' '' TYPE 'b a c'
50 test_sort 'a (datetime) b (f) c (a5) d (a2) e (a1)' '' FORMAT 'e d c b a'
52 'VARIABLE LABEL a "hi there".' \
55 'VALUE LABELS a 123 "xyzzy".' \
58 'MISSING VALUES a (123).' \
61 'VARIABLE LEVEL a (SCALE) b (ORDINAL) c (NOMINAL).' \
63 test_sort 'b n i s t p' \
64 'VARIABLE ROLE /INPUT i /TARGET t /BOTH b /NONE n /PARTITION p /SPLIT s.' \
66 test_sort 'c10 c5 c15 c9' \
67 'VARIABLE WIDTH c10(10) c5(5) c15(15) c9(9).' \
68 COLUMNS 'c5 c9 c10 c15'
70 'VARIABLE ALIGNMENT c (CENTER) l (LEFT) r (RIGHT).' \
72 test_sort 'az ax ay ab' \
73 'VARIABLE ATTRIBUTE VARIABLES=az ATTRIBUTE=key("z").
74 VARIABLE ATTRIBUTE VARIABLES=ax ATTRIBUTE=key("x").
75 VARIABLE ATTRIBUTE VARIABLES=ay ATTRIBUTE=key("y").
76 VARIABLE ATTRIBUTE VARIABLES=ab ATTRIBUTE=key("b").' \
77 'ATTRIBUTE key' 'ab ax ay az'
80 AT_SETUP([SORT VARIABLES syntax errors])
81 AT_DATA([sort-variables.sps], [dnl
82 DATA LIST LIST NOTABLE /x y z.
84 SORT VARIABLES BY ATTRIBUTE **.
85 SORT VARIABLES BY NAME (**).
86 SORT VARIABLES BY NAME (A **).
88 AT_CHECK([pspp -O format=csv sort-variables.sps], [1], [dnl
89 "sort-variables.sps:2.19-2.20: error: SORT VARIABLES: Syntax error expecting one of the following: NAME, TYPE, FORMAT, LABEL, VALUES, MISSING, MEASURE, ROLE, COLUMNS, ALIGNMENT, ATTRIBUTE.
90 2 | SORT VARIABLES BY **.
93 "sort-variables.sps:3.29-3.30: error: SORT VARIABLES: Syntax error expecting identifier.
94 3 | SORT VARIABLES BY ATTRIBUTE **.
97 "sort-variables.sps:4.25-4.26: error: SORT VARIABLES: Syntax error expecting A or D.
98 4 | SORT VARIABLES BY NAME (**).
101 "sort-variables.sps:5.27-5.28: error: SORT VARIABLES: Syntax error expecting `)'.
102 5 | SORT VARIABLES BY NAME (A **).