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([ASCII driver -- rendering corner cases])

AT_SETUP([ASCII driver overwriting single-width text])
AT_KEYWORDS([render rendering])
AT_DATA([input], [dnl
## overwriting rest of line
# plain
0 0 0 abc
1 0 0 BCD
# emphasized over plain
0 1 0 efg
1 1 1 FGH
# plain over emphasized
0 2 1 ijk
1 2 0 JKL
# emphasized over emphasized
0 3 1 mno
1 3 1 NOP

## overwriting partial line
# plain
0 5 0 abcdef
0 5 0 A
2 5 0 CDE
# emphasized over plain
0 6 0 ghijkl
0 6 1 G
2 6 1 IJK
# plain over emphasized
0 7 1 mnopqr
0 7 0 M
2 7 0 OPQ
# emphasized over emphasized
0 8 1 stuvwx
0 8 1 S
2 8 1 UVW

## overwriting rest of line with double-width characters
# plain
0 10 0 kakiku
2 10 0 きくけ
# emphasized over plain
0 11 0 kakiku
2 11 1 きくけ
# plain over emphasized
0 12 1 kakiku
2 12 0 きくけ
# emphasized over emphasized
0 13 1 kakiku
2 13 1 きくけ

## overwriting partial line with double-width characters
# plain
0 15 0 kakikukeko
0 15 0 か
4 15 0 くけ
# emphasized over plain
0 16 0 kakikukeko
0 16 1 か
4 16 1 くけ
# plain over emphasized
0 17 1 kakikukeko
0 17 0 か
4 17 0 くけ
# emphasized over emphasized
0 18 1 kakikukeko
0 18 1 か
4 18 1 くけ
])
AT_CHECK([ascii-test --emph=none input], [0], [dnl
aBCD
eFGH
iJKL
mNOP

AbCDEf
GhIJKl
MnOPQr
StUVWx

kaきくけ
kaきくけ
kaきくけ
kaきくけ

かkiくけko
かkiくけko
かkiくけko
かkiくけko
])
AT_CHECK([ascii-test --emph=bold input], [0], [dnl
aBCD
eFGH
iJKL
mNOP

AbCDEf
GhIJKl
MnOPQr
StUVWx

kaきくけ
kaきくけ
kaきくけ
kaきくけ

かkiくけko
かkiくけko
かkiくけko
かkiくけko
])
AT_CHECK([ascii-test --emph=underline input], [0], [dnl
aBCD
eFGH
iJKL
mNOP

AbCDEf
GhIJKl
MnOPQr
StUVWx

kaきくけ
kaきくけ
kaきくけ
kaきくけ

かkiくけko
かkiくけko
かkiくけko
かkiくけko
])
AT_CLEANUP

