04e965b226ba675a77827929306b8d5ad30043fd
[pspp] / tests / language / control / do-if.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([DO IF])
18
19 AT_SETUP([DO IF])
20 (for a in 0 1 ' '; do
21     for b in 0 1 ' '; do
22         for c in 0 1 ' '; do
23             for d in 0 1 ' '; do
24                 abcd=$a$b$c$d
25                 echo "$abcd" 1>&3
26                 if test "$a" = "1"; then
27                     echo " $abcd A"
28                 elif test "$a" = " "; then
29                     :
30                 elif test "$b" = "1"; then
31                     echo " $abcd B"
32                 elif test "$b" = " "; then
33                     :
34                 elif test "$c" = "1"; then
35                     echo " $abcd C"
36                 elif test "$c" = " "; then
37                     :
38                 elif test "$d" = "1"; then
39                     echo " $abcd D"
40                 elif test "$d" = " "; then
41                     :
42                 else
43                     echo " $abcd E"
44                 fi
45             done
46         done
47     done
48 done) >expout 3>do-if.txt || exit 99
49 AT_DATA([do-if.sps], [dnl
50 DATA LIST FILE="do-if.txt"/A B C D 1-4 ABCD 1-4 (A).
51 DO IF A.
52 PRINT OUTFILE="do-if.out"/ABCD 'A'.
53 ELSE IF B.
54 PRINT OUTFILE="do-if.out"/ABCD 'B'.
55 ELSE IF C.
56 PRINT OUTFILE="do-if.out"/ABCD 'C'.
57 ELSE IF D.
58 PRINT OUTFILE="do-if.out"/ABCD 'D'.
59 ELSE.
60 PRINT OUTFILE="do-if.out"/ABCD 'E'.
61 END IF.
62 EXECUTE.
63 ])
64 AT_CHECK([pspp do-if.sps], [0], [ignore])
65 AT_CHECK([cat do-if.out], [0], [expout])
66 AT_CLEANUP
67
68 AT_SETUP([DO IF - negative])
69 AT_DATA([do-if.sps], [dnl
70 DATA LIST LIST NOTABLE/a b c.
71 BEGIN DATA.
72 1 2 3
73 END DATA.
74
75 END IF.
76 ELSE.
77 ELSE IF 1.
78
79 DO IF 0.
80 ELSE.
81 ELSE.
82 END IF.
83
84 DO IF 0.
85 ELSE.
86 ELSE IF 0.
87 END IF.
88
89 DO IF !.
90 END IF.
91
92 DO IF 0.
93 ])
94 AT_CHECK([pspp -O format=csv do-if.sps], [1], [dnl
95 do-if.sps:6: error: END IF: This command cannot appear outside DO IF...END IF.
96
97 do-if.sps:7: error: ELSE: This command cannot appear outside DO IF...END IF.
98
99 do-if.sps:8: error: ELSE IF: This command cannot appear outside DO IF...END IF.
100
101 "do-if.sps:12.1-12.4: error: DO IF: Only one ELSE is allowed within DO IF...END IF.
102    12 | ELSE.
103       | ^~~~"
104
105 "do-if.sps:11.1-11.5: note: DO IF: This is the location of the previous ELSE clause.
106    11 | ELSE.
107       | ^~~~~"
108
109 "do-if.sps:10.1-10.8: note: DO IF: This is the location of the DO IF command.
110    10 | DO IF 0.
111       | ^~~~~~~~"
112
113 "do-if.sps:17.1-17.7: error: DO IF: ELSE IF is not allowed following ELSE within DO IF...END IF.
114    17 | ELSE IF 0.
115       | ^~~~~~~"
116
117 "do-if.sps:16.1-16.5: note: DO IF: This is the location of the previous ELSE clause.
118    16 | ELSE.
119       | ^~~~~"
120
121 "do-if.sps:15.1-15.8: note: DO IF: This is the location of the DO IF command.
122    15 | DO IF 0.
123       | ^~~~~~~~"
124
125 "do-if.sps:20.7: error: DO IF: Syntax error.
126    20 | DO IF !.
127       |       ^"
128
129 error: DO IF: At end of input: Syntax error.
130 ])
131 AT_CLEANUP