[formatter] support negative indicies

for example '{items[-3]}'
This commit is contained in:
Mike Fährmann
2025-09-11 20:50:50 +02:00
parent 0dfc3b18d3
commit 9035b92230
2 changed files with 7 additions and 0 deletions

View File

@@ -178,6 +178,11 @@ class TestFormatter(unittest.TestCase):
self._run_test("{l[0]}" , "a")
self._run_test("{a[6]}" , "w")
def test_indexing_negative(self):
self._run_test("{l[-1]}" , "c")
self._run_test("{a[-7]}" , "o")
self._run_test("{a[-0]}" , "h") # same as a[0]
def test_dict_access(self):
self._run_test("{d[a]}" , "foo")
self._run_test("{d['a']}", "foo")