AT_SETUP([ASCII driver overwriting double-width text])
AT_KEYWORDS([render rendering])
AT_DATA([input], [dnl
## overwrite rest of line, aligned double-width over double-width
# plain
0 0 0 あいう
2 0 0 きくけ
# emphasized over plain
0 1 0 あいう
2 1 1 きくけ
# plain over emphasized
0 2 1 あいう
2 2 0 きくけ
# emphasized over emphasized
0 3 1 あいう
2 3 1 きくけ

## overwrite rest of line, misaligned double-width over double-width
# plain
0 5 0 あいう
3 5 0 きくけ
# emphasized over plain
0 6 0 あいう
3 6 1 きくけ
# plain over emphasized
0 7 1 あいう
3 7 0 きくけ
# emphasized over emphasized
0 8 1 あいう
3 8 1 きくけ

## overwrite partial line, aligned double-width over double-width
# plain
0 10 0 あいうえお
0 10 0 か
4 10 0 くけ
# emphasized over plain
0 11 0 あいうえお
0 11 1 か
4 11 1 くけ
# plain over emphasized
0 12 1 あいうえお
0 12 0 か
4 12 0 くけ
# emphasized over emphasized
0 13 1 あいうえお
0 13 1 か
4 13 1 くけ

## overwrite partial line, misaligned double-width over double-width
# plain
0 15 0 あいうえおさ
1 15 0 か
5 15 0 くけ
# emphasized over plain
0 16 0 あいうえおさ
1 16 1 か
5 16 1 くけ
# plain over emphasized
0 17 1 あいうえおさ
1 17 0 か
5 17 0 くけ
# emphasized over emphasized
0 18 1 あいうえおさ
1 18 1 か
5 18 1 くけ

## overwrite rest of line, aligned single-width over double-width
# plain
0 20 0 あいう
2 20 0 kikuko
# emphasized over plain
0 21 0 あいう
2 21 1 kikuko
# plain over emphasized
0 22 1 あいう
2 22 0 kikuko
# emphasized over emphasized
0 23 1 あいう
2 23 1 kikuko

## overwrite rest of line, misaligned single-width over double-width
# plain
0 25 0 あいう
3 25 0 kikuko
# emphasized over plain
0 26 0 あいう
3 26 1 kikuko
# plain over emphasized
0 27 1 あいう
3 27 0 kikuko
# emphasized over emphasized
0 28 1 あいう
3 28 1 kikuko

## overwrite partial line, aligned single-width over double-width
# plain
0 30 0 あいうえお
0 30 0 ka
4 30 0 kuke
# emphasized over plain
0 31 0 あいうえお
0 31 1 ka
4 31 1 kuke
# plain over emphasized
0 32 1 あいうえお
0 32 0 ka
4 32 0 kuke
# emphasized over emphasized
0 33 1 あいうえお
0 33 1 ka
4 33 1 kuke

## overwrite partial line, misaligned single-width over double-width
# plain
0 35 0 あいうえおさ
1 35 0 a
5 35 0 kuke
# emphasized over plain
0 36 0 あいうえおさ
1 36 1 a
5 36 1 kuke
# plain over emphasized
0 37 1 あいうえおさ
1 37 0 a
5 37 0 kuke
# emphasized over emphasized
0 38 1 あいうえおさ
1 38 1 a
5 38 1 kuke
])
AT_CHECK([ascii-test --emph=none input], [0], [dnl
あきくけ
あきくけ
あきくけ
あきくけ

あ?きくけ
あ?きくけ
あ?きくけ
あ?きくけ

かいくけお
かいくけお
かいくけお
かいくけお

?か??くけ?さ
?か??くけ?さ
?か??くけ?さ
?か??くけ?さ

あkikuko
あkikuko
あkikuko
あkikuko

あ?kikuko
あ?kikuko
あ?kikuko
あ?kikuko

kaいkukeお
kaいkukeお
kaいkukeお
kaいkukeお

?aい?kuke?さ
?aい?kuke?さ
?aい?kuke?さ
?aい?kuke?さ
])
AT_CHECK([ascii-test --emph=bold input], [0], [dnl
あきくけ
あきくけ
あきくけ
あきくけ

あ?きくけ
あ?きくけ
あ?きくけ
あ?きくけ

かいくけお
かいくけお
かいくけお
かいくけお

?か??くけ?さ
?か??くけ?さ
?か??くけ?さ
?か??くけ?さ

あkikuko
あkikuko
あkikuko
あkikuko

あ?kikuko
あ?kikuko
あ?kikuko
あ?kikuko

kaいkukeお
kaいkukeお
kaいkukeお
kaいkukeお

?aい?kuke?さ
?aい?kuke?さ
?aい?kuke?さ
?aい?kuke?さ
])
AT_CHECK([ascii-test --emph=underline input], [0], [dnl
あきくけ
あきくけ
あきくけ
あきくけ

あ?きくけ
あ?きくけ
あ?きくけ
あ?きくけ

かいくけお
かいくけお
かいくけお
かいくけお

?か??くけ?さ
?か??くけ?さ
?か??くけ?さ
?か??くけ?さ

あkikuko
あkikuko
あkikuko
あkikuko

あ?kikuko
あ?kikuko
あ?kikuko
あ?kikuko

kaいkukeお
kaいkukeお
kaいkukeお
kaいkukeお

?aい?kuke?さ
?aい?kuke?さ
?aい?kuke?さ
?aい?kuke?さ
])
AT_CLEANUP

AT_SETUP([ASCII driver overwriting combining characters])
AT_KEYWORDS([render rendering])
AT_DATA([input], [dnl
## overwriting rest of line, ordinary over combining
# plain
0 0 0 àéî
1 0 0 xyz
# emphasized over plain
0 1 0 àéî
1 1 1 xyz
# plain over emphasized
0 2 1 àéî
1 2 0 xyz
# emphasized over emphasized
0 3 1 àéî
1 3 1 xyz

## overwriting rest of line, combining over ordinary
# plain
0 5 0 xyz
1 5 0 àéî
# emphasized over plain
0 6 0 xyz
1 6 1 àéî
# plain over emphasized
0 7 1 xyz
1 7 0 àéî
# emphasized over emphasized
0 8 1 xyz
1 8 1 àéî

## overwriting partial line, ordinary over combining
# plain
0 10 0 àéîo̧ũẙ
0 10 0 a
2 10 0 iou
# emphasized over plain
0 11 0 àéîo̧ũẙ
0 11 1 a
2 11 1 iou
# plain over emphasized
0 12 1 àéîo̧ũẙ
0 12 0 a
2 12 0 iou
# emphasized over emphasized
0 13 1 àéîo̧ũẙ
0 13 1 a
2 13 1 iou

## overwriting partial line, combining over ordinary
# plain
0 15 0 aeiouy
0 15 0 à
2 15 0 îo̧ũ
# emphasized over plain
0 16 0 aeiouy
0 16 1 à
2 16 1 îo̧ũ
# plain over emphasized
0 17 1 aeiouy
0 17 0 à
2 17 0 îo̧ũ
# emphasized over emphasized
0 18 1 aeiouy
0 18 1 à
2 18 1 îo̧ũ
])
AT_CHECK([ascii-test --emph=none input], [0], [dnl
àxyz
àxyz
àxyz
àxyz

xàéî
xàéî
xàéî
xàéî

aéiouẙ
aéiouẙ
aéiouẙ
aéiouẙ

àeîo̧ũy
àeîo̧ũy
àeîo̧ũy
àeîo̧ũy
])
AT_CHECK([ascii-test --emph=bold input], [0], [dnl
àxyz
àxyz
àxyz
àxyz

xàéî
xàéî
xàéî
xàéî

aéiouẙ
aéiouẙ
aéiouẙ
aéiouẙ

àeîo̧ũy
àeîo̧ũy
àeîo̧ũy
àeîo̧ũy
])
AT_CHECK([ascii-test --emph=underline input], [0], [dnl
àxyz
àxyz
àxyz
àxyz

xàéî
xàéî
xàéî
xàéî

aéiouẙ
aéiouẙ
aéiouẙ
aéiouẙ

àeîo̧ũy
àeîo̧ũy
àeîo̧ũy
àeîo̧ũy
])
AT_CLEANUP

