c35329c53bf1d05fe8b92f87f1513376ba785e7b
[pspp] / tests / language / dictionary / sort-variables.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([SORT VARIABLES])
17
18 AT_SETUP([SORT VARIABLES])
19 # This reverses the order of its input lines.
20 # From the GNU sed manual.
21 tac () {
22     sed -n '1! G
23 $ p
24 h'
25 }
26
27 test_sort () {
28     cat > sort-variables.sps <<EOF
29 DATA LIST FREE/$1.
30 $2
31 SORT VARIABLES $3.
32 DISPLAY NAMES.
33 SORT VARIABLES $3(D).
34 DISPLAY NAMES.
35 EOF
36     AT_CHECK_UNQUOTED([pspp -O format=csv sort-variables.sps], [0],
37 [Variable
38 `for var in $4; do echo $var; done`
39
40 Variable
41 `for var in $4; do echo $var; done | tac`
42 ])
43 }
44
45 test_sort 'x100 c b x99 a y400 y5' '' NAME 'a b c x99 x100 y5 y400'
46 test_sort 'c(a10) a(a5) b' '' TYPE 'b a c'
47 test_sort 'a (datetime) b (f) c (a5) d (a2) e (a1)' '' FORMAT 'e d c b a'
48 test_sort 'a b c' \
49     'VARIABLE LABEL a "hi there".' \
50     LABEL 'b c a'
51 test_sort 'a b c' \
52     'VALUE LABELS a 123 "xyzzy".' \
53     VALUES 'b c a'
54 test_sort 'a b c' \
55     'MISSING VALUES a (123).' \
56     MISSING 'b c a'
57 test_sort 'a b c' \
58     'VARIABLE LEVEL a (SCALE) b (ORDINAL) c (NOMINAL).' \
59     MEASURE 'c b a'
60 test_sort 'b n i s t p' \
61     'VARIABLE ROLE /INPUT i /TARGET t /BOTH b /NONE n /PARTITION p /SPLIT s.' \
62     ROLE 'i t b n p s'
63 test_sort 'c10 c5 c15 c9' \
64     'VARIABLE WIDTH c10(10) c5(5) c15(15) c9(9).' \
65     COLUMNS 'c5 c9 c10 c15'
66 test_sort 'c l r' \
67     'VARIABLE ALIGNMENT c (CENTER) l (LEFT) r (RIGHT).' \
68     ALIGNMENT 'l r c'
69 test_sort 'az ax ay ab' \
70     'VARIABLE ATTRIBUTE VARIABLES=az ATTRIBUTE=key("z").
71      VARIABLE ATTRIBUTE VARIABLES=ax ATTRIBUTE=key("x").
72      VARIABLE ATTRIBUTE VARIABLES=ay ATTRIBUTE=key("y").
73      VARIABLE ATTRIBUTE VARIABLES=ab ATTRIBUTE=key("b").' \
74     'ATTRIBUTE key' 'ab ax ay az'
75 AT_CLEANUP