Skip to content

Commit 7f2949f

Browse files
committed
parsing error tests and changes
1 parent ab535f8 commit 7f2949f

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

atest/robot/parsing/invalid.robot

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ Directory Containing File With Invalid Encoding
4848
... UnicodeDecodeError: .*
4949
... ${PARSING}/invalid_encoding/invalid_encoding.robot
5050

51+
If with else after else
52+
Run tests and check parsing error
53+
... ${PARSING}/if/else_after_else.robot
54+
... .* Invalid second ELSE detected
55+
... ${PARSING}/if/else_after_else.robot
56+
57+
If with else if after else
58+
Run tests and check parsing error
59+
... ${PARSING}/if/else_if_after_else.robot
60+
... .* Invalid ELSE IF detected after ELSE
61+
... ${PARSING}/if/else_if_after_else.robot
62+
5163
Multisource Containing File With Invalid Encoding
5264
Run tests and check parsing error
5365
... ${PARSING}/invalid_encoding/invalid_encoding.robot ${PARSING}/invalid_encoding/a_valid_file.robot
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*** Test Cases ***
2+
Invalid else after else
3+
IF ${False}
4+
Log something
5+
ELSE
6+
Log something
7+
ELSE
8+
Log something
9+
END
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*** Test Cases ***
2+
Invalid else after else
3+
IF ${False}
4+
Log something
5+
ELSE
6+
Log something
7+
ELSE IF ${True}
8+
Log something
9+
END

src/robot/parsing/lexer/blocklexers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ def input(self, statement):
252252
if self._else_seen:
253253
raise DataError("line [%s] : Invalid second ELSE detected" % lexer.lineno)
254254
self._else_seen = True
255+
if isinstance(lexer, ElseIfStatementLexer) and self._else_seen:
256+
raise DataError("line [%s] : Invalid ELSE IF detected after ELSE" % lexer.lineno)
255257

256258
def lexer_classes(self):
257259
return (IfStatementLexer, ElseIfStatementLexer, ElseLexer, ForLoopHeaderLexer, EndLexer, KeywordCallLexer)

src/robot/parsing/lexer/statementlexers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ def lex(self):
212212
self.statement[0].type = Token.ELSE_IF
213213
self.statement[1].type = Token.ARGUMENT
214214

215+
@property
216+
def lineno(self):
217+
return self.statement[0].lineno
218+
215219

216220
class ElseLexer(StatementLexer):
217221

0 commit comments

Comments
 (0)