summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeistungsabfall <Leistungsabfall@users.noreply.github.com>2021-10-24 18:35:47 +0200
committerGitHub <noreply@github.com>2021-10-24 18:35:47 +0200
commit616c36733c0804d2f7a611cbb744619573da1210 (patch)
tree01e273eca15b218d34fc5703470a33429cd17c1a
parent907df2c247ed56d4c4562249fbdee482217fce34 (diff)
downloadpygments-git-616c36733c0804d2f7a611cbb744619573da1210.tar.gz
robotframework: fix empty braces being thrown away after list or dict… (#1921)
* robotframework: fix empty braces being thrown away after list or dict variable * robotframework: add test cases to ensure correct behaviour
-rw-r--r--pygments/lexers/robotframework.py2
-rw-r--r--tests/test_robotframework_lexer.py38
2 files changed, 39 insertions, 1 deletions
diff --git a/pygments/lexers/robotframework.py b/pygments/lexers/robotframework.py
index 305cc26f..3c212f5e 100644
--- a/pygments/lexers/robotframework.py
+++ b/pygments/lexers/robotframework.py
@@ -99,7 +99,7 @@ class VariableTokenizer:
yield var.identifier + '{', SYNTAX
yield from self.tokenize(var.base, VARIABLE)
yield '}', SYNTAX
- if var.index:
+ if var.index is not None:
yield '[', SYNTAX
yield from self.tokenize(var.index, VARIABLE)
yield ']', SYNTAX
diff --git a/tests/test_robotframework_lexer.py b/tests/test_robotframework_lexer.py
new file mode 100644
index 00000000..d768885f
--- /dev/null
+++ b/tests/test_robotframework_lexer.py
@@ -0,0 +1,38 @@
+"""
+ Pygments Robot Framework lexer tests
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import pytest
+
+from pygments.lexers.robotframework import RobotFrameworkLexer
+
+
+@pytest.fixture(scope='module')
+def lexer():
+ yield RobotFrameworkLexer()
+
+
+def assert_same_text(lexer, text):
+ """Show that lexed text does not remove any content. """
+ tokens = list(lexer.get_tokens_unprocessed(text))
+ output = ''.join(t[2] for t in tokens)
+ assert text == output
+
+
+def test_empty_brackets_after_scalar_variable(lexer):
+ assert_same_text(lexer, '*** Variables ***\n'
+ '${test}[]\n')
+
+
+def test_empty_brackets_after_list_variable(lexer):
+ assert_same_text(lexer, '*** Variables ***\n'
+ '@{test}[]\n')
+
+
+def test_empty_brackets_after_dict_variable(lexer):
+ assert_same_text(lexer, '*** Variables ***\n'
+ '&{test}[]\n')