Skip to content

Commit 9aa4c40

Browse files
committed
lexer: Lex tests withtout name
1 parent 48d59f1 commit 9aa4c40

File tree

3 files changed

+5
-26
lines changed

3 files changed

+5
-26
lines changed

atest/robot/core/empty_tc_and_uk.robot

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ Resource atest_resource.robot
77
Test Case Without Name
88
Check Test Case ${EMPTY}
99

10-
User Keyword Without Name
11-
Check Test Case ${TESTNAME}
12-
1310
Empty Test Case
1411
Check Test Case ${TESTNAME}
1512

atest/testdata/core/empty_testcase_and_uk.robot

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ Documentation NO RIDE because it removes empty [Return]
55
[Documentation] FAIL Test case name cannot be empty.
66
Fail Should not be executed
77

8-
User Keyword Without Name
9-
[Documentation] FAIL Keyword name cannot be empty.
10-
\ argh
11-
Fail Should not be executed
12-
138
Empty Test Case
149
[Documentation] FAIL Test case contains no keywords.
1510

src/robot/parsing/lexer/lexers.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,25 +214,20 @@ class TestCaseSectionLexer(SectionLexer):
214214
markers = ('Test Case', 'Test Cases', 'Task', 'Tasks')
215215

216216
def lexer_classes(self):
217-
return (TestCaseSectionHeaderLexer, TestCaseLexer,
218-
InvalidTestOrKeywordLexer)
217+
return (TestCaseSectionHeaderLexer, TestCaseLexer)
219218

220219

221220
class KeywordSectionLexer(SettingSectionLexer):
222221
markers = ('Keyword', 'Keywords')
223222

224223
def lexer_classes(self):
225-
return (KeywordSectionHeaderLexer, KeywordLexer,
226-
InvalidTestOrKeywordLexer)
224+
return (KeywordSectionHeaderLexer, KeywordLexer)
227225

228226

229227
class TestOrKeywordLexer(BlockLexer):
230228
_in_for_loop = False
231229
_old_style_for = None
232-
233-
@classmethod
234-
def handles(cls, statement):
235-
return bool(statement[0].value)
230+
_name_set = False
236231

237232
def accepts_more(self, statement):
238233
return not statement[0].value
@@ -247,8 +242,9 @@ def input(self, statement):
247242

248243
def _handle_name_or_indentation(self, statement):
249244
# TODO: Use dedicated lexers?
250-
if statement[0].value:
245+
if not self._name_set:
251246
statement.pop(0).type = Token.NAME
247+
self._name_set = True
252248
while statement and not statement[0].value:
253249
statement.pop(0).type = Token.IGNORE
254250

@@ -288,15 +284,6 @@ def lex(self, ctx):
288284
TestOrKeywordLexer.lex(self, ctx)
289285

290286

291-
class InvalidTestOrKeywordLexer(BlockLexer):
292-
293-
def accepts_more(self, statement):
294-
return not statement[0].value
295-
296-
def lexer_classes(self):
297-
return (ErrorLexer,)
298-
299-
300287
class TestOrKeywordSettingLexer(SettingLexer):
301288

302289
@classmethod

0 commit comments

Comments
 (0)