From 5932bd9c0ea4c316fc8d4a07e60b0a204c17db1a Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 13:51:10 +0500 Subject: [PATCH 01/15] TranslatorSpec: C++: Fix test for boolean to string conversion (bool.to_i) The behavior was changed in PR #106 (b8896546cb773fb01e3a709d24507e475ad8d247) Fixes [info] - cpp_stl:some_bool.to_i *** FAILED *** [info] "[((some_bool()) ? 1 : 0])" was not equal to "[some_bool(])" (TranslatorSpec.scala:197) [info] Analysis: [info] "[((some_bool()) ? 1 : 0])" -> "[some_bool(])" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d0e93b38b..e27808c02 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -203,7 +203,7 @@ class TranslatorSpec extends AnyFunSpec { } full("some_bool.to_i", CalcBooleanType, CalcIntType, Map[LanguageCompilerStatic, String]( - CppCompiler -> "some_bool()", + CppCompiler -> "((some_bool()) ? 1 : 0)", CSharpCompiler -> "(SomeBool ? 1 : 0)", GoCompiler -> """tmp1 := 0 |if this.SomeBool { From 4012ce16a5be3e6641874b87fe4340be9f68e882 Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 15:02:05 +0500 Subject: [PATCH 02/15] TranslatorSpec: C++: Fix to_i conversion that was changed in 0acd030cbd60915657365d2eafacdade45690eec Fixes [info] - cpp_stl:"12345".to_i *** FAILED *** [info] "[kaitai::kstream::string_to_int](std::string("12345"..." was not equal to "[std::stoi](std::string("12345"..." (TranslatorSpec.scala:520) [info] Analysis: [info] "[kaitai::kstream::string_to_int](std::string("12345"..." -> "[std::stoi](std::string("12345"..." [info] - cpp_stl:"1234fe".to_i(16) *** FAILED *** [info] "[kaitai::kstream::string_to_int(std::string("1234fe")], 16)" was not equal to "[std::stoi(std::string("1234fe"), 0], 16)" (TranslatorSpec.scala:533) [info] Analysis: [info] "[kaitai::kstream::string_to_int(std::string("1234fe")], 16)" -> "[std::stoi(std::string("1234fe"), 0], 16)" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 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 e27808c02..658fb513f 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -537,7 +537,7 @@ class TranslatorSpec extends AnyFunSpec { )) full("\"12345\".to_i", CalcIntType, CalcIntType, Map[LanguageCompilerStatic, String]( - CppCompiler -> "std::stoi(std::string(\"12345\"))", + CppCompiler -> "kaitai::kstream::string_to_int(std::string(\"12345\"))", CSharpCompiler -> "Convert.ToInt64(\"12345\", 10)", GoCompiler -> "func()(int){i, err := strconv.Atoi(\"12345\"); if (err != nil) { panic(err) }; return i}()", JavaCompiler -> "Long.parseLong(\"12345\", 10)", @@ -550,7 +550,7 @@ class TranslatorSpec extends AnyFunSpec { )) full("\"1234fe\".to_i(16)", CalcIntType, CalcIntType, Map[LanguageCompilerStatic, String]( - CppCompiler -> "std::stoi(std::string(\"1234fe\"), 0, 16)", + CppCompiler -> "kaitai::kstream::string_to_int(std::string(\"1234fe\"), 16)", CSharpCompiler -> "Convert.ToInt64(\"1234fe\", 16)", GoCompiler -> "func()(int64){i, err := strconv.ParseInt(\"1234fe\", 16, 64); if (err != nil) { panic(err) }; return i}()", JavaCompiler -> "Long.parseLong(\"1234fe\", 16)", From 0bb6be57c1940b607b151959eadc99230a6139d8 Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 15:51:42 +0500 Subject: [PATCH 03/15] TranslatorSpec: C#: Fix string reverse tests that was changed in f8a9742bae939f7fe2b400f862bef8f36a3a6ca6 --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 658fb513f..243accb3f 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -525,7 +525,7 @@ class TranslatorSpec extends AnyFunSpec { full("\"str\".reverse", CalcIntType, CalcStrType, Map[LanguageCompilerStatic, String]( CppCompiler -> "kaitai::kstream::reverse(std::string(\"str\"))", - CSharpCompiler -> "new string(Array.Reverse(\"str\".ToCharArray()))", + CSharpCompiler -> "KaitaiStream.StringReverse(\"str\")", GoCompiler -> "kaitai.StringReverse(\"str\")", JavaCompiler -> "new StringBuilder(\"str\").reverse().toString()", JavaScriptCompiler -> "Array.from(\"str\").reverse().join('')", From 9100de399e253f0dc72c11f9fcf10f2fccb91b5b Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 15:46:52 +0500 Subject: [PATCH 04/15] TranslatorSpec: C#, JavaScript, Lua: Fix tests of length calculation of byte arrays Fixes [info] - csharp:[0, 1, 2].length *** FAILED *** [info] no expected result, but actual result is new byte[] { 0, 1, 2 }.Length (TranslatorSpec.scala:332) [info] - javascript:[0, 1, 2].length *** FAILED *** [info] no expected result, but actual result is [0, 1, 2].length (TranslatorSpec.scala:332) [info] - lua:[0, 1, 2].length *** FAILED *** [info] "[#"\000\001\002"]" was not equal to "[string.len("str")]" (TranslatorSpec.scala:332) [info] Analysis: [info] "[#"\000\001\002"]" -> "[string.len("str")]" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 243accb3f..fc6ed2b79 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -343,9 +343,11 @@ class TranslatorSpec extends AnyFunSpec { describe("operations") { full("[0, 1, 2].length", CalcIntType, CalcIntType, Map[LanguageCompilerStatic, String]( CppCompiler -> "std::string(\"\\x00\\x01\\x02\", 3).length()", + CSharpCompiler -> "new byte[] { 0, 1, 2 }.Length", GoCompiler -> "len([]uint8{0, 1, 2})", JavaCompiler -> "new byte[] { 0, 1, 2 }.length", - LuaCompiler -> "string.len(\"str\")", + JavaScriptCompiler -> "[0, 1, 2].length", + LuaCompiler -> "#\"\\000\\001\\002\"", PerlCompiler -> "length(pack('C*', (0, 1, 2)))", PHPCompiler -> "strlen(\"\\x00\\x01\\x02\")", PythonCompiler -> "len(b\"\\x00\\x01\\x02\")", From cdf4bcbe4141befeec120ab6e43690f0631a0c2f Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 14:05:55 +0500 Subject: [PATCH 05/15] TranslatorSpec: Go: Correct expected value of translation of fields in tests for boolean expressions It seems that Go always uses `this.UpperCase` instead of `lowerCase` field names since it was introduced in 640809f28c1cc9994f3748372906ff1e2caa3e5a. Fixes [info] - go:a != 2 and a != 5 *** FAILED *** [info] "[ ((this.A != 2) && (this.A != 5)) ]" was not equal to "[a != 2 && a != 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ ((this.A != 2) && (this.A != 5)) ]" -> "[a != 2 && a != 5]" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fc6ed2b79..9fc29e348 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -288,7 +288,7 @@ class TranslatorSpec extends AnyFunSpec { full("a != 2 and a != 5", CalcIntType, CalcBooleanType, Map[LanguageCompilerStatic, String]( CppCompiler -> "a() != 2 && a() != 5", CSharpCompiler -> "A != 2 && A != 5", - GoCompiler -> "a != 2 && a != 5", + GoCompiler -> " ((this.A != 2) && (this.A != 5)) ", JavaCompiler -> "a() != 2 && a() != 5", JavaScriptCompiler -> "this.a != 2 && this.a != 5", LuaCompiler -> "self.a ~= 2 and self.a ~= 5", From 46ab0b24c113b5fe74eac635c2288b22736f107f Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 16:11:18 +0500 Subject: [PATCH 06/15] TranslatorSpec: Go: Fix test for \u000a character translation It seems that it always translated to "\n" so it is strange why test expected "\u000a" Fixes [info] - go:"str\u000anext" *** FAILED *** [info] ""str\[n]next"" was not equal to ""str\[u000a]next"" (TranslatorSpec.scala:435) [info] Analysis: [info] ""str\[n]next"" -> ""str\[u000a]next"" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9fc29e348..2a06053b5 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -452,7 +452,7 @@ class TranslatorSpec extends AnyFunSpec { full("\"str\\u000anext\"", CalcIntType, CalcStrType, Map[LanguageCompilerStatic, String]( CppCompiler -> "std::string(\"str\\nnext\")", CSharpCompiler -> "\"str\\nnext\"", - GoCompiler -> "\"str\\u000anext\"", + GoCompiler -> "\"str\\nnext\"", JavaCompiler -> "\"str\\nnext\"", JavaScriptCompiler -> "\"str\\nnext\"", LuaCompiler -> "\"str\\nnext\"", From 3a0a7a1723b2cbf3ae698c6c71f6854dc6a7d793 Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 16:30:15 +0500 Subject: [PATCH 07/15] TranslatorSpec: Go: Fix tests for to_i conversion for strings Most probably was done in f8dbedd840f29e76e713724cc03c13baf91e0485 Fixes [info] - go:"12345".to_i *** FAILED *** [info] "[tmp1, err := strconv.ParseInt("12345", 10, 0) [info] if err != nil { [info] return err [info] } [info] tmp1]" was not equal to "[func()(int){i, err := strconv.Atoi("12345"); if (err != nil) { panic(err) }; return i}()]" (TranslatorSpec.scala:520) [info] Analysis: [info] "[tmp1, err := strconv.ParseInt("12345", 10, 0) [info] if err != nil { [info] return err [info] } [info] tmp1]" -> "[func()(int){i, err := strconv.Atoi("12345"); if (err != nil) { panic(err) }; return i}()]" [info] - go:"1234fe".to_i(16) *** FAILED *** [info] "[tmp1, err := strconv.ParseInt("1234fe", 16, 0) [info] if err != nil { [info] return err [info] } [info] tmp1]" was not equal to "[func()(int64){i, err := strconv.ParseInt("1234fe", 16, 64); if (err != nil) { panic(err) }; return i}()]" (TranslatorSpec.scala:533) [info] Analysis: [info] "[tmp1, err := strconv.ParseInt("1234fe", 16, 0) [info] if err != nil { [info] return err [info] } [info] tmp1]" -> "[func()(int64){i, err := strconv.ParseInt("1234fe", 16, 64); if (err != nil) { panic(err) }; return i}()]" --- .../kaitai/struct/translators/TranslatorSpec.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 2a06053b5..577c33ca0 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -541,7 +541,11 @@ class TranslatorSpec extends AnyFunSpec { full("\"12345\".to_i", CalcIntType, CalcIntType, Map[LanguageCompilerStatic, String]( CppCompiler -> "kaitai::kstream::string_to_int(std::string(\"12345\"))", CSharpCompiler -> "Convert.ToInt64(\"12345\", 10)", - GoCompiler -> "func()(int){i, err := strconv.Atoi(\"12345\"); if (err != nil) { panic(err) }; return i}()", + GoCompiler -> """tmp1, err := strconv.ParseInt("12345", 10, 0) + |if err != nil { + | return err + |} + |tmp1""".stripMargin, JavaCompiler -> "Long.parseLong(\"12345\", 10)", JavaScriptCompiler -> "Number.parseInt(\"12345\", 10)", LuaCompiler -> "tonumber(\"12345\")", @@ -554,7 +558,11 @@ class TranslatorSpec extends AnyFunSpec { full("\"1234fe\".to_i(16)", CalcIntType, CalcIntType, Map[LanguageCompilerStatic, String]( CppCompiler -> "kaitai::kstream::string_to_int(std::string(\"1234fe\"), 16)", CSharpCompiler -> "Convert.ToInt64(\"1234fe\", 16)", - GoCompiler -> "func()(int64){i, err := strconv.ParseInt(\"1234fe\", 16, 64); if (err != nil) { panic(err) }; return i}()", + GoCompiler -> """tmp1, err := strconv.ParseInt("1234fe", 16, 0) + |if err != nil { + | return err + |} + |tmp1""".stripMargin, JavaCompiler -> "Long.parseLong(\"1234fe\", 16)", JavaScriptCompiler -> "Number.parseInt(\"1234fe\", 16)", LuaCompiler -> "tonumber(\"1234fe\", 16)", From f553ec22148528d0bee865be9768f75f3fc5aab6 Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 16:31:11 +0500 Subject: [PATCH 08/15] TranslatorSpec: Go: Fix a `.last` expression tests Changes was made in fa896a007e0e7f9ddcb0cc33911e212e2b004dcb Fixes [info] - go:a.last *** FAILED *** [info] "t[mp1 := this.A [info] tmp1[len(tmp1) - ]1]" was not equal to "t[his.A[len(this.A)-]1]" (TranslatorSpec.scala:382) [info] Analysis: [info] "t[mp1 := this.A [info] tmp1[len(tmp1) - ]1]" -> "t[his.A[len(this.A)-]1]" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 577c33ca0..4074a33b9 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -396,7 +396,8 @@ class TranslatorSpec extends AnyFunSpec { full("a.last", ArrayTypeInStream(CalcIntType), CalcIntType, Map[LanguageCompilerStatic, String]( CppCompiler -> "a()->back()", CSharpCompiler -> "A[A.Count - 1]", - GoCompiler -> "this.A[len(this.A)-1]", + GoCompiler -> """tmp1 := this.A + |tmp1[len(tmp1) - 1]""".stripMargin, JavaCompiler -> "a().get(a().size() - 1)", JavaScriptCompiler -> "this.a[this.a.length - 1]", LuaCompiler -> "self.a[#self.a]", From 6f658a088f593dfe20d55b01119a20b4d37cc457 Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 16:36:46 +0500 Subject: [PATCH 09/15] TranslatorSpec: Go: Fix tests of casting to byte arrays Changes was made in 4128d9f25428f16e5d592f23deb08f0d567fa17e Fixes [info] - go:[].as *** FAILED *** [info] "[[]uint8{}]" was not equal to "[""]" (TranslatorSpec.scala:588) [info] Analysis: [info] "[[]uint8{}]" -> "[""]" [info] - go:[0 + 1, 5].as *** FAILED *** [info] "[[]uint8{(0 + 1), 5}]" was not equal to "[string([]byte{(0 + 1), 5})]" (TranslatorSpec.scala:628) [info] Analysis: [info] "[[]uint8{(0 + 1), 5}]" -> "[string([]byte{(0 + 1), 5})]" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 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 4074a33b9..e755ee0c9 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -623,7 +623,7 @@ class TranslatorSpec extends AnyFunSpec { full("[].as", CalcIntType, CalcBytesType, Map[LanguageCompilerStatic, String]( CppCompiler -> "std::string(\"\", 0)", CSharpCompiler -> "new byte[] { }", - GoCompiler -> "\"\"", + GoCompiler -> "[]uint8{}", JavaCompiler -> "new byte[] { }", JavaScriptCompiler -> "[]", LuaCompiler -> "\"\"", @@ -665,7 +665,7 @@ class TranslatorSpec extends AnyFunSpec { full("[0 + 1, 5].as", CalcIntType, CalcBytesType, Map[LanguageCompilerStatic, String]( CppCompiler -> "???", CSharpCompiler -> "new byte[] { (0 + 1), 5 }", - GoCompiler -> "string([]byte{(0 + 1), 5})", + GoCompiler -> "[]uint8{(0 + 1), 5}", JavaCompiler -> "new byte[] { (0 + 1), 5 }", JavaScriptCompiler -> "new Uint8Array([(0 + 1), 5])", LuaCompiler -> "???", From d1d1d6624363cbdc73e35e9b1d84534437db3ef7 Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 14:27:15 +0500 Subject: [PATCH 10/15] TranslatorSpec: Java: Correct test of `_root` translation Fixes [info] - java:_root.foo *** FAILED *** [info] "_root[()].foo()" was not equal to "_root[].foo()" (TranslatorSpec.scala:267) [info] Analysis: [info] "_root[()].foo()" -> "_root[].foo()" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e755ee0c9..f15256b11 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -276,7 +276,7 @@ class TranslatorSpec extends AnyFunSpec { CppCompiler -> "_root()->foo()", CSharpCompiler -> "M_Root.Foo", GoCompiler -> "this._root.Foo", - JavaCompiler -> "_root.foo()", + JavaCompiler -> "_root().foo()", JavaScriptCompiler -> "this._root.foo", LuaCompiler -> "self._root.foo", PerlCompiler -> "$self->_root()->foo()", From a59808106b6a90aa357977a73a5d8d6186d48c2f Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 16:49:18 +0500 Subject: [PATCH 11/15] TranslatorSpec: Java: Array subscript tests should use cast to int, as implemented in 1f86742d2da6ad7dcf0afe33d4a55e98667601b9 Fixes [info] - java:a[42 - 2] *** FAILED *** [info] "a().get(([int) (]42 - 2))" was not equal to "a().get(([]42 - 2))" (TranslatorSpec.scala:356) [info] Analysis: [info] "a().get(([int) (]42 - 2))" -> "a().get(([]42 - 2))" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f15256b11..f0baf6725 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -371,7 +371,7 @@ class TranslatorSpec extends AnyFunSpec { CppCompiler -> "a()->at((42 - 2))", CSharpCompiler -> "A[(42 - 2)]", GoCompiler -> "this.A[(42 - 2)]", - JavaCompiler -> "a().get((42 - 2))", + JavaCompiler -> "a().get((int) (42 - 2))", JavaScriptCompiler -> "this.a[(42 - 2)]", LuaCompiler -> "self.a[(43 - 2)]", PerlCompiler -> "@{$self->a()}[(42 - 2)]", From 2ee122e513a53a99b7ef24a1ed2c0e15eadee70d Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 16:00:56 +0500 Subject: [PATCH 12/15] TranslatorSpec: JavaScript: Change usage of octal literals to hex literals to represent characters in string The change in translator was made in 338629dc4f2ce3a015dc570f1e2b249b91651260 Fixes [info] - javascript:"str\0next" *** FAILED *** [info] ""str\[x]00next"" was not equal to ""str\[0]00next"" (TranslatorSpec.scala:448) [info] Analysis: [info] ""str\[x]00next"" -> ""str\[0]00next"" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f0baf6725..8bba12706 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -468,7 +468,7 @@ class TranslatorSpec extends AnyFunSpec { CSharpCompiler -> "\"str\\0next\"", GoCompiler -> "\"str\\000next\"", JavaCompiler -> "\"str\\000next\"", - JavaScriptCompiler -> "\"str\\000next\"", + JavaScriptCompiler -> "\"str\\x00next\"", LuaCompiler -> "\"str\\000next\"", PerlCompiler -> "\"str\\000next\"", PHPCompiler -> "\"str\\000next\"", From e2b69674931ab52d6751f713c941e27df59f66cd Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 16:48:11 +0500 Subject: [PATCH 13/15] TranslatorSpec: Lua: Constant folding not implemented now, fix tests that assume this Fixes [info] - lua:a[42] *** FAILED *** [info] "self.a[4[2 + 1]]" was not equal to "self.a[4[3]]" (TranslatorSpec.scala:343) [info] Analysis: [info] "self.a[4[2 + 1]]" -> "self.a[4[3]]" [info] - lua:a[42 - 2] *** FAILED *** [info] "self.a[(4[2 - 2) + 1]]" was not equal to "self.a[(4[3 - 2)]]" (TranslatorSpec.scala:356) [info] Analysis: [info] "self.a[(4[2 - 2) + 1]]" -> "self.a[(4[3 - 2)]]" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 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 8bba12706..ec6ee56c1 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -360,7 +360,7 @@ class TranslatorSpec extends AnyFunSpec { GoCompiler -> "this.A[42]", JavaCompiler -> "a().get((int) 42)", JavaScriptCompiler -> "this.a[42]", - LuaCompiler -> "self.a[43]", + LuaCompiler -> "self.a[42 + 1]", PerlCompiler -> "@{$self->a()}[42]", PHPCompiler -> "$this->a()[42]", PythonCompiler -> "self.a[42]", @@ -373,7 +373,7 @@ class TranslatorSpec extends AnyFunSpec { GoCompiler -> "this.A[(42 - 2)]", JavaCompiler -> "a().get((int) (42 - 2))", JavaScriptCompiler -> "this.a[(42 - 2)]", - LuaCompiler -> "self.a[(43 - 2)]", + LuaCompiler -> "self.a[(42 - 2) + 1]", PerlCompiler -> "@{$self->a()}[(42 - 2)]", PHPCompiler -> "$this->a()[(42 - 2)]", PythonCompiler -> "self.a[(42 - 2)]", From b15324d1f9eaf39eb8a352619dc7172493e7c12e Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 15:39:41 +0500 Subject: [PATCH 14/15] TranslatorSpec: Python: fix translation of array literals where all elements between 0 and 255 Fixes [info] - python:[255, 0, 255] *** FAILED *** [info] "b"\[xFF\x00\xFF]"" was not equal to "b"\[255\000\255]"" (TranslatorSpec.scala:319) [info] Analysis: [info] "b"\[xFF\x00\xFF]"" -> "b"\[255\000\255]"" --- .../scala/io/kaitai/struct/translators/TranslatorSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ec6ee56c1..4c150486f 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -335,7 +335,7 @@ class TranslatorSpec extends AnyFunSpec { LuaCompiler -> "\"\\255\\000\\255\"", PerlCompiler -> "pack('C*', (255, 0, 255))", PHPCompiler -> "\"\\xFF\\x00\\xFF\"", - PythonCompiler -> "b\"\\255\\000\\255\"", + PythonCompiler -> "b\"\\xFF\\x00\\xFF\"", RubyCompiler -> "[255, 0, 255].pack('C*')" )) } From 30c0201dec77517bceb695606127b25ee7d12753 Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 8 Mar 2024 13:47:38 +0500 Subject: [PATCH 15/15] TranslatorSpec: Expressions gets translated in parenthesis so correct all tests accordingly Fixes [info] - cpp_stl:2 < 3 ? "foo" : "bar" *** FAILED *** [info] "([(2 < 3) ? (std::string("foo")) : (std::string("bar")]))" was not equal to "([2 < 3) ? (std::string("foo")) : (std::string("bar"]))" (TranslatorSpec.scala:133) [info] Analysis: [info] "([(2 < 3) ? (std::string("foo")) : (std::string("bar")]))" -> "([2 < 3) ? (std::string("foo")) : (std::string("bar"]))" [info] - csharp:2 < 3 ? "foo" : "bar" *** FAILED *** [info] "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133) [info] Analysis: [info] "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]" [info] - java:2 < 3 ? "foo" : "bar" *** FAILED *** [info] "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133) [info] Analysis: [info] "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]" [info] - javascript:2 < 3 ? "foo" : "bar" *** FAILED *** [info] "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133) [info] Analysis: [info] "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]" [info] - lua:2 < 3 ? "foo" : "bar" *** FAILED *** [info] "utils.box_unwrap([(2 < 3) and utils.box_wrap("foo") or ("bar")])" was not equal to "utils.box_unwrap([2 < 3 and utils.box_wrap("foo") or "bar"])" (TranslatorSpec.scala:133) [info] Analysis: [info] "utils.box_unwrap([(2 < 3) and utils.box_wrap("foo") or ("bar")])" -> "utils.box_unwrap([2 < 3 and utils.box_wrap("foo") or "bar"])" [info] - perl:2 < 3 ? "foo" : "bar" *** FAILED *** [info] "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133) [info] Analysis: [info] "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]" [info] - php:2 < 3 ? "foo" : "bar" *** FAILED *** [info] "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133) [info] Analysis: [info] "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]" [info] - python:2 < 3 ? "foo" : "bar" *** FAILED *** [info] "[(u"foo" if 2 < 3 else u"bar")]" was not equal to "[u"foo" if 2 < 3 else u"bar"]" (TranslatorSpec.scala:133) [info] Analysis: [info] "[(u"foo" if 2 < 3 else u"bar")]" -> "[u"foo" if 2 < 3 else u"bar"]" [info] - ruby:2 < 3 ? "foo" : "bar" *** FAILED *** [info] "[(2 < 3 ? "foo" : "bar")]" was not equal to "[2 < 3 ? "foo" : "bar"]" (TranslatorSpec.scala:133) [info] Analysis: [info] "[(2 < 3 ? "foo" : "bar")]" -> "[2 < 3 ? "foo" : "bar"]" [info] - cpp_stl:some_bool.to_i *** FAILED *** [info] "[((some_bool()) ? 1 : 0])" was not equal to "[some_bool(])" (TranslatorSpec.scala:197) [info] Analysis: [info] "[((some_bool()) ? 1 : 0])" -> "[some_bool(])" [info] - lua:some_bool.to_i *** FAILED *** [info] "[(self.some_bool and 1 or 0)]" was not equal to "[self.some_bool and 1 or 0]" (TranslatorSpec.scala:197) [info] Analysis: [info] "[(self.some_bool and 1 or 0)]" -> "[self.some_bool and 1 or 0]" [info] - cpp_stl:a != 2 and a != 5 *** FAILED *** [info] "[ ((a() != 2) && (a() != 5)) ]" was not equal to "[a() != 2 && a() != 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ ((a() != 2) && (a() != 5)) ]" -> "[a() != 2 && a() != 5]" [info] - csharp:a != 2 and a != 5 *** FAILED *** [info] "[ ((A != 2) && (A != 5)) ]" was not equal to "[A != 2 && A != 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ ((A != 2) && (A != 5)) ]" -> "[A != 2 && A != 5]" [info] - java:a != 2 and a != 5 *** FAILED *** [info] "[ ((a() != 2) && (a() != 5)) ]" was not equal to "[a() != 2 && a() != 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ ((a() != 2) && (a() != 5)) ]" -> "[a() != 2 && a() != 5]" [info] - javascript:a != 2 and a != 5 *** FAILED *** [info] "[ ((this.a != 2) && (this.a != 5)) ]" was not equal to "[this.a != 2 && this.a != 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ ((this.a != 2) && (this.a != 5)) ]" -> "[this.a != 2 && this.a != 5]" [info] - lua:a != 2 and a != 5 *** FAILED *** [info] "[ ((self.a ~= 2) and (self.a ~= 5)) ]" was not equal to "[self.a ~= 2 and self.a ~= 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ ((self.a ~= 2) and (self.a ~= 5)) ]" -> "[self.a ~= 2 and self.a ~= 5]" [info] - perl:a != 2 and a != 5 *** FAILED *** [info] "[ (($self->a() != 2) && ($self->a() != 5)) ]" was not equal to "[$self->a() != 2 && $self->a() != 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ (($self->a() != 2) && ($self->a() != 5)) ]" -> "[$self->a() != 2 && $self->a() != 5]" [info] - php:a != 2 and a != 5 *** FAILED *** [info] "[ (($this->a() != 2) && ($this->a() != 5)) ]" was not equal to "[$this->a() != 2 && $this->a() != 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ (($this->a() != 2) && ($this->a() != 5)) ]" -> "[$this->a() != 2 && $this->a() != 5]" [info] - python:a != 2 and a != 5 *** FAILED *** [info] "[ ((self.a != 2) and (self.a != 5)) ]" was not equal to "[self.a != 2 and self.a != 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ ((self.a != 2) and (self.a != 5)) ]" -> "[self.a != 2 and self.a != 5]" [info] - ruby:a != 2 and a != 5 *** FAILED *** [info] "[ ((a != 2) && (a != 5)) ]" was not equal to "[a != 2 && a != 5]" (TranslatorSpec.scala:280) [info] Analysis: [info] "[ ((a != 2) && (a != 5)) ]" -> "[a != 2 && a != 5]" [info] - python:"str".reverse *** FAILED *** [info] "[(u"str")][::-1]" was not equal to "[u"str"][::-1]" (TranslatorSpec.scala:507) [info] Analysis: [info] "[(u"str")][::-1]" -> "[u"str"][::-1]" --- .../struct/translators/TranslatorSpec.scala | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 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 4c150486f..fc59f2ff6 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -135,8 +135,8 @@ class TranslatorSpec extends AnyFunSpec { everybody("1 == 2", "1 == 2", CalcBooleanType) full("2 < 3 ? \"foo\" : \"bar\"", CalcIntType, CalcStrType, Map[LanguageCompilerStatic, String]( - CppCompiler -> "(2 < 3) ? (std::string(\"foo\")) : (std::string(\"bar\"))", - CSharpCompiler -> "2 < 3 ? \"foo\" : \"bar\"", + CppCompiler -> "((2 < 3) ? (std::string(\"foo\")) : (std::string(\"bar\")))", + CSharpCompiler -> "(2 < 3 ? \"foo\" : \"bar\")", GoCompiler -> """var tmp1 string; |if (2 < 3) { @@ -145,13 +145,13 @@ class TranslatorSpec extends AnyFunSpec { | tmp1 = "bar" |} |tmp1""".stripMargin, - JavaCompiler -> "2 < 3 ? \"foo\" : \"bar\"", - JavaScriptCompiler -> "2 < 3 ? \"foo\" : \"bar\"", - LuaCompiler -> "utils.box_unwrap(2 < 3 and utils.box_wrap(\"foo\") or \"bar\")", - PerlCompiler -> "2 < 3 ? \"foo\" : \"bar\"", - PHPCompiler -> "2 < 3 ? \"foo\" : \"bar\"", - PythonCompiler -> "u\"foo\" if 2 < 3 else u\"bar\"", - RubyCompiler -> "2 < 3 ? \"foo\" : \"bar\"" + JavaCompiler -> "(2 < 3 ? \"foo\" : \"bar\")", + JavaScriptCompiler -> "(2 < 3 ? \"foo\" : \"bar\")", + LuaCompiler -> "utils.box_unwrap((2 < 3) and utils.box_wrap(\"foo\") or (\"bar\"))", + PerlCompiler -> "(2 < 3 ? \"foo\" : \"bar\")", + PHPCompiler -> "(2 < 3 ? \"foo\" : \"bar\")", + PythonCompiler -> "(u\"foo\" if 2 < 3 else u\"bar\")", + RubyCompiler -> "(2 < 3 ? \"foo\" : \"bar\")" )) everybodyExcept("~777", "~777", Map[LanguageCompilerStatic, String]( @@ -212,7 +212,7 @@ class TranslatorSpec extends AnyFunSpec { |tmp1""".stripMargin, JavaCompiler -> "(someBool() ? 1 : 0)", JavaScriptCompiler -> "(this.someBool | 0)", - LuaCompiler -> "self.some_bool and 1 or 0", + LuaCompiler -> "(self.some_bool and 1 or 0)", PerlCompiler -> "$self->some_bool()", PHPCompiler -> "intval($this->someBool())", PythonCompiler -> "int(self.some_bool)", @@ -286,16 +286,16 @@ class TranslatorSpec extends AnyFunSpec { )) full("a != 2 and a != 5", CalcIntType, CalcBooleanType, Map[LanguageCompilerStatic, String]( - CppCompiler -> "a() != 2 && a() != 5", - CSharpCompiler -> "A != 2 && A != 5", + CppCompiler -> " ((a() != 2) && (a() != 5)) ", + CSharpCompiler -> " ((A != 2) && (A != 5)) ", GoCompiler -> " ((this.A != 2) && (this.A != 5)) ", - JavaCompiler -> "a() != 2 && a() != 5", - JavaScriptCompiler -> "this.a != 2 && this.a != 5", - LuaCompiler -> "self.a ~= 2 and self.a ~= 5", - PerlCompiler -> "$self->a() != 2 && $self->a() != 5", - PHPCompiler -> "$this->a() != 2 && $this->a() != 5", - PythonCompiler -> "self.a != 2 and self.a != 5", - RubyCompiler -> "a != 2 && a != 5" + JavaCompiler -> " ((a() != 2) && (a() != 5)) ", + JavaScriptCompiler -> " ((this.a != 2) && (this.a != 5)) ", + LuaCompiler -> " ((self.a ~= 2) and (self.a ~= 5)) ", + PerlCompiler -> " (($self->a() != 2) && ($self->a() != 5)) ", + PHPCompiler -> " (($this->a() != 2) && ($this->a() != 5)) ", + PythonCompiler -> " ((self.a != 2) and (self.a != 5)) ", + RubyCompiler -> " ((a != 2) && (a != 5)) " )) } @@ -535,7 +535,7 @@ class TranslatorSpec extends AnyFunSpec { LuaCompiler -> "string.reverse(\"str\")", PerlCompiler -> "scalar(reverse(\"str\"))", PHPCompiler -> "strrev(\"str\")", - PythonCompiler -> "u\"str\"[::-1]", + PythonCompiler -> "(u\"str\")[::-1]", RubyCompiler -> "\"str\".reverse" ))