dnl PSPP - a program for statistical analysis.
dnl Copyright (C) 2017 Free Software Foundation, Inc.
dnl
dnl This program is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation, either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
dnl
AT_BANNER([DO IF])

AT_SETUP([DO IF])
(for a in 0 1 ' '; do
    for b in 0 1 ' '; do
	for c in 0 1 ' '; do
	    for d in 0 1 ' '; do
		abcd=$a$b$c$d
		echo "$abcd" 1>&3
		if test "$a" = "1"; then
		    echo " $abcd A"
		elif test "$a" = " "; then
		    :
		elif test "$b" = "1"; then
		    echo " $abcd B"
		elif test "$b" = " "; then
		    :
		elif test "$c" = "1"; then
		    echo " $abcd C"
		elif test "$c" = " "; then
		    :
		elif test "$d" = "1"; then
		    echo " $abcd D"
		elif test "$d" = " "; then
		    :
		else
		    echo " $abcd E"
		fi
	    done
	done
    done
done) >expout 3>do-if.txt || exit 99
AT_DATA([do-if.sps], [dnl
DATA LIST FILE="do-if.txt"/A B C D 1-4 ABCD 1-4 (A).
DO IF A.
PRINT OUTFILE="do-if.out"/ABCD 'A'.
ELSE IF B.
PRINT OUTFILE="do-if.out"/ABCD 'B'.
ELSE IF C.
PRINT OUTFILE="do-if.out"/ABCD 'C'.
ELSE IF D.
PRINT OUTFILE="do-if.out"/ABCD 'D'.
ELSE.
PRINT OUTFILE="do-if.out"/ABCD 'E'.
END IF.
EXECUTE.
])
AT_CHECK([pspp do-if.sps], [0], [ignore])
AT_CHECK([cat do-if.out], [0], [expout])
AT_CLEANUP

AT_SETUP([DO IF - negative])
AT_DATA([do-if.sps], [dnl
DATA LIST LIST NOTABLE/a b c.
BEGIN DATA.
1 2 3
END DATA.

END IF.
ELSE.
ELSE IF 1.

DO IF 0.
ELSE.
ELSE.
END IF.

DO IF 0.
ELSE.
ELSE IF 0.
END IF.

DO IF !.
END IF.

DO IF 0.
])
AT_CHECK([pspp -O format=csv do-if.sps], [1], [dnl
"do-if.sps:6.1-6.6: error: END IF: This command cannot appear outside DO IF...END IF.
    6 | END IF.
      | ^~~~~~"

"do-if.sps:7.1-7.4: error: ELSE: This command cannot appear outside DO IF...END IF.
    7 | ELSE.
      | ^~~~"

"do-if.sps:8.1-8.7: error: ELSE IF: This command cannot appear outside DO IF...END IF.
    8 | ELSE IF 1.
      | ^~~~~~~"

"do-if.sps:12.1-12.4: error: DO IF: Only one ELSE is allowed within DO IF...END IF.
   12 | ELSE.
      | ^~~~"

"do-if.sps:11.1-11.5: note: DO IF: This is the location of the previous ELSE clause.
   11 | ELSE.
      | ^~~~~"

"do-if.sps:10.1-10.8: note: DO IF: This is the location of the DO IF command.
   10 | DO IF 0.
      | ^~~~~~~~"

"do-if.sps:17.1-17.7: error: DO IF: ELSE IF is not allowed following ELSE within DO IF...END IF.
   17 | ELSE IF 0.
      | ^~~~~~~"

"do-if.sps:16.1-16.5: note: DO IF: This is the location of the previous ELSE clause.
   16 | ELSE.
      | ^~~~~"

"do-if.sps:15.1-15.8: note: DO IF: This is the location of the DO IF command.
   15 | DO IF 0.
      | ^~~~~~~~"

"do-if.sps:20.7: error: DO IF: Syntax error parsing expression.
   20 | DO IF !.
      |       ^"

error: DO IF: At end of input: Syntax error expecting END IF.
])
AT_CLEANUP
