2ca25ce32caa82317f6e9be2e1eb52f41fa0876f
[pspp] / tests / language / lexer / lexer.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([lexer])
17
18 AT_SETUP([lexer ignores initial @%:@! line])
19 AT_DATA([lexer.sps], [dnl
20 #! /usr/local/bin/pspp
21 DATA LIST LIST NOTABLE /a.
22 BEGIN DATA.
23 1
24 2
25 END DATA.
26 LIST.
27 ])
28 AT_CHECK([pspp -o pspp.csv lexer.sps])
29 AT_CHECK([cat pspp.csv], [0], [dnl
30 Table: Data List
31 a
32 1.00
33 2.00
34 ])
35 AT_CLEANUP
36
37 AT_SETUP([lexer properly reports scan errors])
38 AT_DATA([lexer.sps], [dnl
39 x'123'
40 x'1x'
41 u''
42 u'012345678'
43 u'd800'
44 u'110000'
45 'foo
46 'very long unterminated string that be ellipsized in its error message
47 1e .x
48 `
49
50 ])
51 AT_CHECK([pspp -O format=csv lexer.sps], [1], [dnl
52 "lexer.sps:1.1-1.6: error: Syntax error at `x'123'': String of hex digits has 3 characters, which is not a multiple of 2."
53
54 lexer.sps:2.1-2.5: error: Syntax error at `x'1x'': `x' is not a valid hex digit.
55
56 "lexer.sps:3.1-3.3: error: Syntax error at `u''': Unicode string contains 0 bytes, which is not in the valid range of 1 to 8 bytes."
57
58 "lexer.sps:4.1-4.12: error: Syntax error at `u'012345678'': Unicode string contains 9 bytes, which is not in the valid range of 1 to 8 bytes."
59
60 lexer.sps:5.1-5.7: error: Syntax error at `u'd800'': U+D800 is not a valid Unicode code point.
61
62 lexer.sps:6.1-6.9: error: Syntax error at `u'110000'': U+110000 is not a valid Unicode code point.
63
64 lexer.sps:7.1-7.4: error: Syntax error at `'foo': Unterminated string constant.
65
66 lexer.sps:8.1-8.70: error: Syntax error at `'very long unterminated string that be ellipsized in its err...': Unterminated string constant.
67
68 lexer.sps:9.1-9.2: error: Syntax error at `1e': Missing exponent following `1e'.
69
70 lexer.sps:9.4: error: Syntax error at `.': Unexpected `.' in middle of command.
71
72 lexer.sps:9: error: Unknown command `x'.
73
74 lexer.sps:10.1: error: Syntax error at ``': Bad character ``' in input.
75
76 lexer.sps:11.1: error: Syntax error at `�': Bad character U+FFFD in input.
77 ])
78 AT_CLEANUP
79
80 # Bug #47602.
81 AT_SETUP([lexer crash due to null byte])
82 # Intentionally leave out the new-line and add a null byte:
83 printf "datA dist list notable file='input.txt'/a b c.
84 lis|.\0" > lexer.sps
85
86 # We sort the output into a predictable order because the lexer finds
87 # and reports null bytes as soon as it reads them into its input
88 # buffer, as opposed to when it encounters them during tokenization.
89 # This also means that null bytes might be reported as part of one
90 # command or another or none, hence removing the LIST: prefix.
91 AT_CHECK([pspp -O format=csv lexer.sps > lexer.csv], [1])
92 AT_CHECK([sed '/^$/d
93 s/LIST: //' lexer.csv | sort], [0], [dnl
94 lexer.sps: error: Bad character U+0000 in input.
95 lexer.sps:1: error: Unknown command `datA dist'.
96 lexer.sps:2: error: LIST is allowed only after the active dataset has been defined.
97 ])
98 AT_CLEANUP