AT_SETUP([ASCII driver u8_line_set_length])
AT_KEYWORDS([render rendering])
AT_DATA([input], [dnl
0 0 0 àéî
0 1 0 àéî
0 2 0 àéî
0 3 0 àéî
0 4 0 àéî
set-length 0 4
set-length 1 3
set-length 2 2
set-length 3 1
set-length 4 0

0 5 0 あい
0 6 0 あい
0 7 0 あい
0 8 0 あい
0 9 0 あい
0 10 0 あい
set-length 5 5
set-length 6 4
set-length 7 3
set-length 8 2
set-length 9 1
set-length 10 0
])
AT_CHECK([ascii-test input], [0], [dnl
àéî
àéî
àé
à

あい
あい
あ?
あ
?
])
AT_CLEANUP

AT_SETUP([ASCII driver syntax printback])
AT_DATA([ascii.sps], [dnl
SET PRINTBACK=ON.
DATA LIST LIST /x * y * a (a23).
BEGIN DATA.
1 11 One
2 22 Two
3 33 Three
END DATA.

REGRESSION
/VARIABLES= a
/DEPENDENT= x y
/STATISTICS=COEFF R ANOVA.
])
AT_CHECK([pspp ascii.sps], [0], [dnl
SET PRINTBACK=ON.

DATA LIST LIST /x * y * a (a23).

Reading free-form data from INLINE.
+--------+------+
|Variable|Format|
+--------+------+
|x       |F8.0  |
|y       |F8.0  |
|a       |A23   |
+--------+------+

BEGIN DATA.
1 11 One
2 22 Two
3 33 Three
END DATA.


REGRESSION
/VARIABLES= a

ascii.sps:10.13: warning: REGRESSION: a is not a numeric variable.  It will not
be included in the variable list.
   10 | /VARIABLES= a
      |             ^

/DEPENDENT= x y
/STATISTICS=COEFF R ANOVA.
])

AT_CLEANUP

AT_SETUP([ASCII unicode box chars])

AT_DATA([uc.sps], [dnl
SET FORMAT=F8.4.
DATA LIST NOTABLE LIST /x * .
BEGIN DATA.
1
2
3
END DATA.

DESCRIPTIVES X.
])


AT_CHECK([pspp -O box=unicode uc.sps], [0], [dnl
                 Descriptive Statistics
╭────────────────────┬─┬──────┬───────┬───────┬───────╮
│                    │N│ Mean │Std Dev│Minimum│Maximum│
├────────────────────┼─┼──────┼───────┼───────┼───────┤
│x                   │3│2.0000│ 1.0000│ 1.0000│ 3.0000│
│Valid N (listwise)  │3│      │       │       │       │
│Missing N (listwise)│0│      │       │       │       │
╰────────────────────┴─┴──────┴───────┴───────┴───────╯
])

AT_CLEANUP

AT_SETUP([ASCII crash on empty line])

AT_DATA([print.sps], [dnl
data list notable /x y 1-2.
begin data.
12
end data.

print.

execute.
])

AT_CHECK([pspp print.sps], [0], [ignore])

AT_CLEANUP



dnl A crash has been observed when the first character
dnl of a string is U+0008
AT_SETUP([ASCII crash on non-printables])

AT_DATA([nonprint.sps], [dnl
DATA LIST FREE /s8 (a8).
BEGIN DATA.
xxxxxx zzz a qqq
END DATA.

LIST.
])

AT_CHECK([pspp nonprint.sps], [0], [ignore])

AT_CLEANUP
