From 05abbac297d3fe97d159b8468fb463d6e7a28c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 2 Aug 2022 20:52:40 +0200 Subject: tests: add subscript in script generator --- tests/scripts/python/unparse.py | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tests/scripts') diff --git a/tests/scripts/python/unparse.py b/tests/scripts/python/unparse.py index 42b4a74e7..f3c1066b7 100755 --- a/tests/scripts/python/unparse.py +++ b/tests/scripts/python/unparse.py @@ -289,6 +289,15 @@ class UnparsePython(object): # note: deprecated since Python 3.8, replaced by ast.Constant self.add(repr(node.s)) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + node.value, + '[', + node.slice, + ']', + ) + def _ast_tuple(self, node): """Add an AST Tuple in output.""" self.add( @@ -484,6 +493,17 @@ class UnparsePerl(UnparsePython): # note: deprecated since Python 3.8, replaced by ast.Constant self.add('"%s"' % node.s.replace('$', '\\$').replace('@', '\\@')) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + (self.prefix, '$'), + node.value, + (self.prefix, None), + '->{', + node.slice, + '}', + ) + class UnparseRuby(UnparsePython): """ @@ -821,6 +841,18 @@ class UnparseTcl(UnparsePython): # note: deprecated since Python 3.8, replaced by ast.Constant self.add('"%s"' % node.s.replace('$', '\\$')) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + '[dict get ', + (self.prefix, '$'), + node.value, + (self.prefix, None), + ' ', + node.slice, + ']', + ) + class UnparseGuile(UnparsePython): """ @@ -1007,6 +1039,16 @@ class UnparseGuile(UnparsePython): # note: deprecated since Python 3.8, replaced by ast.Constant self.add('"%s"' % node.s) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + '(assoc-ref ', + node.value, + ' ', + node.slice, + ')', + ) + class UnparseJavascript(UnparsePython): """ @@ -1222,6 +1264,16 @@ class UnparsePhp(UnparsePython): # note: deprecated since Python 3.8, replaced by ast.Constant self.add('"%s"' % node.s.replace('$', '\\$')) + def _ast_subscript(self, node): + """Add an AST Subscript in output.""" + self.add( + '$', + node.value, + '[', + node.slice, + ']', + ) + def get_languages(): """Return a list of supported languages: ['python', 'perl', ...].""" -- cgit v1.2.3