From d370048b3132196af17e67be10eca2ba1c53a2dc Mon Sep 17 00:00:00 2001 From: Mingun Date: Tue, 24 Oct 2023 20:17:34 +0500 Subject: [PATCH] Fix some Perl array tests (#259) * Perl allow several pairs of brackets to define arrays: (), [] and several others Since 7ff2eda38136b4d8be044c930f1f156c7fd4dc81 Perl expression translator uses [] instead of (). Fix tests to reflect that * Fix Perl tests after changes in d9ae2b9187a3701f75137d72cf078ff37e9b4071 * Fix Perl tests after ba114f269bedba69acc094f5817c95fce7ba3edc * Fix Perl array subscript translation tests .first and .last and subscript was implemented initially in c20661acadaf23183ceae896db95c9ea69a6c524 --- .../struct/translators/TranslatorSpec.scala | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala index 31f254507..522b6c226 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -297,7 +297,7 @@ class TranslatorSpec extends AnyFunSuite { JavaCompiler -> "new ArrayList(Arrays.asList(0, 1, 100500))", JavaScriptCompiler -> "[0, 1, 100500]", LuaCompiler -> "{0, 1, 100500}", - PerlCompiler -> "(0, 1, 100500)", + PerlCompiler -> "[0, 1, 100500]", PHPCompiler -> "[0, 1, 100500]", PythonCompiler -> "[0, 1, 100500]", RubyCompiler -> "[0, 1, 100500]" @@ -347,6 +347,7 @@ class TranslatorSpec extends AnyFunSuite { JavaCompiler -> "a().get((int) 42)", JavaScriptCompiler -> "this.a[42]", LuaCompiler -> "self.a[43]", + PerlCompiler -> "@{$self->a()}[42]", PHPCompiler -> "$this->a()[42]", PythonCompiler -> "self.a[42]", RubyCompiler -> "a[42]" @@ -359,6 +360,7 @@ class TranslatorSpec extends AnyFunSuite { JavaCompiler -> "a().get((42 - 2))", JavaScriptCompiler -> "this.a[(42 - 2)]", LuaCompiler -> "self.a[(43 - 2)]", + PerlCompiler -> "@{$self->a()}[(42 - 2)]", PHPCompiler -> "$this->a()[(42 - 2)]", PythonCompiler -> "self.a[(42 - 2)]", RubyCompiler -> "a[(42 - 2)]" @@ -371,6 +373,7 @@ class TranslatorSpec extends AnyFunSuite { JavaCompiler -> "a().get(0)", JavaScriptCompiler -> "this.a[0]", LuaCompiler -> "self.a[1]", + PerlCompiler -> "@{$self->a()}[0]", PHPCompiler -> "$this->a()[0]", PythonCompiler -> "self.a[0]", RubyCompiler -> "a.first" @@ -383,6 +386,7 @@ class TranslatorSpec extends AnyFunSuite { JavaCompiler -> "a().get(a().size() - 1)", JavaScriptCompiler -> "this.a[this.a.length - 1]", LuaCompiler -> "self.a[#self.a]", + PerlCompiler -> "@{$self->a()}[-1]", PHPCompiler -> "$this->a()[count($this->a()) - 1]", PythonCompiler -> "self.a[-1]", RubyCompiler -> "a.last" @@ -396,7 +400,7 @@ class TranslatorSpec extends AnyFunSuite { JavaScriptCompiler -> "this.a.length", LuaCompiler -> "#self.a", PHPCompiler -> "count($this->a())", - PerlCompiler -> "scalar($self->a())", + PerlCompiler -> "scalar(@{$self->a()})", PythonCompiler -> "len(self.a)", RubyCompiler -> "a.length" )) @@ -520,7 +524,7 @@ class TranslatorSpec extends AnyFunSuite { JavaCompiler -> "Long.parseLong(\"12345\", 10)", JavaScriptCompiler -> "Number.parseInt(\"12345\", 10)", LuaCompiler -> "tonumber(\"12345\")", - PerlCompiler -> "\"12345\"", + PerlCompiler -> "\"12345\" + 0", PHPCompiler -> "intval(\"12345\", 10)", PythonCompiler -> "int(u\"12345\")", RubyCompiler -> "\"12345\".to_i" @@ -601,7 +605,7 @@ class TranslatorSpec extends AnyFunSuite { JavaCompiler -> "new ArrayList(Arrays.asList())", JavaScriptCompiler -> "[]", LuaCompiler -> "{}", - PerlCompiler -> "()", + PerlCompiler -> "[]", PHPCompiler -> "[]", PythonCompiler -> "[]", RubyCompiler -> "[]" @@ -614,7 +618,7 @@ class TranslatorSpec extends AnyFunSuite { JavaCompiler -> "new ArrayList(Arrays.asList())", JavaScriptCompiler -> "[]", LuaCompiler -> "{}", - PerlCompiler -> "()", + PerlCompiler -> "[]", PHPCompiler -> "[]", PythonCompiler -> "[]", RubyCompiler -> "[]" @@ -641,7 +645,7 @@ class TranslatorSpec extends AnyFunSuite { JavaCompiler -> "new ArrayList(Arrays.asList(0, 1, 2))", JavaScriptCompiler -> "[0, 1, 2]", LuaCompiler -> "{0, 1, 2}", - PerlCompiler -> "(0, 1, 2)", + PerlCompiler -> "[0, 1, 2]", PHPCompiler -> "[0, 1, 2]", PythonCompiler -> "[0, 1, 2]", RubyCompiler -> "[0, 1, 2]"