Fixed: #270 AS decompilation - comma in ternar

This commit is contained in:
Jindra Petřík
2021-03-13 20:32:24 +01:00
parent b84ccc7005
commit 98703e4e5a
11 changed files with 212 additions and 15 deletions

View File

@@ -1978,7 +1978,7 @@ public class ActionScript2Test extends ActionScript2TestBase {
+ "{\r\n"
+ "trace(_loc1_);\r\n"
+ "}\r\n"
+ "_loc3_.r1 = _loc2_ + 1 + \". \" + (!_loc4_ ? _loc3_.r2 = v1[_loc2_][0] : \"unk\");\r\n"
+ "_loc3_.r1 = _loc2_ + 1 + \". \" + (!_loc4_ ? (_loc3_.r2 = v1[_loc2_][0]) : \"unk\");\r\n"
+ "}\r\n"
+ "trace(\"chainedAfterForInTest\");\r\n"
+ "var v1 = {};\r\n"

View File

@@ -75,6 +75,14 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
false);
}
@Test
public void testComma() {
decompileMethod("classic_air", "testComma", "var a:int = 5;\r\n"
+ "var b:int = 0;\r\n"
+ "trace(a > 4 ? (b = 5, a) : 35);\r\n",
false);
}
@Test
public void testComplexExpressions() {
decompileMethod("classic_air", "testComplexExpressions", "var i:int = 0;\r\n"
@@ -560,6 +568,25 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
false);
}
@Test
public void testForInIf() {
decompileMethod("classic_air", "testForInIf", "var arr:Array = [\"a\",\"b\",\"c\"];\r\n"
+ "var b:int = 5;\r\n"
+ "for(var a in arr)\r\n"
+ "{\r\n"
+ "if(b == 5)\r\n"
+ "{\r\n"
+ "if(b <= 7)\r\n"
+ "{\r\n"
+ "return;\r\n"
+ "}\r\n"
+ "trace(\"b>7\");\r\n"
+ "}\r\n"
+ "trace(\"forend\");\r\n"
+ "}\r\n",
false);
}
@Test
public void testForInReturn() {
decompileMethod("classic_air", "testForInReturn", "var dic:Dictionary = null;\r\n"
@@ -574,6 +601,27 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
false);
}
@Test
public void testForInSwitch() {
decompileMethod("classic_air", "testForInSwitch", "var arr:Array = [\"a\",\"b\",\"c\"];\r\n"
+ "for(var a in arr)\r\n"
+ "{\r\n"
+ "switch(a)\r\n"
+ "{\r\n"
+ "case \"a\":\r\n"
+ "trace(\"val a\");\r\n"
+ "break;\r\n"
+ "case \"b\":\r\n"
+ "trace(\"val b\");\r\n"
+ "break;\r\n"
+ "case \"c\":\r\n"
+ "trace(\"val c\");\r\n"
+ "}\r\n"
+ "trace(\"final\");\r\n"
+ "}\r\n",
false);
}
@Test
public void testForXml() {
decompileMethod("classic_air", "testForXml", "var i:int = 0;\r\n"
@@ -846,6 +894,31 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
false);
}
@Test
public void testIfTry() {
decompileMethod("classic_air", "testIfTry", "var c:int = 0;\r\n"
+ "var i:int = 0;\r\n"
+ "var b:Boolean = true;\r\n"
+ "if(b)\r\n"
+ "{\r\n"
+ "c = 5;\r\n"
+ "for(i = 0; i < c; )\r\n"
+ "{\r\n"
+ "trace(\"xx\");\r\n"
+ "i++;\r\n"
+ "}\r\n"
+ "}\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n",
false);
}
@Test
public void testIgnoreAndOr() {
decompileMethod("classic_air", "testIgnoreAndOr", "var k:int = Math.random();\r\n"

View File

@@ -75,6 +75,14 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
false);
}
@Test
public void testComma() {
decompileMethod("classic", "testComma", "var a:int = 5;\r\n"
+ "var b:int = 0;\r\n"
+ "trace(a > 4 ? (b = 5, a) : 35);\r\n",
false);
}
@Test
public void testComplexExpressions() {
decompileMethod("classic", "testComplexExpressions", "var i:int = 0;\r\n"
@@ -554,6 +562,26 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
false);
}
@Test
public void testForInIf() {
decompileMethod("classic", "testForInIf", "var a:* = null;\r\n"
+ "var arr:Array = [\"a\",\"b\",\"c\"];\r\n"
+ "var b:int = 5;\r\n"
+ "for(a in arr)\r\n"
+ "{\r\n"
+ "if(b == 5)\r\n"
+ "{\r\n"
+ "if(b <= 7)\r\n"
+ "{\r\n"
+ "return;\r\n"
+ "}\r\n"
+ "trace(\"b>7\");\r\n"
+ "}\r\n"
+ "trace(\"forend\");\r\n"
+ "}\r\n",
false);
}
@Test
public void testForInReturn() {
decompileMethod("classic", "testForInReturn", "var dic:Dictionary = null;\r\n"
@@ -568,6 +596,29 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
false);
}
@Test
public void testForInSwitch() {
decompileMethod("classic", "testForInSwitch", "var a:* = null;\r\n"
+ "var arr:Array = [\"a\",\"b\",\"c\"];\r\n"
+ "for(a in arr)\r\n"
+ "{\r\n"
+ "switch(a)\r\n"
+ "{\r\n"
+ "case \"a\":\r\n"
+ "trace(\"val a\");\r\n"
+ "break;\r\n"
+ "case \"b\":\r\n"
+ "trace(\"val b\");\r\n"
+ "break;\r\n"
+ "case \"c\":\r\n"
+ "trace(\"val c\");\r\n"
+ "break;\r\n"
+ "}\r\n"
+ "trace(\"final\");\r\n"
+ "}\r\n",
false);
}
@Test
public void testForXml() {
decompileMethod("classic", "testForXml", "var c:int = 0;\r\n"
@@ -837,6 +888,30 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
false);
}
@Test
public void testIfTry() {
decompileMethod("classic", "testIfTry", "var c:int = 0;\r\n"
+ "var i:int = 0;\r\n"
+ "var b:Boolean = true;\r\n"
+ "if(b)\r\n"
+ "{\r\n"
+ "c = 5;\r\n"
+ "for(i = 0; i < c; i++)\r\n"
+ "{\r\n"
+ "trace(\"xx\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n",
false);
}
@Test
public void testIgnoreAndOr() {
decompileMethod("classic", "testIgnoreAndOr", "var k:int = Math.random();\r\n"