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:14 UTC
[22/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/js/goog/TestGoogClass.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogClass.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogClass.java
new file mode 100644
index 0000000..2bad420
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogClass.java
@@ -0,0 +1,260 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestClass;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+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 'goog' JS code for Classes.
+ *
+ * @author Michael Schmalle
+ * @author Erik de Bruin
+ */
+public class TestGoogClass extends TestClass
+{
+ @Override
+ @Test
+ public void testSimple()
+ {
+ IClassNode node = getClassNode("public class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleInternal()
+ {
+ // (erikdebruin) the AS compiler will enforce 'internal' namespace,
+ // in JS we ignore it
+ IClassNode node = getClassNode("internal class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleFinal()
+ {
+ // (erikdebruin) the AS compiler will enforce the 'final' keyword,
+ // in JS we ignore it
+ IClassNode node = getClassNode("public final class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleDynamic()
+ {
+ // (erikdebruin) all JS objects are 'dynamic' by design
+ IClassNode node = getClassNode("public dynamic class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleExtends()
+ {
+ IClassNode node = getClassNode("public class A extends EventTarget {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n */\norg.apache.flex.A = function() {\n\torg.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testSimpleImplements()
+ {
+ IClassNode node = getClassNode("public class A implements IEventDispatcher {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @implements {flash.events.IEventDispatcher}\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A implements IEventDispatcher, ListenableKey {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @implements {flash.events.IEventDispatcher}\n * @implements {goog.events.ListenableKey}\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleExtendsImplements()
+ {
+ IClassNode node = getClassNode("public class A extends EventTarget implements IEventDispatcher {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @implements {flash.events.IEventDispatcher}\n */\norg.apache.flex.A = function() {\n\torg.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testSimpleExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A extends EventTarget implements IEventDispatcher, ListenableKey {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @implements {flash.events.IEventDispatcher}\n * @implements {goog.events.ListenableKey}\n */\norg.apache.flex.A = function() {\n\torg.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testSimpleFinalExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public final class A extends EventTarget implements IEventDispatcher, ListenableKey {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @implements {flash.events.IEventDispatcher}\n * @implements {goog.events.ListenableKey}\n */\norg.apache.flex.A = function() {\n\torg.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testQualifiedExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A extends goog.events.EventTarget implements flash.events.IEventDispatcher, goog.events.ListenableKey {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @implements {flash.events.IEventDispatcher}\n * @implements {goog.events.ListenableKey}\n */\norg.apache.flex.A = function() {\n\torg.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testConstructor()
+ {
+ IClassNode node = getClassNode("public class A {public function A() { }}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Test
+ public void testConstructor_super()
+ {
+ IClassNode node = getClassNode("public class A {public function A() { super(); }}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n\tvar self = this;\n\t;\n};");
+ }
+
+ @Test
+ public void testExtendsConstructor_super()
+ {
+ IClassNode node = getClassNode("public class A extends goog.events.EventTarget { public function A() { super('foo', 42);}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n */\norg.apache.flex.A = function() {\n\tvar self = this;\n\torg.apache.flex.A.base(this, 'constructor', 'foo', 42);\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testConstructor_withArguments()
+ {
+ IClassNode node = getClassNode("public class A {public function A(arg1:String, arg2:int) {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @param {string} arg1\n * @param {number} arg2\n */\norg.apache.flex.A = function(arg1, arg2) {\n};");
+ }
+
+ @Override
+ @Test
+ public void testExtendsConstructor_withArguments()
+ {
+ IClassNode node = getClassNode("public class A extends goog.events.EventTarget {public function A(arg1:String, arg2:int) {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @param {string} arg1\n * @param {number} arg2\n */\norg.apache.flex.A = function(arg1, arg2) {\n\torg.apache.flex.A.base(this, 'constructor', arg1, arg2);\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @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("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};\n\n/**\n * @type {Object}\n */\norg.apache.flex.A.prototype.a;\n\n/**\n * @protected\n * @type {string}\n */\norg.apache.flex.A.prototype.b;\n\n/**\n * @private\n * @type {number}\n */\norg.apache.flex.A.prototype.c;\n\n/**\n * @type {number}\n */\norg.apache.flex.A.prototype.d;\n\n/**\n * @type {number}\n */\norg.apache.flex.A.prototype.e;");
+ }
+
+ @Override
+ @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("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};\n\n/**\n * @const\n * @type {number}\n */\norg.apache.flex.A.A = 42;\n\n/**\n * @protected\n * @const\n * @type {number}\n */\norg.apache.flex.A.B = 42;\n\n/**\n * @private\n * @const\n * @type {number}\n */\norg.apache.flex.A.C = 42;\n\n/**\n * @const\n * @type {string}\n */\norg.apache.flex.A.C = 'me' + 'you';");
+ }
+
+ @Override
+ @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("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};\n\n/**\n * @type {Object}\n */\norg.apache.flex.A.prototype.foo1;\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo1', \n\t{get:function() {\n\t\tvar self = this;\n\t\treturn null;\n\t}, configurable:true}\n);\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo1', \n\t{set:function(value) {\n\t}, configurable:true}\n);\n\n/**\n * @protected\n * @type {Object}\n */\norg.apache.flex.A.prototype.foo2;\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo2', \n\t{get:function() {\n\t\tvar self = this;\n\t\treturn null;\n\t}, configurable:true}\n);\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo2', \n\t{set:function(value) {\n\t}, configurable:true}\n);\n\n/**\n * @private\n * @type {Object}\n */\norg.apache.flex.A.prototype.foo3;\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo3', \n\t{get:function() {\n\t\tvar self = this;\
n\t\treturn null;\n\t}, configurable:true}\n);\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo3', \n\t{set:function(value) {\n\t}, configurable:true}\n);\n\n/**\n * @type {Object}\n */\norg.apache.flex.A.prototype.foo5;\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo5', \n\t{get:function() {\n\t\tvar self = this;\n\t\treturn null;\n\t}, configurable:true}\n);\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo5', \n\t{set:function(value) {\n\t}, configurable:true}\n);\n\n/**\n * @type {Object}\n */\norg.apache.flex.A.prototype.foo6;\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo6', \n\t{get:function() {\n\t\tvar self = this;\n\t\treturn null;\n\t}, configurable:true}\n);\n\nObject.defineProperty(\n\torg.apache.flex.A.prototype, \n\t'foo6', \n\t{set:function(value) {\n\t}, configurable:true}\n);");
+ }
+
+ @Override
+ @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("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};\n\n/**\n * @return {Object}\n */\norg.apache.flex.A.prototype.foo1 = function() {\n\tvar self = this;\n\treturn null;\n};\n\n/**\n * @return {Object}\n */\norg.apache.flex.A.prototype.foo1a = function() {\n\tvar self = this;\n\treturn null;\n};\n\n/**\n * @return {Object}\n * @override\n */\norg.apache.flex.A.prototype.foo1b = function() {\n\tvar self = this;\n\treturn org.apache.flex.A.base(this, 'foo1b');\n};\n\n/**\n * @param {Object} value\n */\norg.apache.flex.A.prototype.foo2 = function(value) {\n};\n\n/**\n * @param {Object} value\n */\norg.apache.flex.A.prototype.foo3 = function(value) {\n};\n\n/**\n * @param {Object} value\n */\norg.apache.flex.A.prototype.foo5 = function(value) {\n};\n\n/**\n * @param {Object} value\n */\norg.apache.flex.A.prototype.foo6 = function(value) {\n};\n\n/**\n * @param {Object} value\n */\norg.apache.flex.A.foo7 = function(value) {\n};\n\n/**\n * @param {Object} va
lue\n */\norg.apache.flex.A.foo7 = function(value) {\n};");
+ }
+
+ @Override
+ protected IClassNode getClassNode(String code)
+ {
+ String source = "package org.apache.flex {import flash.events.IEventDispatcher;import goog.events.EventTarget;import goog.events.Event;import goog.events.ListenableKey;"
+ + code + "}";
+ IFileNode node = compileAS(source);
+ IClassNode child = (IClassNode) findFirstDescendantOfType(node,
+ IClassNode.class);
+ return child;
+ }
+
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogEmiter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogEmiter.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogEmiter.java
new file mode 100644
index 0000000..21a9c90
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogEmiter.java
@@ -0,0 +1,153 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of 'goog' JavaScript output.
+ * <p>
+ * Note; this is a complete prototype more used in figuring out where
+ * abstraction and indirection is needed concerning the AS -> JS translations.
+ *
+ * @author Michael Schmalle
+ */
+public class TestGoogEmiter extends ASTestBase
+{
+
+ @Test
+ public void testSimple()
+ {
+ String code = "package com.example.components {"
+ + "import goog.events.EventTarget;"
+ + "public class MyEventTarget extends EventTarget {"
+ + "public function MyEventTarget() {if (foo() != 42) { bar(); } }"
+ + "private var _privateVar:String = \"do \";"
+ + "public var publicProperty:Number = 100;"
+ + "public function myFunction(value: String): String{"
+ + "return \"Don't \" + _privateVar + value; }";
+ IFileNode node = compileAS(code);
+ asBlockWalker.visitFile(node);
+ assertOut("goog.provide('com.example.components.MyEventTarget');\n\ngoog.require('goog.events.EventTarget');\n\n/**\n * @constructor\n * @extends {goog.events.EventTarget}\n */\ncom.example.components.MyEventTarget = function() {\n\tvar self = this;\n\tcom.example.components.MyEventTarget.base(this, 'constructor');\n\tif (foo() != 42) {\n\t\tbar();\n\t}\n};\ngoog.inherits(com.example.components.MyEventTarget, goog.events.EventTarget);\n\n/**\n * @private\n * @type {string}\n */\ncom.example.components.MyEventTarget.prototype._privateVar = \"do \";\n\n/**\n * @type {number}\n */\ncom.example.components.MyEventTarget.prototype.publicProperty = 100;\n\n/**\n * @param {string} value\n * @return {string}\n */\ncom.example.components.MyEventTarget.prototype.myFunction = function(value) {\n\tvar self = this;\n\treturn \"Don't \" + self._privateVar + value;\n};");
+ }
+
+ @Test
+ public void testSimpleInterface()
+ {
+ String code = "package com.example.components {"
+ + "public interface TestInterface { } }";
+ IFileNode node = compileAS(code);
+ asBlockWalker.visitFile(node);
+ assertOut("goog.provide('com.example.components.TestInterface');\n\n/**\n * @interface\n */\ncom.example.components.TestInterface = function() {\n};");
+ }
+
+ @Test
+ public void testSimpleClass()
+ {
+ String code = "package com.example.components {"
+ + "public class TestClass { } }";
+ IFileNode node = compileAS(code);
+ asBlockWalker.visitFile(node);
+ assertOut("goog.provide('com.example.components.TestClass');\n\n/**\n * @constructor\n */\ncom.example.components.TestClass = function() {\n};");
+ }
+
+ @Test
+ public void testSimpleMethod()
+ {
+ IFunctionNode node = getMethod("function method1():void{\n}");
+ asBlockWalker.visitFunction(node);
+ assertOut("FalconTest_A.prototype.method1 = function() {\n}");
+ }
+
+ @Test
+ public void testSimpleParameterReturnType()
+ {
+ IFunctionNode node = getMethodWithPackage("function method1(bar:int):int{\n}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {number} bar\n * @return {number}\n */\n"
+ + "foo.bar.FalconTest_A.prototype.method1 = function(bar) {\n}");
+ }
+
+ @Test
+ public void testSimpleMultipleParameter()
+ {
+ IFunctionNode node = getMethodWithPackage("function method1(bar:int, baz:String, goo:Array):void{\n}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {number} bar\n * @param {string} baz\n * @param {Array} goo\n */\n"
+ + "foo.bar.FalconTest_A.prototype.method1 = function(bar, baz, goo) {\n}");
+ }
+
+ @Test
+ public void testSimpleMultipleParameter_JSDoc()
+ {
+ IFunctionNode node = getMethodWithPackage("function method1(bar:int, baz:String, goo:Array):void{\n}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {number} bar\n * @param {string} baz\n * @param {Array} goo\n */\n"
+ + "foo.bar.FalconTest_A.prototype.method1 = function(bar, baz, goo) {\n}");
+ }
+
+ @Test
+ public void testDefaultParameter()
+ {
+ IFunctionNode node = getMethodWithPackage("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{return p1 + p2 + p3 + p4;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {number} p1\n * @param {number} p2\n * @param {number=} p3\n * @param {number=} p4\n * @return {number}\n */\n"
+ + "foo.bar.FalconTest_A.prototype.method1 = function(p1, p2, p3, p4) {\n"
+ + "\tvar self = this;\n"
+ + "\tp3 = typeof p3 !== 'undefined' ? p3 : 3;\n"
+ + "\tp4 = typeof p4 !== 'undefined' ? p4 : 4;\n"
+ + "\treturn p1 + p2 + p3 + p4;\n}");
+ }
+
+ @Test
+ public void testDefaultParameter_Body()
+ {
+ IFunctionNode node = getMethodWithPackage("function method1(bar:int = 42, bax:int = 4):void{if (a) foo();}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {number=} bar\n * @param {number=} bax\n */\n"
+ + "foo.bar.FalconTest_A.prototype.method1 = function(bar, bax) {\n"
+ + "\tvar self = this;\n"
+ + "\tbar = typeof bar !== 'undefined' ? bar : 42;\n"
+ + "\tbax = typeof bax !== 'undefined' ? bax : 4;\n"
+ + "\tif (a)\n\t\tfoo();\n}");
+ }
+
+ @Test
+ public void testDefaultParameter_NoBody()
+ {
+ IFunctionNode node = getMethodWithPackage("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {number} p1\n * @param {number} p2\n * @param {number=} p3\n * @param {number=} p4\n * @return {number}\n */\n"
+ + "foo.bar.FalconTest_A.prototype.method1 = function(p1, p2, p3, p4) {\n"
+ + "\tp3 = typeof p3 !== 'undefined' ? p3 : 3;\n"
+ + "\tp4 = typeof p4 !== 'undefined' ? p4 : 4;\n}");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogExpressions.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogExpressions.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogExpressions.java
new file mode 100644
index 0000000..df0c1cc
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogExpressions.java
@@ -0,0 +1,195 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestExpressions;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.INamespaceAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * @author Michael Schmalle
+ * @author Erik de Bruin
+ */
+public class TestGoogExpressions extends TestExpressions
+{
+ @Override
+ @Test
+ public void testVisitLanguageIdentifierNode_SuperMethod_1()
+ {
+ IFunctionNode node = getMethod("function foo(){if (a) super.foo();}");
+ asBlockWalker.visitFunction(node);
+ assertOut("FalconTest_A.prototype.foo = function() {\n\tvar self = this;\n\tif (a)\n\t\tFalconTest_A.base(this, 'foo');\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitLanguageIdentifierNode_SuperMethod_2()
+ {
+ IFunctionNode node = getMethod("function foo(){if (a) super.foo(a, b, c);}");
+ asBlockWalker.visitFunction(node);
+ assertOut("FalconTest_A.prototype.foo = function() {\n\tvar self = this;\n\tif (a)\n\t\tFalconTest_A.base(this, 'foo', a, b, c);\n}");
+ }
+
+ //----------------------------------
+ // Primary expression keywords
+ //----------------------------------
+
+ //----------------------------------
+ // Logical
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalAndAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a &&= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a = a && b");
+ }
+
+ @Override
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalOrAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ||= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a = a || b");
+ }
+
+ //----------------------------------
+ // Other
+ //----------------------------------
+
+ @Test
+ public void testParentheses_1()
+ {
+ IVariableNode node = (IVariableNode) getNode("var a = (a + b);",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {*} */ a = (a + b)");
+ }
+
+ @Test
+ public void testParentheses_2()
+ {
+ IVariableNode node = (IVariableNode) getNode("var a = (a + b) - c;",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {*} */ 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 /** @type {*} */ a = ((a + b) - (c + d)) * e");
+ }
+
+ @Override
+ @Test
+ public void testAnonymousFunction()
+ {
+ IVariableNode node = (IVariableNode) getNode("var a = function(){};",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {*} */ a = function() {\n}");
+ }
+
+ @Override
+ @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 /** @type {Object} */ a = function(foo, bar) {\n\tbar = typeof bar !== 'undefined' ? bar : 'goo';\n\treturn -1;\n}");
+ }
+
+ @Override
+ @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) {\n\tdoit();\n})");
+ }
+
+ @Override
+ @Test
+ public void testVisitAs()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a as b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("(is(a, b) ? a : null)");
+ }
+
+ @Override
+ @Test
+ public void testVisitBinaryOperator_Instancof()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a instanceof b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a instanceof b");
+ }
+
+ @Override
+ @Test
+ public void testVisitBinaryOperator_Is()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a is b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("is(a, b)");
+ }
+
+ @Override
+ @Test
+ public void testVisitBinaryOperator_NamespaceAccess_1()
+ {
+ INamespaceAccessExpressionNode node = getNamespaceAccessExpressionNode("a::b");
+ asBlockWalker.visitNamespaceAccessExpression(node);
+ assertOut("a.b");
+ }
+
+ @Override
+ @Test
+ public void testVisitBinaryOperator_NamespaceAccess_2()
+ {
+ INamespaceAccessExpressionNode node = getNamespaceAccessExpressionNode("a::b::c");
+ asBlockWalker.visitNamespaceAccessExpression(node);
+ assertOut("a.b.c");
+ }
+
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogFieldMembers.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogFieldMembers.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogFieldMembers.java
new file mode 100644
index 0000000..e4ead99
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogFieldMembers.java
@@ -0,0 +1,261 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestFieldMembers;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of 'goog' JavaScript for Class Field members.
+ *
+ * @author Michael Schmalle
+ * @author Erik de Bruin
+ */
+public class TestGoogFieldMembers extends TestFieldMembers
+{
+ //--------------------------------------------------------------------------
+ // Fields
+ //--------------------------------------------------------------------------
+
+ @Override
+ @Test
+ public void testField()
+ {
+ IVariableNode node = getField("var foo;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @type {*}\n */\nFalconTest_A.prototype.foo");
+ }
+
+ @Override
+ @Test
+ public void testField_withType()
+ {
+ IVariableNode node = getField("var foo:int;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @type {number}\n */\nFalconTest_A.prototype.foo");
+ }
+
+ @Override
+ @Test
+ public void testField_withTypeValue()
+ {
+ IVariableNode node = getField("var foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @type {number}\n */\nFalconTest_A.prototype.foo = 420");
+ }
+
+ @Test
+ public void testField_withTypeValue_Negative()
+ {
+ IVariableNode node = getField("var foo:int = -420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @type {number}\n */\nFalconTest_A.prototype.foo = -420");
+ }
+
+ @Override
+ @Test
+ public void testField_withNamespaceTypeValue()
+ {
+ IVariableNode node = getField("private var foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @private\n * @type {number}\n */\nFalconTest_A.prototype.foo = 420");
+ }
+
+ @Override
+ @Test
+ public void testField_withCustomNamespaceTypeValue()
+ {
+ IVariableNode node = getField("mx_internal var foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ // (erikdebruin) we ignore custom namespaces completely (are there side effects I'm missing?)
+ assertOut("/**\n * @type {number}\n */\nFalconTest_A.prototype.foo = 420");
+ }
+
+ @Override
+ @Test
+ public void testField_withNamespaceTypeCollection()
+ {
+ IVariableNode node = getField("protected var foo:Vector.<Foo>;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @protected\n * @type {Vector.<Foo>}\n */\nFalconTest_A.prototype.foo");
+ }
+
+ @Override
+ @Test
+ public void testField_withNamespaceTypeCollectionComplex()
+ {
+ IVariableNode node = getField("protected var foo:Vector.<Vector.<Vector.<Foo>>>;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @protected\n * @type {Vector.<Vector.<Vector.<Foo>>>}\n */\nFalconTest_A.prototype.foo");
+ }
+
+ @Override
+ @Test
+ public void testField_withNamespaceTypeValueComplex()
+ {
+ IVariableNode node = getField("protected var foo:Foo = new Foo('bar', 42);");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @protected\n * @type {Foo}\n */\nFalconTest_A.prototype.foo = new Foo('bar', 42)");
+ }
+
+ @Override
+ @Test
+ public void testField_withList()
+ {
+ IVariableNode node = getField("protected var a:int = 4, b:int = 11, c:int = 42;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @protected\n * @type {number}\n */\nFalconTest_A.prototype.a = 4;\n\n/**\n * @protected\n * @type {number}\n */\nFalconTest_A.prototype.b = 11;\n\n/**\n * @protected\n * @type {number}\n */\nFalconTest_A.prototype.c = 42");
+ }
+
+ //--------------------------------------------------------------------------
+ // Constants
+ //--------------------------------------------------------------------------
+
+ @Override
+ @Test
+ public void testConstant()
+ {
+ IVariableNode node = getField("static const foo;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @const\n * @type {*}\n */\nFalconTest_A.foo");
+ }
+
+ @Test
+ public void testConstant_nonStatic()
+ {
+ IVariableNode node = getField("const foo;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @const\n * @type {*}\n */\nFalconTest_A.prototype.foo");
+ }
+
+ @Override
+ @Test
+ public void testConstant_withType()
+ {
+ IVariableNode node = getField("static const foo:int;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @const\n * @type {number}\n */\nFalconTest_A.foo");
+ }
+
+ @Test
+ public void testConstant_withType_nonStatic()
+ {
+ IVariableNode node = getField("const foo:int;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @const\n * @type {number}\n */\nFalconTest_A.prototype.foo");
+ }
+
+ @Override
+ @Test
+ public void testConstant_withTypeValue()
+ {
+ IVariableNode node = getField("static const foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @const\n * @type {number}\n */\nFalconTest_A.foo = 420");
+ }
+
+ @Test
+ public void testConstant_withTypeValue_nonStatic()
+ {
+ IVariableNode node = getField("const foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @const\n * @type {number}\n */\nFalconTest_A.prototype.foo = 420");
+ }
+
+ @Override
+ @Test
+ public void testConstant_withNamespaceTypeValue()
+ {
+ IVariableNode node = getField("private static const foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @private\n * @const\n * @type {number}\n */\nFalconTest_A.foo = 420");
+ }
+
+ @Test
+ public void testConstant_withNamespaceTypeValue_nonStatic()
+ {
+ IVariableNode node = getField("private const foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @private\n * @const\n * @type {number}\n */\nFalconTest_A.prototype.foo = 420");
+ }
+
+ @Override
+ @Test
+ public void testConstant_withCustomNamespaceTypeValue()
+ {
+ IVariableNode node = getField("mx_internal static const foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ // (erikdebruin) we ignore custom namespaces completely (are there side effects I'm missing?)
+ assertOut("/**\n * @const\n * @type {number}\n */\nFalconTest_A.foo = 420");
+ }
+
+ @Test
+ public void testConstant_withCustomNamespaceTypeValue_nonStatic()
+ {
+ IVariableNode node = getField("mx_internal const foo:int = 420;");
+ asBlockWalker.visitVariable(node);
+ // (erikdebruin) we ignore custom namespaces completely (are there side effects I'm missing?)
+ assertOut("/**\n * @const\n * @type {number}\n */\nFalconTest_A.prototype.foo = 420");
+ }
+
+ //--------------------------------------------------------------------------
+ // Namespace
+ //--------------------------------------------------------------------------
+
+ // TODO (erikdebruin) not sure what to do with these when emitting JS...
+
+ @Override
+ @Test
+ public void testNamespace()
+ {
+// INamespaceNode node = getNamespace("namespace ns = \"http://whatever\";");
+// asBlockWalker.visitNamespace(node);
+// assertOut("namespace ns = \"http://whatever\"");
+ }
+
+ @Override
+ @Test
+ public void testNamespace_public()
+ {
+// INamespaceNode node = getNamespace("public namespace ns = \"http://whatever\";");
+// asBlockWalker.visitNamespace(node);
+// assertOut("public namespace ns = \"http://whatever\"");
+ }
+
+ @Override
+ @Test
+ public void testNamespace_protected()
+ {
+// INamespaceNode node = getNamespace("protected namespace ns = \"http://whatever\";");
+// asBlockWalker.visitNamespace(node);
+// assertOut("protected namespace ns = \"http://whatever\"");
+ }
+
+ //--------------------------------------------------------------------------
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogFile.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogFile.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogFile.java
new file mode 100644
index 0000000..dcfacb2
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogFile.java
@@ -0,0 +1,93 @@
+/*
+ *
+ * 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.js.goog;
+
+import java.io.File;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+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 'goog' JS code from an external
+ * file.
+ *
+ * @author Erik de Bruin
+ */
+public class TestGoogFile extends ASTestBase
+{
+ @Test
+ public void testFile_plain()
+ {
+ IFileNode node = compileAS("input", true, "goog" + File.separator
+ + "files");
+ asBlockWalker.visitFile(node);
+ assertOut(getCodeFromFile("output", true, "goog" + File.separator
+ + "files"));
+ }
+
+ @Test
+ public void testFile_getset()
+ {
+ IFileNode node = compileAS("get-set", true, "goog" + File.separator
+ + "files");
+ asBlockWalker.visitFile(node);
+ assertOut(getCodeFromFile("get-set_result", true, "goog"
+ + File.separator + "files"));
+ }
+
+ @Test
+ public void testFile_callsuper()
+ {
+ IFileNode node = compileAS("call-super", true, "goog" + File.separator
+ + "files");
+ asBlockWalker.visitFile(node);
+ assertOut(getCodeFromFile("call-super_result", true, "goog"
+ + File.separator + "files"));
+ }
+
+ @Test
+ public void testFile_qualifynewobject()
+ {
+ IFileNode node = compileAS("qualify-new-object", true, "goog"
+ + File.separator + "files");
+ asBlockWalker.visitFile(node);
+ assertOut(getCodeFromFile("qualify-new-object_result", true, "goog"
+ + File.separator + "files"));
+ }
+
+ @Test
+ public void testFile_poc()
+ {
+ IFileNode node = compileAS("poc", true, "goog" + File.separator
+ + "files");
+ asBlockWalker.visitFile(node);
+ assertOut(getCodeFromFile("poc_result", true, "goog" + File.separator
+ + "files"));
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalClasses.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalClasses.java
new file mode 100644
index 0000000..fc9e523
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalClasses.java
@@ -0,0 +1,309 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestGlobalClasses;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+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 TestGoogGlobalClasses extends TestGlobalClasses
+{
+ @Override
+ @Test
+ public void testArgumentError()
+ {
+ IVariableNode node = getVariable("var a:ArgumentError = new ArgumentError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {ArgumentError} */ a = new ArgumentError()");
+ }
+
+ @Override
+ @Test
+ public void testArguments()
+ {
+ IFunctionNode node = getMethod("function a():void {\ttrace(arguments);}");
+ asBlockWalker.visitFunction(node);
+ assertOut("FalconTest_A.prototype.a = function() {\n\tvar self = this;\n\ttrace(arguments);\n}");
+ }
+
+ @Override
+ @Test
+ public void testArray()
+ {
+ IVariableNode node = getVariable("var a:Array = new Array(1);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Array} */ a = new Array(1)");
+ }
+
+ @Override
+ @Test
+ public void testBoolean()
+ {
+ IVariableNode node = getVariable("var a:Boolean = new Boolean(1);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {boolean} */ a = new Boolean(1)");
+ }
+
+ @Override
+ @Test
+ public void testClass()
+ {
+ IVariableNode node = getVariable("var a:Class = new Class();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Object} */ a = new Class()");
+ }
+
+ @Override
+ @Test
+ public void testDate()
+ {
+ IVariableNode node = getVariable("var a:Date = new Date();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Date} */ a = new Date()");
+ }
+
+ @Override
+ @Test
+ public void testDefinitionError()
+ {
+ IVariableNode node = getVariable("var a:DefinitionError = new DefinitionError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {DefinitionError} */ a = new DefinitionError()");
+ }
+
+ @Override
+ @Test
+ public void testError()
+ {
+ IVariableNode node = getVariable("var a:Error = new Error();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Error} */ a = new Error()");
+ }
+
+ @Override
+ @Test
+ public void testEvalError()
+ {
+ IVariableNode node = getVariable("var a:EvalError = new EvalError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {EvalError} */ a = new EvalError()");
+ }
+
+ @Override
+ @Test
+ public void testFunction()
+ {
+ IVariableNode node = getVariable("var a:Function = new Function();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Function} */ a = new Function()");
+ }
+
+ @Override
+ @Test
+ public void testInt()
+ {
+ IVariableNode node = getVariable("var a:int = new int(1.8);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = new int(1.8)");
+ }
+
+ @Override
+ @Test
+ public void testJSON()
+ {
+ IVariableNode node = getVariable("var a:JSON = new JSON();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {JSON} */ a = new JSON()");
+ }
+
+ @Override
+ @Test
+ public void testMath()
+ {
+ IVariableNode node = getVariable("var a:Number = Math.PI;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = Math.PI");
+ }
+
+ @Override
+ @Test
+ public void testNamespace()
+ {
+ IVariableNode node = getVariable("var a:Namespace = new Namespace(\"http://example.com\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Namespace} */ a = new Namespace(\"http://example.com\")");
+ }
+
+ @Override
+ @Test
+ public void testNumber()
+ {
+ IVariableNode node = getVariable("var a:Number = new Number(\"1\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = new Number(\"1\")");
+ }
+
+ @Override
+ @Test
+ public void testObject()
+ {
+ IVariableNode node = getVariable("var a:Object = new Object();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Object} */ a = new Object()");
+ }
+
+ @Override
+ @Test
+ public void testQName()
+ {
+ IVariableNode node = getVariable("var a:QName = new QName();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {QName} */ a = new QName()");
+ }
+
+ @Override
+ @Test
+ public void testRangeError()
+ {
+ IVariableNode node = getVariable("var a:RangeError = new RangeError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {RangeError} */ a = new RangeError()");
+ }
+
+ @Override
+ @Test
+ public void testReferenceError()
+ {
+ IVariableNode node = getVariable("var a:ReferenceError = new ReferenceError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {ReferenceError} */ a = new ReferenceError()");
+ }
+
+ @Override
+ @Test
+ public void testRegExp_Literal()
+ {
+ IVariableNode node = getVariable("var a:RegExp = /test-\\d/i;");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {RegExp} */ a = /test-\\d/i");
+ }
+
+ @Override
+ @Test
+ public void testSecurityError()
+ {
+ IVariableNode node = getVariable("var a:SecurityError = new SecurityError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {SecurityError} */ a = new SecurityError()");
+ }
+
+ @Override
+ @Test
+ public void testString()
+ {
+ IVariableNode node = getVariable("var a:String = new String(\"100\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {string} */ a = new String(\"100\")");
+ }
+
+ @Override
+ @Test
+ public void testSyntaxError()
+ {
+ IVariableNode node = getVariable("var a:SyntaxError = new SyntaxError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {SyntaxError} */ a = new SyntaxError()");
+ }
+
+ @Override
+ @Test
+ public void testTypeError()
+ {
+ IVariableNode node = getVariable("var a:TypeError = new TypeError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {TypeError} */ a = new TypeError()");
+ }
+
+ @Override
+ @Test
+ public void testUint()
+ {
+ IVariableNode node = getVariable("var a:uint = new uint(-100);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = new uint(-100)");
+ }
+
+ @Override
+ @Test
+ public void testURIError()
+ {
+ IVariableNode node = getVariable("var a:URIError = new URIError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {URIError} */ a = new URIError()");
+ }
+
+ @Override
+ @Test
+ public void testVector()
+ {
+ IVariableNode node = getVariable("var a:Vector.<String> = new Vector.<String>(['Hello', 'World']);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Vector.<string>} */ a = new Array(['Hello', 'World'])");
+ }
+
+ @Override
+ @Test
+ public void testVerifyError()
+ {
+ IVariableNode node = getVariable("var a:VerifyError = new VerifyError();");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {VerifyError} */ a = new VerifyError()");
+ }
+
+ @Override
+ @Test
+ public void testXML()
+ {
+ IVariableNode node = getVariable("var a:XML = new XML('@');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {XML} */ a = new XML('@')");
+ }
+
+ @Override
+ @Test
+ public void testXMLList()
+ {
+ IVariableNode node = getVariable("var a:XMLList = new XMLList('<!-- comment -->');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {XMLList} */ a = new XMLList('<!-- comment -->')");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalConstants.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalConstants.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalConstants.java
new file mode 100644
index 0000000..4bb2186
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalConstants.java
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestGlobalConstants;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestGoogGlobalConstants extends TestGlobalConstants
+{
+ @Override
+ @Test
+ public void testInfinity()
+ {
+ IVariableNode node = getField("var a:Number = Infinity;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @type {number}\n */\nFalconTest_A.prototype.a = Infinity");
+ }
+
+ @Override
+ @Test
+ public void testNegativeInfinity()
+ {
+ IVariableNode node = getField("var a:Number = -Infinity;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @type {number}\n */\nFalconTest_A.prototype.a = -Infinity");
+ }
+
+ @Override
+ @Test
+ public void testNaN()
+ {
+ IVariableNode node = getField("var a:Number = NaN;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @type {number}\n */\nFalconTest_A.prototype.a = NaN");
+ }
+
+ @Override
+ @Test
+ public void testUndefined()
+ {
+ IVariableNode node = getField("var a:* = undefined;");
+ asBlockWalker.visitVariable(node);
+ assertOut("/**\n * @type {*}\n */\nFalconTest_A.prototype.a = undefined");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalFunctions.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalFunctions.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalFunctions.java
new file mode 100644
index 0000000..614edd5
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogGlobalFunctions.java
@@ -0,0 +1,238 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestGlobalFunctions;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+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 TestGoogGlobalFunctions extends TestGlobalFunctions
+{
+ @Override
+ @Test
+ public void testArray()
+ {
+ IVariableNode node = getVariable("var a:Array = Array(1);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Array} */ a = Array(1)");
+ }
+
+ @Override
+ @Test
+ public void testBoolean()
+ {
+ IVariableNode node = getVariable("var a:Boolean = Boolean(1);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {boolean} */ a = Boolean(1)");
+ }
+
+ @Override
+ @Test
+ public void testDecodeURI()
+ {
+ IVariableNode node = getVariable("var a:String = decodeURI('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {string} */ a = decodeURI('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testDecodeURIComponent()
+ {
+ IVariableNode node = getVariable("var a:String = decodeURIComponent('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {string} */ a = decodeURIComponent('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testEncodeURI()
+ {
+ IVariableNode node = getVariable("var a:String = encodeURI('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {string} */ a = encodeURI('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testEncodeURIComponent()
+ {
+ IVariableNode node = getVariable("var a:String = encodeURIComponent('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {string} */ a = encodeURIComponent('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testEscape()
+ {
+ IVariableNode node = getVariable("var a:String = escape('http://whatever.com');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {string} */ a = escape('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testInt()
+ {
+ IVariableNode node = getVariable("var a:int = int(1.8);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = int(1.8)");
+ }
+
+ @Override
+ @Test
+ public void testIsFinite()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isFinite(1000000.9);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {boolean} */ a = isFinite(1000000.9)");
+ }
+
+ @Override
+ @Test
+ public void testIsNaN()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isNaN(NaN);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {boolean} */ a = isNaN(NaN)");
+ }
+
+ @Override
+ @Test
+ public void testIsXMLName()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isXMLName(\"?\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {boolean} */ a = isXMLName(\"?\")");
+ }
+
+ @Override
+ @Test
+ public void testNumber()
+ {
+ IVariableNode node = getVariable("var a:Number = Number(\"1\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = Number(\"1\")");
+ }
+
+ @Override
+ @Test
+ public void testObject()
+ {
+ IVariableNode node = getVariable("var a:Object = Object(\"1\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Object} */ a = Object(\"1\")");
+ }
+
+ @Override
+ @Test
+ public void testParseFloat()
+ {
+ IVariableNode node = getVariable("var a:Number = parseFloat(\"1.8\");");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = parseFloat(\"1.8\")");
+ }
+
+ @Override
+ @Test
+ public void testParseInt()
+ {
+ IVariableNode node = getVariable("var a:Number = parseInt(\"666\", 10);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = parseInt(\"666\", 10)");
+ }
+
+ @Override
+ @Test
+ public void testString()
+ {
+ IVariableNode node = getVariable("var a:String = String(100);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {string} */ a = String(100)");
+ }
+
+ @Override
+ @Test
+ public void testTrace()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode(
+ "trace('Hello World');", IFunctionCallNode.class);
+ asBlockWalker.visitFunctionCall(node);
+ assertOut("trace('Hello World')");
+ }
+
+ @Override
+ @Test
+ public void testUint()
+ {
+ IVariableNode node = getVariable("var a:uint = uint(-100);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = uint(-100)");
+ }
+
+ @Override
+ @Test
+ public void testUnescape()
+ {
+ IVariableNode node = getVariable("var a:String = unescape('%25');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {string} */ a = unescape('%25')");
+ }
+
+ @Override
+ @Test
+ public void testVector()
+ {
+ IVariableNode node = getVariable("var a:Vector.<String> = Vector.<String>(['Hello', 'World']);");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Vector.<string>} */ a = Array(['Hello', 'World'])");
+ }
+
+ @Override
+ @Test
+ public void testXML()
+ {
+ IVariableNode node = getVariable("var a:XML = XML('@');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {XML} */ a = XML('@')");
+ }
+
+ @Override
+ @Test
+ public void testXMLList()
+ {
+ IVariableNode node = getVariable("var a:XMLList = XMLList('<!-- comment -->');");
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {XMLList} */ a = XMLList('<!-- comment -->')");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogInterface.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogInterface.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogInterface.java
new file mode 100644
index 0000000..460515a
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogInterface.java
@@ -0,0 +1,113 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestInterface;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid 'goog' JS code for Interface
+ * production.
+ *
+ * @author Michael Schmalle
+ * @author Erik de Bruin
+ */
+public class TestGoogInterface extends TestInterface
+{
+ @Override
+ @Test
+ public void testSimple()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA{}");
+ asBlockWalker.visitInterface(node);
+ assertOut("/**\n * @interface\n */\nIA = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleExtends()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA extends IB{}");
+ asBlockWalker.visitInterface(node);
+ assertOut("/**\n * @interface\n * @extends {IB}\n */\nIA = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleExtendsMultiple()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA extends IB, IC, ID {}");
+ asBlockWalker.visitInterface(node);
+ assertOut("/**\n * @interface\n * @extends {IB}\n * @extends {IC}\n * @extends {ID}\n */\nIA = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testQualifiedExtendsMultiple()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA extends foo.bar.IB, baz.goo.IC, foo.ID {}");
+ asBlockWalker.visitInterface(node);
+ assertOut("/**\n * @interface\n * @extends {foo.bar.IB}\n * @extends {baz.goo.IC}\n * @extends {foo.ID}\n */\nIA = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testAccessors()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA {"
+ + "function get foo1():Object;"
+ + "function set foo1(value:Object):void;}");
+ asBlockWalker.visitInterface(node);
+ assertOut("/**\n * @interface\n */\nIA = function() {\n};\nIA.prototype.foo1;");
+ }
+
+ @Override
+ @Test
+ public void testMethods()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA {"
+ + "function baz1():Object;"
+ + "function baz2(value:Object):void;}");
+ asBlockWalker.visitInterface(node);
+ assertOut("/**\n * @interface\n */\nIA = function() {\n};\nIA.prototype.baz1 = function() {\n};\nIA.prototype.baz2 = function(value) {\n};");
+ }
+
+ @Override
+ @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("/**\n * @interface\n */\nIA = function() {\n};\nIA.prototype.foo1;\nIA.prototype.baz1 = function() {\n};\nIA.prototype.baz2 = function(value) {\n};");
+ }
+
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogMethodMembers.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogMethodMembers.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogMethodMembers.java
new file mode 100644
index 0000000..95234ea
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogMethodMembers.java
@@ -0,0 +1,183 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestMethodMembers;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of 'goog'-ified JS code for Class Method
+ * members.
+ *
+ * @author Michael Schmalle
+ * @author Erik de Bruin
+ */
+public class TestGoogMethodMembers extends TestMethodMembers
+{
+ @Override
+ @Test
+ public void testMethod()
+ {
+ IFunctionNode node = getMethod("function foo(){}");
+ asBlockWalker.visitFunction(node);
+ assertOut("FalconTest_A.prototype.foo = function() {\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withReturnType()
+ {
+ IFunctionNode node = getMethod("function foo():int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @return {number}\n */\nFalconTest_A.prototype.foo = function() {\n\tvar self = this;\n\treturn -1;\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withParameterReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {*} bar\n * @return {number}\n */\nFalconTest_A.prototype.foo = function(bar) {\n\tvar self = this;\n\treturn -1;\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {string} bar\n * @return {number}\n */\nFalconTest_A.prototype.foo = function(bar) {\n\tvar self = this;\n\treturn -1;\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withDefaultParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String = \"baz\"):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {string=} bar\n * @return {number}\n */\nFalconTest_A.prototype.foo = function(bar) {\n\tvar self = this;\n\tbar = typeof bar !== 'undefined' ? bar : \"baz\";\n\treturn -1;\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withMultipleDefaultParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n */\nFalconTest_A.prototype.foo = function(bar, baz) {\n\tvar self = this;\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withRestParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String, ...rest):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {string} bar\n * @param {...} rest\n * @return {number}\n */\nFalconTest_A.prototype.foo = function(bar, rest) {\n\tvar self = this;\n\trest = Array.prototype.slice.call(arguments, 1);\n\treturn -1;\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withNamespace()
+ {
+ IFunctionNode node = getMethod("public function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ // we ignore the 'public' namespace completely
+ assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n */\nFalconTest_A.prototype.foo = function(bar, baz) {\n\tvar self = this;\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withNamespaceCustom()
+ {
+ IFunctionNode node = getMethod("mx_internal function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n */\nFalconTest_A.prototype.foo = function(bar, baz) {\n\tvar self = this;\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withNamespaceModifiers()
+ {
+ IFunctionNode node = getMethod("public static function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ // (erikdebruin) here we actually DO want to declare the method
+ // directly on the 'class' constructor instead of the
+ // prototype!
+ assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n */\nFalconTest_A.foo = function(bar, baz) {\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withNamespaceModifierOverride()
+ {
+ IFunctionNode node = getMethod("public override function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n * @override\n */\nFalconTest_A.prototype.foo = function(bar, baz) {\n\tvar self = this;\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
+ }
+
+ @Override
+ @Test
+ public void testMethod_withNamespaceModifierOverrideBackwards()
+ {
+ IFunctionNode node = getMethod("override public function foo(bar:String, baz:int = null):int{return -1;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n * @override\n */\nFalconTest_A.prototype.foo = function(bar, baz) {\n\tvar self = this;\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
+ }
+
+ //--------------------------------------------------------------------------
+ // Doc Specific Tests
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testConstructor_withThisInBody()
+ {
+ IClassNode node = (IClassNode) getNode("public function FalconTest_A() {this.foo;}", IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\tvar self = this;\n\tthis.foo;\n};");
+ }
+
+ @Test
+ public void testMethod_withThisInBody()
+ {
+ IFunctionNode node = getMethod("function foo(){this.foo;}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @this {FalconTest_A}\n */\nFalconTest_A.prototype.foo = function() {\n\tvar self = this;\n\tthis.foo;\n}");
+ }
+
+ @Test
+ public void testMethod_withThisInBodyComplex()
+ {
+ IFunctionNode node = getMethod("function foo(){if(true){while(i){this.bar(42);}}}");
+ asBlockWalker.visitFunction(node);
+ assertOut("/**\n * @this {FalconTest_A}\n */\nFalconTest_A.prototype.foo = function() {\n\tvar self = this;\n\tif (true) "
+ + "{\n\t\twhile (i) {\n\t\t\tthis.bar(42);\n\t\t}\n\t}\n}");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogPackage.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogPackage.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogPackage.java
new file mode 100644
index 0000000..51c4ef2
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogPackage.java
@@ -0,0 +1,112 @@
+/*
+ *
+ * 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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestPackage;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of 'goog' JavaScript for AS package.
+ *
+ * @author Michael Schmalle
+ * @author Erik de Bruin
+ */
+public class TestGoogPackage extends TestPackage
+{
+ @Override
+ @Test
+ public void testPackage_Simple()
+ {
+ IFileNode node = compileAS("package{}");
+ asBlockWalker.visitFile(node);
+ assertOut("");
+ }
+
+ @Test
+ public void testPackage_SimpleName()
+ {
+ IFileNode node = compileAS("package foo {}");
+ asBlockWalker.visitFile(node);
+ assertOut("");
+ }
+
+ @Override
+ @Test
+ public void testPackage_Name()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {}");
+ asBlockWalker.visitFile(node);
+ assertOut("");
+ }
+
+ @Override
+ @Test
+ public void testPackageSimple_Class()
+ {
+ // does JS need a implicit constructor function? ... always?
+ // All class nodes in AST get either an implicit or explicit constructor
+ // this is an implicit and the way I have the before/after handler working
+ // with block disallows implicit blocks from getting { }
+
+ // (erikdebruin) the constuctor IS the class definition, in 'goog' JS,
+ // therefor we need to write out implicit constructors
+ // (if I understand the term correctly)
+
+ IFileNode node = compileAS("package {public class A{}}");
+ asBlockWalker.visitFile(node);
+ assertOut("goog.provide('A');\n\n/**\n * @constructor\n */\nA = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testPackageQualified_Class()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {public class A{}}");
+ asBlockWalker.visitFile(node);
+ assertOut("goog.provide('foo.bar.baz.A');\n\n/**\n * @constructor\n */\nfoo.bar.baz.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testPackageQualified_ClassBody()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {public class A{public function A(){}}}");
+ asBlockWalker.visitFile(node);
+ assertOut("goog.provide('foo.bar.baz.A');\n\n/**\n * @constructor\n */\nfoo.bar.baz.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testPackageQualified_ClassBodyMethodContents()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {public class A{public function A(){if (a){for (var i:Object in obj){doit();}}}}}");
+ asBlockWalker.visitFile(node);
+ assertOut("goog.provide('foo.bar.baz.A');\n\n/**\n * @constructor\n */\nfoo.bar.baz.A = function() {\n\tvar self = this;\n\tif (a) {\n\t\tfor (var /** @type {Object} */ i in obj) {\n\t\t\tdoit();\n\t\t}\n\t}\n};");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogProject.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogProject.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogProject.java
new file mode 100644
index 0000000..a120ec0
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogProject.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.js.goog;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend;
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.utils.TestAdapterFactory;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * This class tests the production of valid 'goog' JS code from an external
+ * project.
+ *
+ * @author Erik de Bruin
+ */
+public class TestGoogProject extends ASTestBase
+{
+
+ private static String projectDirPath = "goog/projects";
+
+ @Test
+ public void test_imports()
+ {
+ String testDirPath = projectDirPath + "/imports";
+
+ String fileName = "Case";
+
+ List<String> compiledFileNames = compileProject(fileName, testDirPath);
+
+ assertProjectOut(compiledFileNames, testDirPath);
+ }
+
+ @Override
+ protected void addSourcePaths(List<File> sourcePaths)
+ {
+ sourcePaths.add(new File(TestAdapterFactory.getTestAdapter().getUnitTestBaseDir(),
+ projectDirPath + "/imports"));
+
+ super.addSourcePaths(sourcePaths);
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+
+ protected void assertProjectOut(List<String> compiledFileNames,
+ String testDirPath)
+ {
+ if (compiledFileNames.size() == 0)
+ {
+ fail("Expected compiled files");
+ }
+ for (String compiledFileName : compiledFileNames)
+ {
+ String compiledFilePath = tempDir.getAbsolutePath()
+ + File.separator + testDirPath + File.separator
+ + compiledFileName + "_output" + "."
+ + backend.getOutputExtension();
+ String compiledResult = readCodeFile(new File(compiledFilePath));
+
+ //System.out.println(compiledResult);
+
+ String expectedFilePath = new File(TestAdapterFactory.getTestAdapter().getUnitTestBaseDir(),
+ testDirPath + "/" + compiledFileName + "_result" + "." + backend.getOutputExtension()).getPath();
+ String expectedResult = readCodeFile(new File(expectedFilePath));
+
+ assertThat(compiledResult, is(expectedResult));
+ }
+ }
+
+}