You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2016/04/13 20:56:20 UTC
[28/51] [partial] git commit: [flex-falcon]
[refs/heads/feature/maven-migration-test] - - Check-In of the migrated
project to make error analysis easier
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestClass.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestClass.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestClass.java
new file mode 100644
index 0000000..3787d45
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestClass.java
@@ -0,0 +1,234 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Class
+ * production.
+ *
+ * @author Michael Schmalle
+ */
+public class TestClass extends ASTestBase
+{
+ //--------------------------------------------------------------------------
+ // Class
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testSimple()
+ {
+ IClassNode node = getClassNode("public class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A {\n}");
+ }
+
+ @Test
+ public void testSimpleInternal()
+ {
+ IClassNode node = getClassNode("internal class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("internal class A {\n}");
+ }
+
+ @Test
+ public void testSimpleFinal()
+ {
+ IClassNode node = getClassNode("public final class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("public final class A {\n}");
+ }
+
+ @Test
+ public void testSimpleDynamic()
+ {
+ IClassNode node = getClassNode("public dynamic class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("public dynamic class A {\n}");
+ }
+
+ @Test
+ public void testSimpleExtends()
+ {
+ IClassNode node = getClassNode("public class A extends B {}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A extends B {\n}");
+ }
+
+ @Test
+ public void testSimpleImplements()
+ {
+ IClassNode node = getClassNode("public class A implements IA {}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A implements IA {\n}");
+ }
+
+ @Test
+ public void testSimpleImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A implements IA, IB, IC {}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A implements IA, IB, IC {\n}");
+ }
+
+ @Test
+ public void testSimpleExtendsImplements()
+ {
+ IClassNode node = getClassNode("public class A extends B implements IA {}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A extends B implements IA {\n}");
+ }
+
+ @Test
+ public void testSimpleExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A extends B implements IA, IB, IC {}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A extends B implements IA, IB, IC {\n}");
+ }
+
+ @Test
+ public void testSimpleFinalExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public final class A extends B implements IA, IB, IC {}");
+ asBlockWalker.visitClass(node);
+ assertOut("public final class A extends B implements IA, IB, IC {\n}");
+ }
+
+ @Test
+ public void testQualifiedExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A extends goo.B implements foo.bar.IA, goo.foo.IB, baz.boo.IC {}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A extends goo.B implements foo.bar.IA, goo.foo.IB, baz.boo.IC {\n}");
+ }
+
+ @Test
+ public void testConstructor()
+ {
+ IClassNode node = getClassNode("public class A {public function A(){super('foo', 42);}}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A {\n\tpublic function A() {\n\t\tsuper('foo', 42);\n\t}\n}");
+ }
+
+ @Test
+ public void testConstructor_withArguments()
+ {
+ IClassNode node = getClassNode("public class A {public function A(arg1:String, arg2:int) {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A {\n\tpublic function A(arg1:String, arg2:int) {\n\t}\n}");
+ }
+
+ @Test
+ public void testExtendsConstructor_withArguments()
+ {
+ IClassNode node = getClassNode("public class A extends B {public function A(arg1:String, arg2:int) {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A extends B {\n\tpublic function A(arg1:String, arg2:int) {\n\t}\n}");
+ }
+
+ @Test
+ public void testFields()
+ {
+ IClassNode node = getClassNode("public class A {public var a:Object;protected var b:String; "
+ + "private var c:int; internal var d:uint; var e:Number}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A {\n\tpublic var a:Object;\n\tprotected var b:String;"
+ + "\n\tprivate var c:int;\n\tvar d:uint;\n\tvar e:Number;\n}");
+ }
+
+ @Test
+ public void testConstants()
+ {
+ IClassNode node = getClassNode("public class A {"
+ + "public static const A:int = 42;"
+ + "protected static const B:Number = 42;"
+ + "private static const C:Number = 42;"
+ + "foo_bar static const C:String = 'me' + 'you';");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A {\n\tpublic static const A:int = 42;\n\t"
+ + "protected static const B:Number = 42;\n\tprivate static const "
+ + "C:Number = 42;\n\tfoo_bar static const C:String = 'me' + 'you';\n}");
+ }
+
+ @Test
+ public void testAccessors()
+ {
+ IClassNode node = getClassNode("public class A {"
+ + "public function get foo1():Object{return null;}"
+ + "public function set foo1(value:Object):void{}"
+ + "protected function get foo2():Object{return null;}"
+ + "protected function set foo2(value:Object):void{}"
+ + "private function get foo3():Object{return null;}"
+ + "private function set foo3(value:Object):void{}"
+ + "internal function get foo5():Object{return null;}"
+ + "internal function set foo5(value:Object):void{}"
+ + "foo_bar function get foo6():Object{return null;}"
+ + "foo_bar function set foo6(value:Object):void{}" + "}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A {\n\tpublic function get foo1():Object {"
+ + "\n\t\treturn null;\n\t}\n\tpublic function set foo1(value:Object)"
+ + ":void {\n\t}\n\tprotected function get foo2():Object {\n\t\treturn "
+ + "null;\n\t}\n\tprotected function set foo2(value:Object):void "
+ + "{\n\t}\n\tprivate function get foo3():Object {\n\t\treturn null;"
+ + "\n\t}\n\tprivate function set foo3(value:Object):void {\n\t}\n\t"
+ + "function get foo5():Object {\n\t\treturn null;\n\t}\n\tfunction set "
+ + "foo5(value:Object):void {\n\t}\n\tfoo_bar function get foo6():Object "
+ + "{\n\t\treturn null;\n\t}\n\tfoo_bar function set "
+ + "foo6(value:Object):void {\n\t}\n}");
+ }
+
+ @Test
+ public void testMethods()
+ {
+ IClassNode node = getClassNode("public class A {"
+ + "public function foo1():Object{return null;}"
+ + "public final function foo1a():Object{return null;}"
+ + "override public function foo1b():Object{return super.foo1b();}"
+ + "protected function foo2(value:Object):void{}"
+ + "private function foo3(value:Object):void{}"
+ + "internal function foo5(value:Object):void{}"
+ + "foo_bar function foo6(value:Object):void{}"
+ + "public static function foo7(value:Object):void{}"
+ + "foo_bar static function foo7(value:Object):void{}" + "}");
+ asBlockWalker.visitClass(node);
+ assertOut("public class A {\n\tpublic function foo1():Object {\n\t\treturn "
+ + "null;\n\t}\n\tpublic final function foo1a():Object {\n\t\treturn "
+ + "null;\n\t}\n\tpublic override function foo1b():Object {\n\t\treturn "
+ + "super.foo1b();\n\t}\n\tprotected function foo2(value:Object):void "
+ + "{\n\t}\n\tprivate function foo3(value:Object):void {\n\t}\n\tfunction "
+ + "foo5(value:Object):void {\n\t}\n\tfoo_bar function foo6(value:Object"
+ + "):void {\n\t}\n\tpublic static function foo7(value:Object):void {\n\t}"
+ + "\n\tfoo_bar static function foo7(value:Object):void {\n\t}\n}");
+ }
+
+ protected IClassNode getClassNode(String code)
+ {
+ String source = "package {" + code + "}";
+ IFileNode node = compileAS(source);
+ IClassNode child = (IClassNode) findFirstDescendantOfType(node,
+ IClassNode.class);
+ return child;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestComments.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestComments.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestComments.java
new file mode 100644
index 0000000..bb38475
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestComments.java
@@ -0,0 +1,73 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestComments extends ASTestBase
+{
+ // (mschmalle) comments aren't preserved, no need for them in release
+ // output...
+
+ @Test
+ public void testComment_SingleLine()
+ {
+// IFunctionNode node = getMethod("function a():void {// single line comment};");
+// visitor.visitFunction(node);
+// assertOut("function a():void {\n\t// single line comment\n}");
+ }
+
+ @Test
+ public void testComment_SingleLine_After()
+ {
+// IFunctionNode node = getMethod("function a():void {var a:String = ''; // single line comment};");
+// visitor.visitFunction(node);
+// assertOut("function a():void {\n\tvar a:String = ''; // single line comment\n}");
+ }
+
+ @Test
+ public void testComment_MultiLine()
+ {
+// IFunctionNode node = getMethod("function a():void {/*first line comment\nsecond line comment*/};");
+// visitor.visitFunction(node);
+// assertOut("function a():void {\n\t/*first line comment\n\tsecond line comment*/\n}");
+ }
+
+ @Test
+ public void testComment_InLine()
+ {
+// IFunctionNode node = getMethod("function a():void {var a:String /* inline comment */ = 'Hello world';};");
+// visitor.visitFunction(node);
+// assertOut("function a():void {\n\tvar a:String /* inline comment */ = 'Hello world';\n}");
+ }
+
+ @Test
+ public void testComment_ASDoc()
+ {
+// IFunctionNode node = getMethod("function a():void {/**\n * line comment\n */};");
+// visitor.visitFunction(node);
+// assertOut("function a():void {\n\t/**\n\t * line comment\n\t */};");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestExpressions.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestExpressions.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestExpressions.java
new file mode 100644
index 0000000..ab7d66f
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestExpressions.java
@@ -0,0 +1,764 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.internal.tree.as.ArrayLiteralNode;
+import org.apache.flex.compiler.internal.tree.as.ObjectLiteralNode;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+import org.apache.flex.compiler.tree.as.IIterationFlowNode;
+import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.INamespaceAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.IReturnNode;
+import org.apache.flex.compiler.tree.as.ITernaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * @author Michael Schmalle
+ */
+public class TestExpressions extends ASTestBase
+{
+
+ @Test
+ public void testVisitLanguageIdentifierNode_This()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) this.a;", IMemberAccessExpressionNode.class);
+ asBlockWalker.visitMemberAccessExpression(node);
+ assertOut("this.a");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_SuperMember()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) super.foo;", IMemberAccessExpressionNode.class);
+ asBlockWalker.visitMemberAccessExpression(node);
+ assertOut("super.foo");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_SuperMethod_1()
+ {
+ // NOTE: This is here as an example that a method call to super
+ // is always held within a IFunctionCallNode, here it's a plain member access
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) super.foo();", IMemberAccessExpressionNode.class);
+ asBlockWalker.visitMemberAccessExpression(node);
+ assertOut("super.foo");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_SuperMethod_2()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode(
+ "if (a) super.foo(a, b, c);", IFunctionCallNode.class);
+ asBlockWalker.visitFunctionCall(node);
+ assertOut("super.foo(a, b, c)");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_This1()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) this.a;", IMemberAccessExpressionNode.class);
+
+ asBlockWalker.visitMemberAccessExpression(node);
+ assertOut("this.a");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_This2()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) this.a;", IMemberAccessExpressionNode.class);
+
+ asBlockWalker.visitMemberAccessExpression(node);
+ assertOut("this.a");
+ }
+
+ //----------------------------------
+ // Primary expression keywords
+ //----------------------------------
+
+ //----------------------------------
+ // Arithmetic
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_Plus()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a + b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a + b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Minus()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a - b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a - b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Divide()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a / b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a / b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Modulo()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a % b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a % b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Multiply()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a * b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a * b");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_PostIncrement()
+ {
+ IUnaryOperatorNode node = getUnaryNode("a++");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("a++");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_PreIncrement()
+ {
+ IUnaryOperatorNode node = getUnaryNode("++a");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("++a");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_PostDecrement()
+ {
+ IUnaryOperatorNode node = getUnaryNode("a--");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("a--");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_PreDecrement()
+ {
+ IUnaryOperatorNode node = getUnaryNode("--a");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("--a");
+ }
+
+ //----------------------------------
+ // Arithmetic compound assignment
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_PlusAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a += b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a += b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_MinusAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a -= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a -= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_DivideAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a /= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a /= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_ModuloAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a %= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a %= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_MultiplyAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a *= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a *= b");
+ }
+
+ //----------------------------------
+ // Assignment
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_Assignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a = b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a = b");
+ }
+
+ //----------------------------------
+ // Bitwise
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseAnd()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a & b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a & b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseLeftShift()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a << b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a << b");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_BitwiseNot()
+ {
+ IUnaryOperatorNode node = getUnaryNode("~a");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("~a");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseOr()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a | b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a | b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseRightShift()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >> b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a >> b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseUnsignedRightShift()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >>> b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a >>> b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseXOR()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ^ b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a ^ b");
+ }
+
+ //----------------------------------
+ // Bitwise compound assignment
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseAndAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a &= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a &= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseLeftShiftAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a <<= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a <<= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseOrAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a |= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a |= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseRightShiftAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >>= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a >>= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseUnsignedRightShiftAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >>>= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a >>>= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseXORAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ^= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a ^= b");
+ }
+
+ //----------------------------------
+ // Comparison
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_Equal()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a == b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a == b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_GreaterThan()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a > b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a > b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_GreaterThanEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a >= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_NotEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a != b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a != b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LessThan()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a < b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a < b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LessThanEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a <= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a <= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_StrictEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a === b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a === b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_StrictNotEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a !== b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a !== b");
+ }
+
+ //----------------------------------
+ // Logical
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalAnd()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a && b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a && b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalAndAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a &&= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a &&= b");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_LogicalNot()
+ {
+ IUnaryOperatorNode node = getUnaryNode("!a");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("!a");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalOr()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a || b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a || b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalOrAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ||= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a ||= b");
+ }
+
+ //----------------------------------
+ // Other
+ //----------------------------------
+
+ @Test
+ public void testParentheses_1()
+ {
+ IVariableNode node = (IVariableNode) getNode("var a = (a + b);",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:* = (a + b)");
+ }
+
+ @Test
+ public void testParentheses_2()
+ {
+ IVariableNode node = (IVariableNode) getNode("var a = (a + b) - c;",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:* = (a + b) - c");
+ }
+
+ @Test
+ public void testParentheses_3()
+ {
+ IVariableNode node = (IVariableNode) getNode(
+ "var a = ((a + b) - (c + d)) * e;", IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:* = ((a + b) - (c + d)) * e");
+ }
+
+ @Test
+ public void testAnonymousFunction()
+ {
+ IVariableNode node = (IVariableNode) getNode("var a = function(){};",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:* = function() {\n}");
+ }
+
+ @Test
+ public void testAnonymousFunctionWithParamsReturn()
+ {
+ IVariableNode node = (IVariableNode) getNode(
+ "var a:Object = function(foo:int, bar:String = 'goo'):int{return -1;};",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Object = function(foo:int, bar:String = 'goo'):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testAnonymousFunctionAsArgument()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode(
+ "addListener('foo', function(event:Object):void{doit();});",
+ IFunctionCallNode.class);
+ asBlockWalker.visitFunctionCall(node);
+ assertOut("addListener('foo', function(event:Object):void {\n\tdoit();\n})");
+ }
+
+ @Test
+ public void testVisitDynamicAccessNode_1()
+ {
+ IDynamicAccessNode node = getDynamicAccessNode("a[b]");
+ asBlockWalker.visitDynamicAccess(node);
+ assertOut("a[b]");
+ }
+
+ @Test
+ public void testVisitDynamicAccessNode_2()
+ {
+ IDynamicAccessNode node = getDynamicAccessNode("a[b[c][d]]");
+ asBlockWalker.visitDynamicAccess(node);
+ assertOut("a[b[c][d]]");
+ }
+
+ @Test
+ public void testVisitAs()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a as b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a as b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Comma()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a, b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a, b");
+ }
+
+ @Test
+ public void testVisitTernaryOperatorNode()
+ {
+ ITernaryOperatorNode node = (ITernaryOperatorNode) getExpressionNode(
+ "a ? b : c", ITernaryOperatorNode.class);
+ asBlockWalker.visitTernaryOperator(node);
+ assertOut("a ? b : c");
+ }
+
+ @Test
+ public void testVisitUnaryOperator_Delete()
+ {
+ IUnaryOperatorNode node = getUnaryNode("delete a");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("delete a");
+ }
+
+ @Test
+ public void testVisitMemberAccess_1()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getExpressionNode(
+ "a.b", IMemberAccessExpressionNode.class);
+ asBlockWalker.visitMemberAccessExpression(node);
+ assertOut("a.b");
+ }
+
+ @Test
+ public void testVisitMemberAccess_2()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getExpressionNode(
+ "a.b.c.d", IMemberAccessExpressionNode.class);
+ asBlockWalker.visitMemberAccessExpression(node);
+ assertOut("a.b.c.d");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_In()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a in b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a in b");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_Instancof()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a instanceof b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a instanceof b");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_Is()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a is b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a is b");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_NamespaceAccess_1()
+ {
+ INamespaceAccessExpressionNode node = getNamespaceAccessExpressionNode("a::b");
+ asBlockWalker.visitNamespaceAccessExpression(node);
+ assertOut("a::b");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_NamespaceAccess_2()
+ {
+ INamespaceAccessExpressionNode node = getNamespaceAccessExpressionNode("a::b::c");
+ asBlockWalker.visitNamespaceAccessExpression(node);
+ assertOut("a::b::c");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_New()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getExpressionNode(
+ "new Object()", IFunctionCallNode.class);
+ asBlockWalker.visitFunctionCall(node);
+ assertOut("new Object()");
+ }
+
+ @Test
+ public void testVisitObjectLiteral_1()
+ {
+ ObjectLiteralNode node = (ObjectLiteralNode) getExpressionNode(
+ "a = {a:1}", ObjectLiteralNode.class);
+ asBlockWalker.visitLiteral(node);
+ assertOut("{a:1}");
+ }
+
+ @Test
+ public void testVisitObjectLiteral_2()
+ {
+ ObjectLiteralNode node = (ObjectLiteralNode) getExpressionNode(
+ "a = {a:1,b:{c:2,d:{e:4}}}", ObjectLiteralNode.class);
+ asBlockWalker.visitLiteral(node);
+ assertOut("{a:1, b:{c:2, d:{e:4}}}");
+ }
+
+ @Test
+ public void testVisitArrayLiteral_1()
+ {
+ ArrayLiteralNode node = (ArrayLiteralNode) getExpressionNode(
+ "a = [0,1,2]", ArrayLiteralNode.class);
+ asBlockWalker.visitLiteral(node);
+ assertOut("[0, 1, 2]");
+ }
+
+ @Test
+ public void testVisitArrayLiteral_2()
+ {
+ ArrayLiteralNode node = (ArrayLiteralNode) getExpressionNode(
+ "a = [0,[0,1,[0,1]],2,[1,2]]", ArrayLiteralNode.class);
+ asBlockWalker.visitLiteral(node);
+ assertOut("[0, [0, 1, [0, 1]], 2, [1, 2]]");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_Typeof()
+ {
+ IUnaryOperatorNode node = getUnaryNode("typeof(a)");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("typeof(a)");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_Typeof_NoParens()
+ {
+ // TODO (mschmalle) the notation without parenthesis is also valid in AS/JS
+ IUnaryOperatorNode node = getUnaryNode("typeof a");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("typeof(a)");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_Void()
+ {
+ IUnaryOperatorNode node = getUnaryNode("void a");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("void a");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_Concate_1()
+ {
+ IBinaryOperatorNode node = getBinaryNode("\"a\" + \"b\"");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("\"a\" + \"b\"");
+ }
+
+ // TODO (mschmalle) what's up with the escaping of backslashes?
+ @Test
+ public void testVisitUnaryOperatorNode_Concate_2()
+ {
+// IBinaryOperatorNode node = getBinaryNode("\"a\\\"\" + \"\\\"b\"");
+// asBlockWalker.visitBinaryOperator(node);
+// assertOut("\"a\\\"\" + \"\\\"b\"");
+ }
+
+ @Test
+ public void testVisitIterationFlowNode_Break()
+ {
+ IIterationFlowNode node = (IIterationFlowNode) getNode("break",
+ IIterationFlowNode.class);
+ asBlockWalker.visitIterationFlow(node);
+ assertOut("break");
+ }
+
+ @Test
+ public void testVisitIterationFlowNode_Continue()
+ {
+ IIterationFlowNode node = (IIterationFlowNode) getNode("continue",
+ IIterationFlowNode.class);
+ asBlockWalker.visitIterationFlow(node);
+ assertOut("continue");
+ }
+
+ @Test
+ public void testVisitReturn()
+ {
+ IReturnNode node = (IReturnNode) getNode("return", IReturnNode.class);
+ asBlockWalker.visitReturn(node);
+ assertOut("return");
+ }
+
+ @Test
+ public void testVisitFunctionCall_1()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode("a()", IFunctionCallNode.class);
+ asBlockWalker.visitFunctionCall(node);
+ assertOut("a()");
+ }
+
+ @Test
+ public void testVisitFunctionCall_2()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode("a(b)", IFunctionCallNode.class);
+ asBlockWalker.visitFunctionCall(node);
+ assertOut("a(b)");
+ }
+
+ @Test
+ public void testVisitFunctionCall_3()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode("a(b, c)", IFunctionCallNode.class);
+ asBlockWalker.visitFunctionCall(node);
+ assertOut("a(b, c)");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestFieldMembers.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestFieldMembers.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestFieldMembers.java
new file mode 100644
index 0000000..0de9f0e
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestFieldMembers.java
@@ -0,0 +1,204 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.INamespaceNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Class Field
+ * members.
+ *
+ * @author Michael Schmalle
+ */
+public class TestFieldMembers extends ASTestBase
+{
+ /*
+ * Field, Constant, [Namespace]
+ *
+ * var foo;
+ * var foo:int;
+ * var foo:int = 42;
+ * private var foo:int;
+ * private var foo:int = 42;
+ * protected var foo:int;
+ * public var foo:int;
+ */
+
+ //--------------------------------------------------------------------------
+ // Field
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testField()
+ {
+ IVariableNode node = getField("var foo;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var foo:*");
+ }
+
+ @Test
+ public void testField_withType()
+ {
+ IVariableNode node = getField("var foo:int;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var foo:int");
+ }
+
+ @Test
+ public void testField_withTypeValue()
+ {
+ IVariableNode node = getField("var foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var foo:int = 420");
+ }
+
+ @Test
+ public void testField_withNamespaceTypeValue()
+ {
+ IVariableNode node = getField("private var foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("private var foo:int = 420");
+ }
+
+ @Test
+ public void testField_withCustomNamespaceTypeValue()
+ {
+ IVariableNode node = getField("mx_internal var foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("mx_internal var foo:int = 420");
+ }
+
+ @Test
+ public void testField_withNamespaceTypeCollection()
+ {
+ IVariableNode node = getField("protected var foo:Vector.<Foo>;");
+ asBlockWalker.visitVariable(node);
+ assertOut("protected var foo:Vector.<Foo>");
+ }
+
+ @Test
+ public void testField_withNamespaceTypeCollectionComplex()
+ {
+ IVariableNode node = getField("protected var foo:Vector.<Vector.<Vector.<Foo>>>;");
+ asBlockWalker.visitVariable(node);
+ assertOut("protected var foo:Vector.<Vector.<Vector.<Foo>>>");
+ }
+
+ @Test
+ public void testField_withNamespaceTypeValueComplex()
+ {
+ IVariableNode node = getField("protected var foo:Foo = new Foo('bar', 42);");
+ asBlockWalker.visitVariable(node);
+ assertOut("protected var foo:Foo = new Foo('bar', 42)");
+ }
+
+ @Test
+ public void testField_withList()
+ {
+ IVariableNode node = getField("protected var a:int = 4, b:int = 11, c:int = 42;");
+ asBlockWalker.visitVariable(node);
+ assertOut("protected var a:int = 4, b:int = 11, c:int = 42");
+ }
+
+ //--------------------------------------------------------------------------
+ // Constant
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testConstant()
+ {
+ IVariableNode node = getField("static const foo;");
+ asBlockWalker.visitVariable(node);
+ assertOut("static const foo:*");
+ }
+
+ @Test
+ public void testConstant_withType()
+ {
+ IVariableNode node = getField("static const foo:int;");
+ asBlockWalker.visitVariable(node);
+ assertOut("static const foo:int");
+ }
+
+ @Test
+ public void testConstant_withTypeValue()
+ {
+ IVariableNode node = getField("static const foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("static const foo:int = 420");
+ }
+
+ @Test
+ public void testConstant_withNamespaceTypeValue()
+ {
+ IVariableNode node = getField("private static const foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("private static const foo:int = 420");
+ }
+
+ @Test
+ public void testConstant_withCustomNamespaceTypeValue()
+ {
+ IVariableNode node = getField("mx_internal static const foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("mx_internal static const foo:int = 420");
+ }
+
+ //--------------------------------------------------------------------------
+ // Namespace
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testNamespace()
+ {
+ INamespaceNode node = getNamespace("namespace ns = \"http://whatever\";");
+ asBlockWalker.visitNamespace(node);
+ assertOut("namespace ns = \"http://whatever\"");
+ }
+
+ @Test
+ public void testNamespace_public()
+ {
+ INamespaceNode node = getNamespace("public namespace ns = \"http://whatever\";");
+ asBlockWalker.visitNamespace(node);
+ assertOut("public namespace ns = \"http://whatever\"");
+ }
+
+ @Test
+ public void testNamespace_protected()
+ {
+ INamespaceNode node = getNamespace("protected namespace ns = \"http://whatever\";");
+ asBlockWalker.visitNamespace(node);
+ assertOut("protected namespace ns = \"http://whatever\"");
+ }
+
+ protected INamespaceNode getNamespace(String code)
+ {
+ String source = "package {public class A {" + code + "}}";
+ IFileNode node = compileAS(source);
+ INamespaceNode child = (INamespaceNode) findFirstDescendantOfType(node,
+ INamespaceNode.class);
+ return child;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalClasses.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalClasses.java
new file mode 100644
index 0000000..6f5797f
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalClasses.java
@@ -0,0 +1,280 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestGlobalClasses extends ASTestBase
+{
+ @Test
+ public void testArgumentError()
+ {
+ IVariableNode node = getVariable("var a:ArgumentError = new ArgumentError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:ArgumentError = new ArgumentError()");
+ }
+
+ @Test
+ public void testArguments()
+ {
+ IFunctionNode node = getMethod("function a():void {\ttrace(arguments);}");
+ asBlockWalker.visitFunction(node);
+ assertOut("function a():void {\n\ttrace(arguments);\n}");
+ }
+
+ @Test
+ public void testArray()
+ {
+ IVariableNode node = getVariable("var a:Array = new Array(1);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Array = new Array(1)");
+ }
+
+ @Test
+ public void testBoolean()
+ {
+ IVariableNode node = getVariable("var a:Boolean = new Boolean(1);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Boolean = new Boolean(1)");
+ }
+
+ @Test
+ public void testClass()
+ {
+ IVariableNode node = getVariable("var a:Class = Class(FooBar)");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Class = Class(FooBar)");
+ }
+
+ @Test
+ public void testDate()
+ {
+ IVariableNode node = getVariable("var a:Date = new Date();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Date = new Date()");
+ }
+
+ @Test
+ public void testDefinitionError()
+ {
+ IVariableNode node = getVariable("var a:DefinitionError = new DefinitionError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:DefinitionError = new DefinitionError()");
+ }
+
+ @Test
+ public void testError()
+ {
+ IVariableNode node = getVariable("var a:Error = new Error();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Error = new Error()");
+ }
+
+ @Test
+ public void testEvalError()
+ {
+ IVariableNode node = getVariable("var a:EvalError = new EvalError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:EvalError = new EvalError()");
+ }
+
+ @Test
+ public void testFunction()
+ {
+ IVariableNode node = getVariable("var a:Function = new Function();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Function = new Function()");
+ }
+
+ @Test
+ public void testInt()
+ {
+ IVariableNode node = getVariable("var a:int = new int(1.8);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:int = new int(1.8)");
+ }
+
+ @Test
+ public void testJSON()
+ {
+ IVariableNode node = getVariable("var a:JSON = new JSON();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:JSON = new JSON()");
+ }
+
+ @Test
+ public void testMath()
+ {
+ IVariableNode node = getVariable("var a:Number = Math.PI;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Number = Math.PI");
+ }
+
+ @Test
+ public void testNamespace()
+ {
+ IVariableNode node = getVariable("var a:Namespace = new Namespace(\"http://example.com\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Namespace = new Namespace(\"http://example.com\")");
+ }
+
+ @Test
+ public void testNumber()
+ {
+ IVariableNode node = getVariable("var a:Number = new Number(\"1\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Number = new Number(\"1\")");
+ }
+
+ @Test
+ public void testObject()
+ {
+ IVariableNode node = getVariable("var a:Object = new Object();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Object = new Object()");
+ }
+
+ @Test
+ public void testQName()
+ {
+ IVariableNode node = getVariable("var a:QName = new QName();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:QName = new QName()");
+ }
+
+ @Test
+ public void testRangeError()
+ {
+ IVariableNode node = getVariable("var a:RangeError = new RangeError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:RangeError = new RangeError()");
+ }
+
+ @Test
+ public void testReferenceError()
+ {
+ IVariableNode node = getVariable("var a:ReferenceError = new ReferenceError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:ReferenceError = new ReferenceError()");
+ }
+
+ // TODO (mschmalle) the backslashes in don't match the backslashes out...
+ @Test
+ public void testRegExp()
+ {
+// IVariableNode node = getVariable("var a:RegExp = new RegExp('test-\\d', 'i');");
+// asBlockWalker.visitVariable(node);
+// assertOut("var a:RegExp = new RegExp('test-\\\\d', 'i')");
+ }
+
+ @Test
+ public void testRegExp_Literal()
+ {
+ IVariableNode node = getVariable("var a:RegExp = /test-\\d/i;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:RegExp = /test-\\d/i");
+ }
+
+ @Test
+ public void testSecurityError()
+ {
+ IVariableNode node = getVariable("var a:SecurityError = new SecurityError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:SecurityError = new SecurityError()");
+ }
+
+ @Test
+ public void testString()
+ {
+ IVariableNode node = getVariable("var a:String = new String(\"100\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:String = new String(\"100\")");
+ }
+
+ @Test
+ public void testSyntaxError()
+ {
+ IVariableNode node = getVariable("var a:SyntaxError = new SyntaxError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:SyntaxError = new SyntaxError()");
+ }
+
+ @Test
+ public void testTypeError()
+ {
+ IVariableNode node = getVariable("var a:TypeError = new TypeError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:TypeError = new TypeError()");
+ }
+
+ @Test
+ public void testUint()
+ {
+ IVariableNode node = getVariable("var a:uint = new uint(-100);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:uint = new uint(-100)");
+ }
+
+ @Test
+ public void testURIError()
+ {
+ IVariableNode node = getVariable("var a:URIError = new URIError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:URIError = new URIError()");
+ }
+
+ @Test
+ public void testVector()
+ {
+ IVariableNode node = getVariable("var a:Vector.<String> = new Vector.<String>(['Hello', 'World']);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Vector.<String> = new Vector.<String>(['Hello', 'World'])");
+ }
+
+ @Test
+ public void testVerifyError()
+ {
+ IVariableNode node = getVariable("var a:VerifyError = new VerifyError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:VerifyError = new VerifyError()");
+ }
+
+ @Test
+ public void testXML()
+ {
+ IVariableNode node = getVariable("var a:XML = new XML('@');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:XML = new XML('@')");
+ }
+
+ @Test
+ public void testXMLList()
+ {
+ IVariableNode node = getVariable("var a:XMLList = new XMLList('<!-- comment -->');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:XMLList = new XMLList('<!-- comment -->')");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalConstants.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalConstants.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalConstants.java
new file mode 100644
index 0000000..ada60af
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalConstants.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestGlobalConstants extends ASTestBase
+{
+ @Test
+ public void testInfinity()
+ {
+ IVariableNode node = getField("var a:Number = Infinity;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Number = Infinity");
+ }
+
+ @Test
+ public void testNegativeInfinity()
+ {
+ IVariableNode node = getField("var a:Number = -Infinity;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Number = -Infinity");
+ }
+
+ @Test
+ public void testNaN()
+ {
+ IVariableNode node = getField("var a:Number = NaN;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Number = NaN");
+ }
+
+ @Test
+ public void testUndefined()
+ {
+ IVariableNode node = getField("var a:* = undefined;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:* = undefined");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalFunctions.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalFunctions.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalFunctions.java
new file mode 100644
index 0000000..2b7a274
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestGlobalFunctions.java
@@ -0,0 +1,208 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestGlobalFunctions extends ASTestBase
+{
+ @Test
+ public void testArray()
+ {
+ IVariableNode node = getVariable("var a:Array = Array(1);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Array = Array(1)");
+ }
+
+ @Test
+ public void testBoolean()
+ {
+ IVariableNode node = getVariable("var a:Boolean = Boolean(1);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Boolean = Boolean(1)");
+ }
+
+ @Test
+ public void testDecodeURI()
+ {
+ IVariableNode node = getVariable("var a:String = decodeURI('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:String = decodeURI('http://whatever.com')");
+ }
+
+ @Test
+ public void testDecodeURIComponent()
+ {
+ IVariableNode node = getVariable("var a:String = decodeURIComponent('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:String = decodeURIComponent('http://whatever.com')");
+ }
+
+ @Test
+ public void testEncodeURI()
+ {
+ IVariableNode node = getVariable("var a:String = encodeURI('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:String = encodeURI('http://whatever.com')");
+ }
+
+ @Test
+ public void testEncodeURIComponent()
+ {
+ IVariableNode node = getVariable("var a:String = encodeURIComponent('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:String = encodeURIComponent('http://whatever.com')");
+ }
+
+ @Test
+ public void testEscape()
+ {
+ IVariableNode node = getVariable("var a:String = escape('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:String = escape('http://whatever.com')");
+ }
+
+ @Test
+ public void testInt()
+ {
+ IVariableNode node = getVariable("var a:int = int(1.8);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:int = int(1.8)");
+ }
+
+ @Test
+ public void testIsFinite()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isFinite(1000000.9);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Boolean = isFinite(1000000.9)");
+ }
+
+ @Test
+ public void testIsNaN()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isNaN(NaN);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Boolean = isNaN(NaN)");
+ }
+
+ @Test
+ public void testIsXMLName()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isXMLName(\"?\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Boolean = isXMLName(\"?\")");
+ }
+
+ @Test
+ public void testNumber()
+ {
+ IVariableNode node = getVariable("var a:Number = Number(\"1\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Number = Number(\"1\")");
+ }
+
+ @Test
+ public void testObject()
+ {
+ IVariableNode node = getVariable("var a:Object = Object(\"1\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Object = Object(\"1\")");
+ }
+
+ @Test
+ public void testParseFloat()
+ {
+ IVariableNode node = getVariable("var a:Number = parseFloat(\"1.8\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Number = parseFloat(\"1.8\")");
+ }
+
+ @Test
+ public void testParseInt()
+ {
+ IVariableNode node = getVariable("var a:Number = parseInt(\"666\", 10);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Number = parseInt(\"666\", 10)");
+ }
+
+ @Test
+ public void testString()
+ {
+ IVariableNode node = getVariable("var a:String = String(100);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:String = String(100)");
+ }
+
+ @Test
+ public void testTrace()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode(
+ "trace('Hello World');", IFunctionCallNode.class);
+ asBlockWalker.visitFunctionCall(node);
+ assertOut("trace('Hello World')");
+ }
+
+ @Test
+ public void testUint()
+ {
+ IVariableNode node = getVariable("var a:uint = uint(-100);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:uint = uint(-100)");
+ }
+
+ @Test
+ public void testUnescape()
+ {
+ IVariableNode node = getVariable("var a:String = unescape('%25');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:String = unescape('%25')");
+ }
+
+ @Test
+ public void testVector()
+ {
+ IVariableNode node = getVariable("var a:Vector.<String> = Vector.<String>(['Hello', 'World']);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:Vector.<String> = Vector.<String>(['Hello', 'World'])");
+ }
+
+ @Test
+ public void testXML()
+ {
+ IVariableNode node = getVariable("var a:XML = XML('@');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:XML = XML('@')");
+ }
+
+ @Test
+ public void testXMLList()
+ {
+ IVariableNode node = getVariable("var a:XMLList = XMLList('<!-- comment -->');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:XMLList = XMLList('<!-- comment -->')");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestInterface.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestInterface.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestInterface.java
new file mode 100644
index 0000000..2b15349
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestInterface.java
@@ -0,0 +1,105 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Interface
+ * production.
+ *
+ * @author Michael Schmalle
+ */
+public class TestInterface extends ASTestBase
+{
+ //--------------------------------------------------------------------------
+ // Interface
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testSimple()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA{}");
+ asBlockWalker.visitInterface(node);
+ assertOut("public interface IA {\n}");
+ }
+
+ @Test
+ public void testSimpleExtends()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA extends IB{}");
+ asBlockWalker.visitInterface(node);
+ assertOut("public interface IA extends IB {\n}");
+ }
+
+ @Test
+ public void testSimpleExtendsMultiple()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA extends IB, IC, ID {}");
+ asBlockWalker.visitInterface(node);
+ assertOut("public interface IA extends IB, IC, ID {\n}");
+ }
+
+ @Test
+ public void testQualifiedExtendsMultiple()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA extends foo.bar.IB, baz.goo.IC, foo.ID {}");
+ asBlockWalker.visitInterface(node);
+ assertOut("public interface IA extends foo.bar.IB, baz.goo.IC, foo.ID {\n}");
+ }
+
+ @Test
+ public void testAccessors()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA {"
+ + "function get foo1():Object;"
+ + "function set foo1(value:Object):void;}");
+ asBlockWalker.visitInterface(node);
+ assertOut("public interface IA {\n\tfunction get foo1():Object;\n\t"
+ + "function set foo1(value:Object):void;\n}");
+ }
+
+ @Test
+ public void testMethods()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA {"
+ + "function foo1():Object;"
+ + "function foo1(value:Object):void;}");
+ asBlockWalker.visitInterface(node);
+ assertOut("public interface IA {\n\tfunction foo1():Object;\n\t"
+ + "function foo1(value:Object):void;\n}");
+ }
+
+ @Test
+ public void testAccessorsMethods()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA {"
+ + "function get foo1():Object;"
+ + "function set foo1(value:Object):void;"
+ + "function baz1():Object;"
+ + "function baz2(value:Object):void;}");
+ asBlockWalker.visitInterface(node);
+ assertOut("public interface IA {\n\tfunction get foo1():Object;"
+ + "\n\tfunction set foo1(value:Object):void;\n\tfunction baz1()"
+ + ":Object;\n\tfunction baz2(value:Object):void;\n}");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestMethodMembers.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestMethodMembers.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestMethodMembers.java
new file mode 100644
index 0000000..ce4316f
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestMethodMembers.java
@@ -0,0 +1,147 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Class Method
+ * members.
+ *
+ * @author Michael Schmalle
+ */
+public class TestMethodMembers extends ASTestBase
+{
+ /*
+ * Method
+ *
+ * function foo(){}
+ * function foo():int{}
+ * function foo(bar):int{}
+ * function foo(bar:String):int{}
+ * function foo(bar:String = "baz"):int{}
+ * function foo(bar:String, baz:int = null):int{}
+ * function foo(bar:String, ...rest):int{}
+ * public function foo(bar:String, baz:int = null):int{}
+ * public static function foo(bar:String, baz:int = null):int{}
+ */
+
+ //--------------------------------------------------------------------------
+ // Method
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testMethod()
+ {
+ IFunctionNode node = getMethod("function foo(){}");
+ asBlockWalker.visitFunction(node);
+ assertOut("function foo() {\n}");
+ }
+
+ @Test
+ public void testMethod_withReturnType()
+ {
+ IFunctionNode node = getMethod("function foo():int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("function foo():int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withParameterReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("function foo(bar:*):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("function foo(bar:String):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withDefaultParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String = \"baz\"):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("function foo(bar:String = \"baz\"):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withMultipleDefaultParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withRestParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String, ...rest):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("function foo(bar:String, ...rest):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespace()
+ {
+ IFunctionNode node = getMethod("public function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("public function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespaceCustom()
+ {
+ IFunctionNode node = getMethod("mx_internal function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("mx_internal function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespaceModifiers()
+ {
+ IFunctionNode node = getMethod("public static function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("public static function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespaceModifierOverride()
+ {
+ IFunctionNode node = getMethod("public override function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("public override function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespaceModifierOverrideBackwards()
+ {
+ IFunctionNode node = getMethod("override public function foo(bar:String, baz:int = null):int{return -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("public override function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestPackage.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestPackage.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestPackage.java
new file mode 100644
index 0000000..ad8b4e7
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestPackage.java
@@ -0,0 +1,103 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Package
+ * production.
+ *
+ * @author Michael Schmalle
+ */
+public class TestPackage extends ASTestBase
+{
+ //--------------------------------------------------------------------------
+ // Package
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testPackage_Simple()
+ {
+ IFileNode node = compileAS("package{}");
+ asBlockWalker.visitFile(node);
+ assertOut("package {\n}");
+ }
+
+ @Test
+ public void testPackage_SimpleName()
+ {
+ IFileNode node = compileAS("package foo {}");
+ asBlockWalker.visitFile(node);
+ assertOut("package foo {\n}");
+ }
+
+ @Test
+ public void testPackage_Name()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {}");
+ asBlockWalker.visitFile(node);
+ assertOut("package foo.bar.baz {\n}");
+ }
+
+ @Test
+ public void testPackageSimple_Class()
+ {
+ IFileNode node = compileAS("package {public class A{}}");
+ asBlockWalker.visitFile(node);
+ assertOut("package {\n\tpublic class A {\n\t}\n}");
+ }
+
+ @Test
+ public void testPackageQualified_Class()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {public class A{}}");
+ asBlockWalker.visitFile(node);
+ assertOut("package foo.bar.baz {\n\tpublic class A {\n\t}\n}");
+ }
+
+ @Test
+ public void testPackageQualified_ClassBody()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {public class A{public function A(){}}}");
+ asBlockWalker.visitFile(node);
+ assertOut("package foo.bar.baz {\n\tpublic class A {\n\t\tpublic function A() {\n\t\t}\n\t}\n}");
+ }
+
+ @Test
+ public void testPackageQualified_ClassBodyMethodContents()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {public class A{public function A(){if (a){for each(var i:Object in obj){doit();}}}}}");
+ asBlockWalker.visitFile(node);
+ assertOut("package foo.bar.baz {\n\tpublic class A {\n\t\tpublic function A() {\n\t\t\t"
+ + "if (a) {\n\t\t\t\tfor each (var i:Object in obj) {\n\t\t\t\t\tdoit();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}");
+ }
+
+ // TODO (mschmalle) implement Import unit tests for as
+ @Test
+ public void testPackage_Import()
+ {
+// IFileNode node = compileAS("package{import foo.bar.Baz;}");
+// asBlockWalker.visitFile(node);
+// assertOut("package {\nimport foo.bar.Baz;}");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestParenthesis.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestParenthesis.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestParenthesis.java
new file mode 100644
index 0000000..5674dd9
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/as/TestParenthesis.java
@@ -0,0 +1,98 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IReturnNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * @author Michael Schmalle
+ */
+public class TestParenthesis extends ASTestBase
+{
+ @Test
+ public void testParentheses_1()
+ {
+ IVariableNode node = (IVariableNode) getNode("var a = (a + b);",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:* = (a + b)");
+ }
+
+ @Test
+ public void testParentheses_2()
+ {
+ IVariableNode node = (IVariableNode) getNode(
+ "var a = ((a + b) - (c + d)) * e;", IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var a:* = ((a + b) - (c + d)) * e");
+ }
+
+ @Test
+ public void testParentheses_3()
+ {
+ IBinaryOperatorNode node = (IBinaryOperatorNode) getNode(
+ "a = (a + b) - c + d * e;", IBinaryOperatorNode.class);
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a = (a + b) - c + d * e");
+ }
+
+ @Test
+ public void testParentheses_4()
+ {
+ IBinaryOperatorNode node = (IBinaryOperatorNode) getNode(
+ "a = ((a + b) - (c + d)) * e;", IBinaryOperatorNode.class);
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a = ((a + b) - (c + d)) * e");
+ }
+
+ @Test
+ public void testParentheses_Strings1()
+ {
+ IBinaryOperatorNode node = (IBinaryOperatorNode) getNode(
+ "a = '' + '' + '' + ''", IBinaryOperatorNode.class);
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a = '' + '' + '' + ''");
+ }
+
+ @Test
+ public void testParentheses_Strings2()
+ {
+ // this is a whacked test but is just proves the logic that for now,
+ // we only leave out parens for String literals on the right hand side
+ IBinaryOperatorNode node = (IBinaryOperatorNode) getNode(
+ "a = '' + 2 + '' + '' * 4 ", IBinaryOperatorNode.class);
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a = '' + 2 + '' + '' * 4");
+ }
+
+ @Test
+ public void testParentheses_Ternary()
+ {
+ IReturnNode node = (IReturnNode) getNode(
+ "return \"a \" + (a < b ? \"<\" : \">=\") + \" b\";", IReturnNode.class);
+ asBlockWalker.visitReturn(node);
+ assertOut("return \"a \" + (a < b ? \"<\" : \">=\") + \" b\"");
+ }
+
+}