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:12 UTC
[20/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/vf2js/TestVF2JSStatements.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/vf2js/TestVF2JSStatements.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/vf2js/TestVF2JSStatements.java
new file mode 100644
index 0000000..2d59b6a
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/vf2js/TestVF2JSStatements.java
@@ -0,0 +1,549 @@
+/*
+ *
+ * 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.vf2js;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.js.goog.TestGoogStatements;
+import org.apache.flex.compiler.internal.driver.js.vf2js.VF2JSBackend;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.tree.as.LabeledStatementNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IForLoopNode;
+import org.apache.flex.compiler.tree.as.IIfNode;
+import org.apache.flex.compiler.tree.as.ISwitchNode;
+import org.apache.flex.compiler.tree.as.ITryNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.apache.flex.compiler.tree.as.IWhileLoopNode;
+import org.apache.flex.compiler.tree.as.IWithNode;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestVF2JSStatements extends TestGoogStatements
+{
+ @Override
+ public void setUp()
+ {
+ project = new FlexJSProject(workspace);
+ super.setUp();
+ }
+
+ @Test
+ public void testVarDeclaration_withReservedWord()
+ {
+ IVariableNode node = (IVariableNode) getNode("var max:int = int.MAX_VALUE;",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ max = INT.MAX_VALUE");
+ }
+
+ @Test
+ public void testVarDeclaration_withTypeAssignedStringWithNewLine()
+ {
+ IVariableNode node = (IVariableNode) getNode("var a:String = \"\\n\"",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {string} */ a = \"\\n\"");
+ }
+
+ @Test
+ public void testVarDeclaration_withXMLList()
+ {
+ IVariableNode node = (IVariableNode) getNode(
+ "var childDesc:XMLList = typeDescription.accessor."
+ + "(@name == childName) + typeDescription.method."
+ + "(@name == childName);",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {XMLList} */ childDesc = 'E4XFilter' + 'E4XFilter'");
+ }
+
+ @Test
+ public void testVarDeclaration_withEmbed()
+ {
+ IVariableNode node = (IVariableNode) getNode(
+ "[Embed(source=\"LuminosityMaskFilter.pbj\", mimeType=\"application/octet-stream\")]\nprivate static var ShaderClass:Class;",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {Object} */ falconTest_a.ShaderClass");
+ }
+
+ //----------------------------------
+ // const declaration
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testConstDeclaration()
+ {
+ IVariableNode node = (IVariableNode) getNode("const a = 42;",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {*} */ a = 42");
+ // ToDo (erikdebruin): assertOut("const /** @type {*} */ a = 42");
+ }
+
+ @Override
+ @Test
+ public void testConstDeclaration_withType()
+ {
+ IVariableNode node = (IVariableNode) getNode("const a:int = 42;",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = 42");
+ // ToDo (erikdebruin): assertOut("const /** @type {number} */ a = 42");
+ }
+
+ @Override
+ @Test
+ public void testConstDeclaration_withList()
+ {
+ IVariableNode node = (IVariableNode) getNode(
+ "const a:int = 4, b:int = 11, c:int = 42;", IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("var /** @type {number} */ a = 4, /** @type {number} */ b = 11, /** @type {number} */ c = 42");
+ // ToDo (erikdebruin): assertOut("const /** @type {number} */ a = 4, /** @type {number} */ b = 11, /** @type {number} */ c = 42");
+ }
+
+ //----------------------------------
+ // for () { }
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitFor_1a()
+ {
+ IForLoopNode node = (IForLoopNode) getNode(
+ "for (var i:int = 0; i < len; i++) { break; }",
+ IForLoopNode.class);
+ asBlockWalker.visitForLoop(node);
+ assertOut("for (var /** @type {number} */ i = 0; i < len; i++) {\n break;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitFor_1b()
+ {
+ IForLoopNode node = (IForLoopNode) getNode(
+ "for (var i:int = 0; i < len; i++) break;", IForLoopNode.class);
+ asBlockWalker.visitForLoop(node);
+ assertOut("for (var /** @type {number} */ i = 0; i < len; i++)\n break;");
+ }
+
+ @Test
+ public void testVisitFor_1c()
+ {
+ IForLoopNode node = (IForLoopNode) getNode(
+ "for (var i:int = 0, j:int = 3; i < j; i++) break;", IForLoopNode.class);
+ asBlockWalker.visitForLoop(node);
+ assertOut("for (var /** @type {number} */ i = 0, /** @type {number} */ j = 3; i < j; i++)\n break;");
+ }
+
+ @Override
+ @Test
+ public void testVisitForIn_1()
+ {
+ IForLoopNode node = (IForLoopNode) getNode(
+ "for (var i:int in obj) { break; }", IForLoopNode.class);
+ asBlockWalker.visitForLoop(node);
+ assertOut("for (var /** @type {number} */ i in obj) {\n break;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitForIn_1a()
+ {
+ IForLoopNode node = (IForLoopNode) getNode(
+ "for (var i:int in obj) break; ", IForLoopNode.class);
+ asBlockWalker.visitForLoop(node);
+ assertOut("for (var /** @type {number} */ i in obj)\n break;");
+ }
+
+ @Override
+ @Test
+ public void testVisitForEach_1()
+ {
+ IForLoopNode node = (IForLoopNode) getNode(
+ "for each(var i:int in obj) { break; }", IForLoopNode.class);
+ asBlockWalker.visitForLoop(node);
+ assertOut("for (var foreachiter0 in obj) \n{\nvar i = obj[foreachiter0];\n{\n break;\n}}\n");
+ }
+
+ @Override
+ @Test
+ public void testVisitForEach_1a()
+ {
+ IForLoopNode node = (IForLoopNode) getNode(
+ "for each(var i:int in obj) break; ", IForLoopNode.class);
+ asBlockWalker.visitForLoop(node);
+ assertOut("for (var foreachiter0 in obj) \n{\nvar i = obj[foreachiter0];\n\n break;}\n");
+ }
+
+ @Test
+ public void testVisitForEach_HoistedVar()
+ {
+ IForLoopNode node = (IForLoopNode) getNode(
+ "var i:int; for each(i in obj) break; ", IForLoopNode.class);
+ asBlockWalker.visitForLoop(node);
+ assertOut("for (var foreachiter0 in obj) \n{\ni = obj[foreachiter0];\n\n break;}\n");
+ }
+
+ //----------------------------------
+ // try {} catch () {} finally {}
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitTry_Catch()
+ {
+ ITryNode node = (ITryNode) getNode("try { a; } catch (e:Error) { b; }",
+ ITryNode.class);
+ asBlockWalker.visitTry(node);
+ assertOut("try {\n a;\n} catch (e) {\n b;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitTry_Catch_Finally()
+ {
+ ITryNode node = (ITryNode) getNode(
+ "try { a; } catch (e:Error) { b; } finally { c; }",
+ ITryNode.class);
+ asBlockWalker.visitTry(node);
+ assertOut("try {\n a;\n} catch (e) {\n b;\n} finally {\n c;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitTry_Catch_Catch_Finally()
+ {
+ // TODO (erikdebruin) handle multiple 'catch' statements (FW in Wiki)
+ ITryNode node = (ITryNode) getNode(
+ "try { a; } catch (e:Error) { b; } catch (f:Error) { c; } finally { d; }",
+ ITryNode.class);
+ asBlockWalker.visitTry(node);
+ assertOut("try {\n a;\n} catch (e) {\n b;\n} catch (f) {\n c;\n} finally {\n d;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitTry_CatchEmpty_FinallyEmpty_()
+ {
+ ITryNode node = (ITryNode) getNode(
+ "try { a; } catch (e:Error) { } finally { }", ITryNode.class);
+ asBlockWalker.visitTry(node);
+ assertOut("try {\n a;\n} catch (e) {\n} finally {\n}");
+ }
+
+ //----------------------------------
+ // switch {}
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitSwitch_1()
+ {
+ ISwitchNode node = (ISwitchNode) getNode("switch(i){case 1: break;}",
+ ISwitchNode.class);
+ asBlockWalker.visitSwitch(node);
+ assertOut("switch (i) {\n case 1:\n break;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitSwitch_1a()
+ {
+ ISwitchNode node = (ISwitchNode) getNode(
+ "switch(i){case 1: { break; }}", ISwitchNode.class);
+ asBlockWalker.visitSwitch(node);
+ // (erikdebruin) the code is valid without the extra braces,
+ // i.e. we're good, we "don't care"
+ assertOut("switch (i) {\n case 1:\n break;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitSwitch_2()
+ {
+ ISwitchNode node = (ISwitchNode) getNode(
+ "switch(i){case 1: break; default: return;}", ISwitchNode.class);
+ asBlockWalker.visitSwitch(node);
+ assertOut("switch (i) {\n case 1:\n break;\n default:\n return;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitSwitch_3()
+ {
+ ISwitchNode node = (ISwitchNode) getNode(
+ "switch(i){case 1: { var x:int = 42; break; }; case 2: { var y:int = 66; break; }}", ISwitchNode.class);
+ asBlockWalker.visitSwitch(node);
+ assertOut("switch (i) {\n case 1:\n var /** @type {number} */ x = 42;\n break;\n case 2:\n var /** @type {number} */ y = 66;\n break;\n}");
+ }
+
+ @Test
+ public void testVisitSwitch_EscapedQuotes()
+ {
+ ISwitchNode node = (ISwitchNode) getNode(
+ "switch (type) { case \"string\": { return \"\\\"\" + value.toString() + \"\\\"\"; } }", ISwitchNode.class);
+ asBlockWalker.visitSwitch(node);
+ assertOut("switch (type) {\n case \"string\":\n return \"\\\"\" + value.toString() + \"\\\"\";\n}");
+ }
+
+ //----------------------------------
+ // if ()
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitIf_1()
+ {
+ IIfNode node = (IIfNode) getNode("if (a) b++;", IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (a)\n b++;");
+ }
+
+ @Override
+ @Test
+ public void testVisitIf_2()
+ {
+ IIfNode node = (IIfNode) getNode("if (a) b++; else c++;", IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (a)\n b++;\nelse\n c++;");
+ }
+
+ @Override
+ @Test
+ public void testVisitIf_4()
+ {
+ IIfNode node = (IIfNode) getNode(
+ "if (a) b++; else if (c) d++; else if(e) --f;", IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (a)\n b++;\nelse if (c)\n d++;\nelse if (e)\n --f;");
+ }
+
+ @Test
+ public void testVisitIf_E4X()
+ {
+ IIfNode node = (IIfNode) getNode(
+ "if (numChildren == 0) { if (!typeDescription.@dynamic) { trace(\"warning: no describeType entry for '\" + childName + \"' on non-dynamic type '\" + typeDescription.@name + \"'\"); } }", IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (numChildren == 0) {\n if (!this.typeDescription['E4XOperator']) {\n org.apache.flex.utils.Language.trace(\"warning: no describeType entry for '\" + childName + \"' on non-dynamic type '\" + this.typeDescription['E4XOperator'] + \"'\");\n }\n}");
+ }
+
+ @Test
+ public void testVisitIf_E4X_Again()
+ {
+ IIfNode node = (IIfNode) getNode(
+ "if (options.includeReadOnly) { properties = classInfo..accessor.(@access != \"writeonly\") + classInfo..variable; }", IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (options.includeReadOnly) {\n properties = 'E4XFilter' + this.classInfo['E4XSelector'];\n}");
+ }
+
+ @Test
+ public void testVisitIf_UnescapedBackSlash()
+ {
+ IIfNode node = (IIfNode) getNode(
+ "if (rootURL && !(url.indexOf(\":\") > -1 || url.indexOf(\"/\") == 0 || url.indexOf(\"\\\\\") == 0)) { var index:int; }", IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (rootURL && !(url.indexOf(\":\") > -1 || url.indexOf(\"/\") == 0 || url.indexOf(\"\\\\\") == 0)) {\n var /** @type {number} */ index;\n}");
+ }
+
+ //----------------------------------
+ // if () { }
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitIf_1a()
+ {
+ IIfNode node = (IIfNode) getNode("if (a) { b++; }", IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (a) {\n b++;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitIf_1b()
+ {
+ IIfNode node = (IIfNode) getNode("if (a) { b++; } else { c++; }",
+ IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (a) {\n b++;\n} else {\n c++;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitIf_1c()
+ {
+ IIfNode node = (IIfNode) getNode(
+ "if (a) { b++; } else if (b) { c++; } else { d++; }",
+ IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (a) {\n b++;\n} else if (b) {\n c++;\n} else {\n d++;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitIf_3()
+ {
+ IIfNode node = (IIfNode) getNode(
+ "if (a) b++; else if (c) d++; else --e;", IIfNode.class);
+ asBlockWalker.visitIf(node);
+ assertOut("if (a)\n b++;\nelse if (c)\n d++;\nelse\n --e;");
+ }
+
+ //----------------------------------
+ // label : for () {}
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitFor_2()
+ {
+ IForLoopNode node = (IForLoopNode) getNode("for (;;) { break; }",
+ IForLoopNode.class);
+ asBlockWalker.visitForLoop(node);
+ assertOut("for (;;) {\n break;\n}");
+ }
+
+ //----------------------------------
+ // while () { }
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitWhileLoop_1()
+ {
+ IWhileLoopNode node = (IWhileLoopNode) getNode(
+ "while(a > b){a++;--b;}", IWhileLoopNode.class);
+ asBlockWalker.visitWhileLoop(node);
+ assertOut("while (a > b) {\n a++;\n --b;\n}");
+ }
+
+ @Override
+ @Test
+ public void testVisitWhileLoop_1a()
+ {
+ IWhileLoopNode node = (IWhileLoopNode) getNode("while(a > b) a++;",
+ IWhileLoopNode.class);
+ asBlockWalker.visitWhileLoop(node);
+ assertOut("while (a > b)\n a++;");
+ }
+
+ //----------------------------------
+ // do {} while ()
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitWhileLoop_Do_1()
+ {
+ IWhileLoopNode node = (IWhileLoopNode) getNode(
+ "do {a++;--b;} while(a > b);", IWhileLoopNode.class);
+ asBlockWalker.visitWhileLoop(node);
+ assertOut("do {\n a++;\n --b;\n} while (a > b);");
+ }
+
+ @Override
+ @Test
+ public void testVisitWhileLoop_Do_1a()
+ {
+ IWhileLoopNode node = (IWhileLoopNode) getNode("do a++; while(a > b);",
+ IWhileLoopNode.class);
+ asBlockWalker.visitWhileLoop(node);
+ assertOut("do\n a++;\nwhile (a > b);");
+ }
+
+ //----------------------------------
+ // label : for () {}
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testVisitLabel_1()
+ {
+ LabeledStatementNode node = (LabeledStatementNode) getNode(
+ "foo: for each(var i:int in obj) { break foo; }",
+ LabeledStatementNode.class);
+ asBlockWalker.visitLabeledStatement(node);
+ assertOut("foo : for (var foreachiter0 in obj) \n{\nvar i = obj[foreachiter0];\n{\n break foo;\n}}\n");
+ }
+
+ @Override
+ @Test
+ public void testVisitLabel_1a()
+ {
+ // TODO (mschmalle) LabelStatement messes up in finally{} block, something is wrong there
+ LabeledStatementNode node = (LabeledStatementNode) getNode(
+ "foo: for each(var i:int in obj) break foo;",
+ LabeledStatementNode.class);
+ asBlockWalker.visitLabeledStatement(node);
+ assertOut("foo : for (var foreachiter0 in obj) \n{\nvar i = obj[foreachiter0];\n\n break foo;}\n");
+ }
+
+ //----------------------------------
+ // with () {}
+ //----------------------------------
+
+ @Test
+ public void testVisitWith()
+ {
+ IWithNode node = (IWithNode) getNode("with (a) { b; }", IWithNode.class);
+ asBlockWalker.visitWith(node);
+ assertOut("with (a) {\n b;\n}");
+ }
+
+ @Test
+ public void testVisitWith_1a()
+ {
+ IWithNode node = (IWithNode) getNode("with (a) b;", IWithNode.class);
+ asBlockWalker.visitWith(node);
+ assertOut("with (a)\n b;");
+ }
+
+ @Override
+ @Test
+ public void testVisit()
+ {
+ IFileNode node = (IFileNode) getNode(
+ "try { a; } catch (e:Error) { if (a) { if (b) { if (c) b; else if (f) a; else e; }} } finally { }"
+ + "if (d) for (var i:int = 0; i < len; i++) break;"
+ + "if (a) { with (ab) { c(); } "
+ + "do {a++;do a++; while(a > b);} while(c > d); }"
+ + "if (b) { try { a; throw new Error('foo'); } catch (e:Error) { "
+ + " switch(i){case 1: break; default: return;}"
+ + " } finally { "
+ + " d; var a:Object = function(foo:int, bar:String = 'goo'):int{return -1;};"
+ + " eee.dd; eee.dd; eee.dd; eee.dd;} }"
+ + "foo: for each(var i:int in obj) break foo;",
+ IFileNode.class);
+ asBlockWalker.visitFile(node);
+ assertOutWithMetadata("/**\n * FalconTest_A\n *\n * @fileoverview\n *\n * @suppress {checkTypes}\n */\n\ngoog.provide('FalconTest_A');\n\n\n\n/**\n * @constructor\n */\nFalconTest_A = function() {};\n\n\nFalconTest_A.prototype.falconTest_a = function() {\n try {\n a;\n } catch (e) {\n if (a) {\n if (b) {\n if (c)\n b;\n else if (f)\n a;\n else\n e;\n }\n }\n } finally {\n }\n if (d)\n for (var /** @type {number} */ i = 0; i < len; i++)\n break;\n if (a) {\n with (ab) {\n c();\n }\n do {\n a++;\n do\n a++;\n while (a > b);\n } while (c > d);\n }\n if (b) {\n try {\n a;\n throw new Error('foo');\n } catch (e) {\n switch (i) {\n case 1:\n break;\n default:\n return;\n }\n } finally {\n d;\n var /** @type {Object} */ a = function(foo, bar) {\n bar = typeof bar !== 'undefined' ? bar
: 'goo';\n return -1;\n };\n eee.dd;\n eee.dd;\n eee.dd;\n eee.dd;\n }\n }\n foo : for (var foreachiter0 in obj) \n {\n var i = obj[foreachiter0];\n \n break foo;}\n ;\n};\n\n\n/**\n * Metadata\n *\n * @type {Object.<string, Array.<Object>>}\n */\nFalconTest_A.prototype.FLEXJS_CLASS_INFO = { names: [{ name: 'FalconTest_A', qName: 'FalconTest_A'}] };\n");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new VF2JSBackend();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLApplication.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLApplication.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLApplication.java
new file mode 100644
index 0000000..fbfe6b8
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLApplication.java
@@ -0,0 +1,109 @@
+/*
+ *
+ * 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.mxml;
+
+import org.apache.flex.compiler.internal.test.MXMLTestBase;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.junit.Test;
+
+public class TestMXMLApplication extends MXMLTestBase
+{
+
+ @Test
+ public void testBasicApp()
+ {
+ String code = ""
+ + "<s:Application xmlns:s=\"library://ns.adobe.com/flex/spark\">"
+ + "</s:Application>";
+
+ IMXMLFileNode node = compileMXML(code);
+
+ mxmlBlockWalker.visitFile(node);
+
+ assertOut("<Application>\n\t\n</Application>");
+ }
+
+ @Test
+ public void testBasicAppWithOneComponent()
+ {
+ String code = ""
+ + "<s:Application xmlns:s=\"library://ns.adobe.com/flex/spark\">"
+ + " <s:Button id=\"myBtn\" label=\"Hello world\"></s:Button>"
+ + "</s:Application>";
+
+ IMXMLFileNode node = compileMXML(code);
+
+ mxmlBlockWalker.visitFile(node);
+
+ assertOut("<Application>\n\t<Button id=\"myBtn\" label=\"Hello world\"></Button>\n</Application>");
+ }
+
+ @Test
+ public void testBasicAppWithTwoComponents()
+ {
+ String code = ""
+ + "<s:Application xmlns:s=\"library://ns.adobe.com/flex/spark\">"
+ + " <s:Label id=\"myLbl\" text=\"Bye bye\"></s:Label>"
+ + " <s:Button id=\"myBtn\" label=\"Hello world\"></s:Button>"
+ + "</s:Application>";
+
+ IMXMLFileNode node = compileMXML(code);
+
+ mxmlBlockWalker.visitFile(node);
+
+ assertOut("<Application>\n\t<Label id=\"myLbl\" text=\"Bye bye\"></Label>\n\t<Button id=\"myBtn\" label=\"Hello world\"></Button>\n</Application>");
+ }
+
+ @Test
+ public void testBasicAppWithSimpleScript()
+ {
+ String code = ""
+ + "<s:Application xmlns:fx=\"http://ns.adobe.com/mxml/2009\" xmlns:s=\"library://ns.adobe.com/flex/spark\">"
+ + " <fx:Script><![CDATA["
+ + " private const GREETING:String = \"Hello world!\""
+ + " ]]></fx:Script>" + "</s:Application>";
+
+ IMXMLFileNode node = compileMXML(code);
+
+ mxmlBlockWalker.visitFile(node);
+
+ assertOut("<Application>\n\t<script><![CDATA[\n\t\tprivate var GREETING:String = \"Hello world!\";\n\t]]></script>\n</Application>");
+ }
+
+ @Test
+ public void testDefaultApp()
+ {
+ String code = ""
+ + "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ + "<s:Application xmlns:fx=\"http://ns.adobe.com/mxml/2009\""
+ + " xmlns:s=\"library://ns.adobe.com/flex/spark\" "
+ + " xmlns:mx=\"library://ns.adobe.com/flex/mx\" "
+ + " minWidth=\"955\" minHeight=\"600\">"
+ + " <fx:Declarations>"
+ + " <!-- Place non-visual elements (e.g., services, value objects) here -->"
+ + " </fx:Declarations>" + "</s:Application>";
+
+ IMXMLFileNode node = compileMXML(code);
+
+ mxmlBlockWalker.visitFile(node);
+
+ assertOut("<Application minWidth=\"955\" minHeight=\"600\">\n\t\n</Application>");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLAttributes.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLAttributes.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLAttributes.java
new file mode 100644
index 0000000..5292df3
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLAttributes.java
@@ -0,0 +1,118 @@
+/*
+ *
+ * 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.mxml;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.flex.compiler.internal.test.MXMLTestBase;
+import org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode;
+import org.junit.Test;
+
+public class TestMXMLAttributes extends MXMLTestBase
+{
+
+ @Test
+ public void testIdAttribute()
+ {
+ // (erikdebruin) id attributes are a special case...
+
+ String code = "id=\"myBtn\"";
+
+ IMXMLInstanceNode node = (IMXMLInstanceNode) getNode(
+ code, IMXMLInstanceNode.class,
+ MXMLTestBase.WRAP_LEVEL_NODE);
+
+ mxmlBlockWalker.visitInstance(node);
+
+ assertThat(((IMXMLInstanceNode) node.getChild(0)).getID(), is("myBtn"));
+ }
+
+ @Test
+ public void testSimpleBooleanAttribute()
+ {
+ String code = "visible=\"false\"";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_NODE);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("visible=\"false\"");
+ }
+
+ @Test
+ public void testSimpleIntAttribute()
+ {
+ String code = "x=\"100\"";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_NODE);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("x=\"100\"");
+ }
+
+ @Test
+ public void testSimpleNumberAttribute()
+ {
+ String code = "width=\"1.5\"";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_NODE);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("width=\"1.5\"");
+ }
+
+ @Test
+ public void testSimpleStringAttribute()
+ {
+ String code = "label=\"Click me ;-)\"";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_NODE);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("label=\"Click me ;-)\"");
+ }
+
+ @Test
+ public void testSimpleUintAttribute()
+ {
+ String code = "color=\"0xFF0000\"";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_NODE);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("color=\"16711680\"");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLNodes.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLNodes.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLNodes.java
new file mode 100644
index 0000000..ba39c2b
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLNodes.java
@@ -0,0 +1,187 @@
+/*
+ *
+ * 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.mxml;
+
+import org.apache.flex.compiler.internal.test.MXMLTestBase;
+import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode;
+import org.junit.Test;
+
+public class TestMXMLNodes extends MXMLTestBase
+{
+
+ @Test
+ public void testSimpleNode()
+ {
+ String code = "<s:Button />";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Button></Button>");
+ }
+
+ @Test
+ public void testSimpleNodeWithId()
+ {
+ String code = "<s:Button id=\"myBtn\"/>";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Button id=\"myBtn\"></Button>");
+ }
+
+ @Test
+ public void testSimpleNodeWithAttribute()
+ {
+ String code = "<s:Button label=\"Click me\" />";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Button label=\"Click me\"></Button>");
+ }
+
+ @Test
+ public void testSimpleNodeWithInnerText()
+ {
+ String code = "<s:Button>Click me</s:Button>";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Button label=\"Click me\"></Button>");
+ }
+
+ @Test
+ public void testAnotherSimpleNodeWithInnerText()
+ {
+ String code = "<s:Label>Hello World!</s:Label>";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Label text=\"Hello World!\"></Label>");
+ }
+
+ @Test
+ public void testSimpleNodeWithMultipleAttributes()
+ {
+ String code = "<s:Button visible=\"false\" x=\"100\" width=\"1.5\" label=\"Click me ;-)\" color=\"0xFF0000\"/>";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Button visible=\"false\" x=\"100\" width=\"1.5\" label=\"Click me ;-)\" color=\"16711680\"></Button>");
+ }
+
+ @Test
+ public void testNodeWithChild()
+ {
+ String code = "<s:Group><s:RadioButton /></s:Group>";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Group><RadioButton></RadioButton></Group>");
+ }
+
+ @Test
+ public void testNodeWithChildAndAttribute()
+ {
+ String code = "<s:Group id=\"myGrp\"><s:RadioButton /></s:Group>";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Group id=\"myGrp\"><RadioButton></RadioButton></Group>");
+ }
+
+ @Test
+ public void testNodeWithNestedChildren()
+ {
+ String code = "<s:Group><s:Group><s:Group>" + "<s:RadioButton />"
+ + "</s:Group></s:Group></s:Group>";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Group><Group><Group><RadioButton></RadioButton></Group></Group></Group>");
+ }
+
+ @Test
+ public void testNodeWithNestedChildrenAndAttribute()
+ {
+ String code = "<s:Group><s:Group><s:Group>"
+ + "<s:RadioButton id=\"myRB\"/>"
+ + "</s:Group></s:Group></s:Group>";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Group><Group><Group><RadioButton id=\"myRB\"></RadioButton></Group></Group></Group>");
+ }
+
+ @Test
+ public void testNodeWithNestedChildrenAndInnerText()
+ {
+ String code = "<s:Group><s:Group><s:Group>"
+ + "<s:Button>Click me</s:Button>"
+ + "</s:Group></s:Group></s:Group>";
+
+ IMXMLPropertySpecifierNode node = (IMXMLPropertySpecifierNode) getNode(
+ code, IMXMLPropertySpecifierNode.class,
+ MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitPropertySpecifier(node);
+
+ assertOut("<Group><Group><Group><Button label=\"Click me\"></Button></Group></Group></Group>");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLScript.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLScript.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLScript.java
new file mode 100644
index 0000000..912ff45
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/TestMXMLScript.java
@@ -0,0 +1,106 @@
+/*
+ *
+ * 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.mxml;
+
+import org.apache.flex.compiler.internal.test.MXMLTestBase;
+import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
+import org.junit.Test;
+
+public class TestMXMLScript extends MXMLTestBase
+{
+
+ @Test
+ public void testEmptyScript()
+ {
+ String code = "" + "<fx:Script><![CDATA[]]></fx:Script>";
+
+ IMXMLScriptNode node = (IMXMLScriptNode) getNode(code,
+ IMXMLScriptNode.class, MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitScript(node);
+
+ assertOut("<script><![CDATA[]]></script>");
+ }
+
+ @Test
+ public void testSimpleScript()
+ {
+ String code = "" + "<fx:Script><![CDATA["
+ + " private var GREETING:String = \"Hello world!\";"
+ + "]]></fx:Script>";
+
+ IMXMLScriptNode node = (IMXMLScriptNode) getNode(code,
+ IMXMLScriptNode.class, MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitScript(node);
+
+ assertOut("<script><![CDATA[\n\tprivate var GREETING:String = \"Hello world!\";\n]]></script>");
+ }
+
+ @Test
+ public void testMultiLineScript()
+ {
+ String code = "" + "<fx:Script><![CDATA["
+ + " public var goodbye:String = \"Bye bye :-(\";"
+ + " private const GREETING:String = \"Hello world!\";"
+ + "]]></fx:Script>";
+
+ IMXMLScriptNode node = (IMXMLScriptNode) getNode(code,
+ IMXMLScriptNode.class, MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitScript(node);
+
+ assertOut("<script><![CDATA[\n\tpublic var goodbye:String = \"Bye bye :-(\";\n\tprivate var GREETING:String = \"Hello world!\";\n]]></script>");
+ }
+
+ @Test
+ public void testComplexScript()
+ {
+ // TODO (erikdebruin) fix indentation...
+ String code = "" + "<fx:Script><![CDATA[" + " var n:int = 3;"
+ + " for (var i:int = 0; i < n; i++)" + " {"
+ + " Alert.show(\"Hi\");" + " }" + "]]></fx:Script>";
+
+ IMXMLScriptNode node = (IMXMLScriptNode) getNode(code,
+ IMXMLScriptNode.class, MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+
+ mxmlBlockWalker.visitScript(node);
+
+ assertOut("<script><![CDATA[\n\tvar n:int = 3;\n\tfor (var i:int = 0; i < n; i++) {\n\tAlert.show(\"Hi\");\n};\n]]></script>");
+ }
+
+ // TODO (erikdebruin) this isn't working...
+ @Test
+ public void testFunctionScript()
+ {
+// String code = "" + "<fx:Script><![CDATA["
+// + " public static function beNice(input:*):Object" + " {"
+// + " Alert.show(\"I'm nice :-P\");"
+// + " return null;" + " }" + "]]></fx:Script>";
+//
+// IMXMLScriptNode node = (IMXMLScriptNode) getNode(code,
+// IMXMLScriptNode.class, MXMLTestBase.WRAP_LEVEL_DOCUMENT);
+//
+// mxmlBlockWalker.visitScript(node);
+//
+// System.out.println(writer.toString());
+//
+// assertOut("<script><![CDATA[\n\tvar n:int = 3;\n\tfor (var i:int = 0; i < n; i++) {\n\tAlert.show(\"Hi\");\n};\n]]></script>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
new file mode 100644
index 0000000..fc5ce66
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
@@ -0,0 +1,279 @@
+/*
+ *
+ * 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.mxml.flexjs;
+
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.test.FlexJSTestBase;
+import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.apache.flex.utils.ITestAdapter;
+import org.apache.flex.utils.TestAdapterFactory;
+import org.junit.Test;
+
+import java.io.File;
+
+public class TestFlexJSMXMLApplication extends FlexJSTestBase
+{
+ private static ITestAdapter testAdapter = TestAdapterFactory.getTestAdapter();
+
+ @Override
+ public void setUp()
+ {
+ super.setUp();
+ ((FlexJSProject)project).config = new JSGoogConfiguration();
+ }
+
+ @Test
+ public void testFile()
+ {
+ String fileName = "wildcard_import";
+
+ IMXMLFileNode node = compileMXML(fileName, true,
+ new File(testAdapter.getUnitTestBaseDir(), "flexjs/files").getPath(), false);
+
+ mxmlBlockWalker.visitFile(node);
+
+ //writeResultToFile(writer.toString(), fileName);
+
+ assertOutWithMetadata(getCodeFromFile(fileName + "_result", true, "flexjs/files"));
+ }
+
+ @Test
+ public void testFlexJSMainFile()
+ {
+ String fileName = "FlexJSTest_again";
+
+ IMXMLFileNode node = compileMXML(fileName, true,
+ new File(testAdapter.getUnitTestBaseDir(), "flexjs/files").getPath(), false);
+
+ mxmlBlockWalker.visitFile(node);
+
+ //writeResultToFile(writer.toString(), fileName);
+
+ assertOutWithMetadata(getCodeFromFile(fileName + "_result", true, "flexjs/files"));
+ }
+
+ @Test
+ public void testFlexJSInitialViewFile()
+ {
+ String fileName = "MyInitialView";
+
+ IMXMLFileNode node = compileMXML(fileName, true,
+ new File(testAdapter.getUnitTestBaseDir(), "flexjs/files").getPath(), false);
+
+ mxmlBlockWalker.visitFile(node);
+
+ //writeResultToFile(writer.toString(), fileName);
+
+ assertOutWithMetadata(getCodeFromFile(fileName + "_result", true, "flexjs/files"));
+ }
+
+ @Test
+ public void testInterfaceAttribute()
+ {
+ String code = "<basic:Application xmlns:fx=\"http://ns.adobe.com/mxml/2009\" xmlns:basic=\"library://ns.apache.org/flexjs/basic\" implements=\"org.apache.flex.core.IChrome\">"
+ + "<fx:Script><![CDATA["
+ + " import org.apache.flex.core.IChrome;"
+ + "]]></fx:Script></basic:Application>";
+
+ IMXMLDocumentNode dnode = (IMXMLDocumentNode) getNode(code,
+ IMXMLDocumentNode.class, FlexJSTestBase.WRAP_LEVEL_NONE);
+
+ ((JSFlexJSEmitter)(mxmlBlockWalker.getASEmitter())).getModel().setCurrentClass(dnode.getDefinition());
+ mxmlBlockWalker.visitDocument(dnode);
+ String appName = dnode.getQualifiedName();
+ String outTemplate = "/**\n" +
+ " * AppName\n" +
+ " *\n" +
+ " * @fileoverview\n" +
+ " *\n" +
+ " * @suppress {checkTypes|accessControls}\n" +
+ " */\n" +
+ "\n" +
+ "goog.provide('AppName');\n" +
+ "\n" +
+ "goog.require('org.apache.flex.core.Application');\n" +
+ "goog.require('org.apache.flex.core.IChrome');\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @constructor\n" +
+ " * @extends {org.apache.flex.core.Application}\n" +
+ " */\n" +
+ "AppName = function() {\n" +
+ " AppName.base(this, 'constructor');\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldd;\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldp;\n" +
+ "};\n" +
+ "goog.inherits(AppName, org.apache.flex.core.Application);\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Metadata\n" +
+ " *\n" +
+ " * @type {Object.<string, Array.<Object>>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_CLASS_INFO = { names: [{ name: 'AppName', qName: 'AppName' }], interfaces: [org.apache.flex.core.IChrome] };\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Prevent renaming of class. Needed for reflection.\n" +
+ " */\n" +
+ "goog.exportSymbol('AppName', AppName);\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Reflection\n" +
+ " *\n" +
+ " * @return {Object.<string, Function>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_REFLECTION_INFO = function () {\n" +
+ " return {\n" +
+ " variables: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " },\n" +
+ " accessors: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " },\n" +
+ " methods: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " }\n" +
+ " };\n" +
+ "};\n" +
+ "\n" +
+ "\n" +
+ "\n";
+
+ assertOutWithMetadata(outTemplate.replaceAll("AppName", appName));
+ }
+
+ @Test
+ public void testTwoInterfaceAttribute()
+ {
+ String code = "<basic:Application xmlns:fx=\"http://ns.adobe.com/mxml/2009\" xmlns:basic=\"library://ns.apache.org/flexjs/basic\" implements=\"org.apache.flex.core.IChrome, org.apache.flex.core.IPopUp\">"
+ + "<fx:Script><![CDATA["
+ + " import org.apache.flex.core.IPopUp;"
+ + " import org.apache.flex.core.IChrome;"
+ + "]]></fx:Script></basic:Application>";
+
+ IMXMLDocumentNode dnode = (IMXMLDocumentNode) getNode(code,
+ IMXMLDocumentNode.class, FlexJSTestBase.WRAP_LEVEL_NONE);
+
+ ((JSFlexJSEmitter)(mxmlBlockWalker.getASEmitter())).getModel().setCurrentClass(dnode.getDefinition());
+ mxmlBlockWalker.visitDocument(dnode);
+ String appName = dnode.getQualifiedName();
+ String outTemplate = "/**\n" +
+ " * AppName\n" +
+ " *\n" +
+ " * @fileoverview\n" +
+ " *\n" +
+ " * @suppress {checkTypes|accessControls}\n" +
+ " */\n" +
+ "\n" +
+ "goog.provide('AppName');\n" +
+ "\n" +
+ "goog.require('org.apache.flex.core.Application');\n" +
+ "goog.require('org.apache.flex.core.IChrome');\n" +
+ "goog.require('org.apache.flex.core.IPopUp');\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @constructor\n" +
+ " * @extends {org.apache.flex.core.Application}\n" +
+ " */\n" +
+ "AppName = function() {\n" +
+ " AppName.base(this, 'constructor');\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldd;\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldp;\n" +
+ "};\n" +
+ "goog.inherits(AppName, org.apache.flex.core.Application);\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Metadata\n" +
+ " *\n" +
+ " * @type {Object.<string, Array.<Object>>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_CLASS_INFO = { names: [{ name: 'AppName', qName: 'AppName' }], interfaces: [org.apache.flex.core.IChrome, org.apache.flex.core.IPopUp] };\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Prevent renaming of class. Needed for reflection.\n" +
+ " */\n" +
+ "goog.exportSymbol('AppName', AppName);\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Reflection\n" +
+ " *\n" +
+ " * @return {Object.<string, Function>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_REFLECTION_INFO = function () {\n" +
+ " return {\n" +
+ " variables: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " },\n" +
+ " accessors: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " },\n" +
+ " methods: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " }\n" +
+ " };\n" +
+ "};\n" +
+ "\n" +
+ "\n" +
+ "\n";
+
+ assertOutWithMetadata(outTemplate.replaceAll("AppName", appName));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
new file mode 100644
index 0000000..3da0c36
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
@@ -0,0 +1,237 @@
+/*
+ *
+ * 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.mxml.flexjs;
+
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.test.FlexJSTestBase;
+import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
+import org.junit.Test;
+
+public class TestFlexJSMXMLScript extends FlexJSTestBase
+{
+
+ @Test
+ public void testSuperInScript()
+ {
+ String code = "" + "<fx:Script><![CDATA["
+ + " override public function addedToParent():void {"
+ + " super.addedToParent();}"
+ + "]]></fx:Script>";
+
+ IMXMLScriptNode node = (IMXMLScriptNode) getNode(code,
+ IMXMLScriptNode.class, FlexJSTestBase.WRAP_LEVEL_DOCUMENT);
+
+ IMXMLDocumentNode dnode = (IMXMLDocumentNode) node
+ .getAncestorOfType(IMXMLDocumentNode.class);
+ ((JSFlexJSEmitter)(mxmlBlockWalker.getASEmitter())).getModel().setCurrentClass(dnode.getDefinition());
+ mxmlBlockWalker.visitDocument(dnode);
+ String appName = dnode.getQualifiedName();
+ String outTemplate = "/**\n" +
+ " * AppName\n" +
+ " *\n" +
+ " * @fileoverview\n" +
+ " *\n" +
+ " * @suppress {checkTypes|accessControls}\n" +
+ " */\n" +
+ "\n" +
+ "goog.provide('AppName');\n" +
+ "\n" +
+ "goog.require('org.apache.flex.core.Application');\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @constructor\n" +
+ " * @extends {org.apache.flex.core.Application}\n" +
+ " */\n" +
+ "AppName = function() {\n" +
+ " AppName.base(this, 'constructor');\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldd;\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldp;\n" +
+ "};\n" +
+ "goog.inherits(AppName, org.apache.flex.core.Application);\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Metadata\n" +
+ " *\n" +
+ " * @type {Object.<string, Array.<Object>>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_CLASS_INFO = { names: [{ name: 'AppName', qName: 'AppName' }] };\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Prevent renaming of class. Needed for reflection.\n" +
+ " */\n" +
+ "goog.exportSymbol('AppName', AppName);\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Reflection\n" +
+ " *\n" +
+ " * @return {Object.<string, Function>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_REFLECTION_INFO = function () {\n" +
+ " return {\n" +
+ " variables: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " },\n" +
+ " accessors: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " },\n" +
+ " methods: function () {\n" +
+ " return {\n" +
+ " 'addedToParent': { type: 'void', declaredBy: 'AppName'}\n" +
+ " };\n" +
+ " }\n" +
+ " };\n" +
+ "};\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @export\n" +
+ " * @override\n" +
+ " */\n" +
+ "AppName.prototype.addedToParent = function() {\n" +
+ " AppName.base(this, 'addedToParent');\n" +
+ "};\n" +
+ "\n" +
+ "\n";
+
+ assertOutWithMetadata(outTemplate.replaceAll("AppName", appName));
+ }
+
+ @Test
+ public void testComplexInitializersInScript()
+ {
+ String code = "" + "<fx:Script><![CDATA["
+ + " public var foo:Array = ['foo'];"
+ + "]]></fx:Script>";
+
+ IMXMLScriptNode node = (IMXMLScriptNode) getNode(code,
+ IMXMLScriptNode.class, FlexJSTestBase.WRAP_LEVEL_DOCUMENT);
+
+ IMXMLDocumentNode dnode = (IMXMLDocumentNode) node
+ .getAncestorOfType(IMXMLDocumentNode.class);
+ ((JSFlexJSEmitter)(mxmlBlockWalker.getASEmitter())).getModel().setCurrentClass(dnode.getDefinition());
+ mxmlBlockWalker.visitDocument(dnode);
+ String appName = dnode.getQualifiedName();
+ String outTemplate = "/**\n" +
+ " * AppName\n" +
+ " *\n" +
+ " * @fileoverview\n" +
+ " *\n" +
+ " * @suppress {checkTypes|accessControls}\n" +
+ " */\n" +
+ "\n" +
+ "goog.provide('AppName');\n" +
+ "\n" +
+ "goog.require('org.apache.flex.core.Application');\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @constructor\n" +
+ " * @extends {org.apache.flex.core.Application}\n" +
+ " */\n" +
+ "AppName = function() {\n" +
+ " AppName.base(this, 'constructor');\n" +
+ " \n" +
+ " this.foo = ['foo'];\n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldd;\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldp;\n" +
+ "};\n" +
+ "goog.inherits(AppName, org.apache.flex.core.Application);\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Metadata\n" +
+ " *\n" +
+ " * @type {Object.<string, Array.<Object>>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_CLASS_INFO = { names: [{ name: 'AppName', qName: 'AppName' }] };\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Prevent renaming of class. Needed for reflection.\n" +
+ " */\n" +
+ "goog.exportSymbol('AppName', AppName);\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Reflection\n" +
+ " *\n" +
+ " * @return {Object.<string, Function>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_REFLECTION_INFO = function () {\n" +
+ " return {\n" +
+ " variables: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " },\n" +
+ " accessors: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " },\n" +
+ " methods: function () {\n" +
+ " return {\n" +
+ " };\n" +
+ " }\n" +
+ " };\n" +
+ "};\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @export\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ "AppName.prototype.foo;\n" +
+ "\n" +
+ "\n" +
+ "";
+
+ assertOutWithMetadata(outTemplate.replaceAll("AppName", appName));
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/TestVF2JSMXMLApplication.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/TestVF2JSMXMLApplication.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/TestVF2JSMXMLApplication.java
new file mode 100644
index 0000000..93f2a6b
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/vf2js/TestVF2JSMXMLApplication.java
@@ -0,0 +1,97 @@
+/*
+ *
+ * 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.mxml.vf2js;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.flex.compiler.internal.test.VF2JSMXMLTestBase;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.apache.flex.utils.ITestAdapter;
+import org.apache.flex.utils.TestAdapterFactory;
+import org.junit.Test;
+
+public class TestVF2JSMXMLApplication extends VF2JSMXMLTestBase
+{
+ private static ITestAdapter testAdapter = TestAdapterFactory.getTestAdapter();
+
+ @Override
+ protected void addSourcePaths(List<File> sourcePaths)
+ {
+ sourcePaths.add(new File(testAdapter.getUnitTestBaseDir(), "vf2js/files"));
+ sourcePaths.add(new File(testAdapter.getUnitTestBaseDir(), "vf2js/projects/simpleMXML/src"));
+
+ super.addSourcePaths(sourcePaths);
+ }
+
+ @Test
+ public void testSimple()
+ {
+ String fileName = "SimpleMXML";
+
+ IMXMLFileNode node = compileMXML(fileName, true,
+ new File(testAdapter.getUnitTestBaseDir(), "vf2js/files").getPath(), false);
+
+ mxmlBlockWalker.visitFile(node);
+
+ //writeResultToFile(writer.toxString(), fileName);
+
+ assertOutWithMetadata(getCodeFromFile(fileName + "_result", true, "vf2js/files"));
+ }
+
+
+ @Test
+ public void testSimpleMXMLProject()
+ {
+ String testDirPath = "vf2js/projects/simpleMXML/src";
+
+ String fileName = "SimpleMXML_Project";
+
+ List<String> compiledFileNames = compileProject(fileName, testDirPath);
+
+ // ToDo (erikdebruin): MXML property initialized with a FunctionCall
+ // are not included in the output (the assignment
+ // should be handled in the constructor, like in AS
+ assertProjectOut(compiledFileNames, testDirPath);
+ }
+
+ protected void assertProjectOut(List<String> compiledFileNames,
+ String testDirPath)
+ {
+ 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));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/AMDTestBase.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/AMDTestBase.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/AMDTestBase.java
new file mode 100644
index 0000000..faa7ea0
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/AMDTestBase.java
@@ -0,0 +1,149 @@
+/*
+ *
+ * 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.test;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IDefinitionNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IGetterNode;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
+import org.apache.flex.compiler.tree.as.ISetterNode;
+import org.apache.flex.compiler.tree.as.ITypeNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.apache.flex.utils.FilenameNormalization;
+import org.apache.flex.utils.TestAdapterFactory;
+
+/**
+ * This class tests the production of AMD JavaScript for AS package.
+ *
+ * @author Michael Schmalle
+ */
+public abstract class AMDTestBase extends TestBase
+{
+ protected IFileNode fileNode;
+
+ protected IClassNode classNode;
+
+ protected IInterfaceNode interfaceNode;
+
+ private String projectPath;
+
+ @Override
+ public void setUp()
+ {
+ super.setUp();
+
+ asEmitter = backend.createEmitter(writer);
+ asBlockWalker = backend.createWalker(project, errors, asEmitter);
+
+ projectPath = new File(TestAdapterFactory.getTestAdapter().getUnitTestBaseDir(),
+ "amd/simple-project/src").getPath();
+
+ String target = getTypeUnderTest().replace(".", File.separator);
+ String targetDir = projectPath + File.separator
+ + target.substring(0, target.lastIndexOf(File.separator));
+ String targetFile = target.substring(
+ target.lastIndexOf(File.separator) + 1, target.length());
+
+ fileNode = compileAS(targetFile, true, targetDir, false);
+ ITypeNode type = (ITypeNode) findFirstDescendantOfType(fileNode,
+ ITypeNode.class);
+ if (type instanceof IClassNode)
+ classNode = (IClassNode) type;
+ else if (type instanceof IInterfaceNode)
+ interfaceNode = (IInterfaceNode) type;
+
+ }
+
+ abstract protected String getTypeUnderTest();
+
+ @Override
+ protected void addLibraries(List<File> libraries)
+ {
+ libraries.add(new File(FilenameNormalization.normalize(env.FPSDK
+ + "/" + env.FPVER + "/playerglobal.swc")));
+
+ super.addLibraries(libraries);
+ }
+
+ @Override
+ protected void addSourcePaths(List<File> sourcePaths)
+ {
+ sourcePaths.add(new File(FilenameNormalization.normalize(projectPath)));
+
+ super.addSourcePaths(sourcePaths);
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new AMDBackend();
+ }
+
+ protected IVariableNode findField(String name, IClassNode node)
+ {
+ IDefinitionNode[] nodes = node.getAllMemberNodes();
+ for (IDefinitionNode inode : nodes)
+ {
+ if (inode.getName().equals(name))
+ return (IVariableNode) inode;
+ }
+ return null;
+ }
+
+ protected IFunctionNode findFunction(String name, IClassNode node)
+ {
+ IDefinitionNode[] nodes = node.getAllMemberNodes();
+ for (IDefinitionNode inode : nodes)
+ {
+ if (inode.getName().equals(name))
+ return (IFunctionNode) inode;
+ }
+ return null;
+ }
+
+ protected IGetterNode findGetter(String name, IClassNode node)
+ {
+ IDefinitionNode[] nodes = node.getAllMemberNodes();
+ for (IDefinitionNode inode : nodes)
+ {
+ if (inode.getName().equals(name) && inode instanceof IGetterNode)
+ return (IGetterNode) inode;
+ }
+ return null;
+ }
+
+ protected ISetterNode findSetter(String name, IClassNode node)
+ {
+ IDefinitionNode[] nodes = node.getAllMemberNodes();
+ for (IDefinitionNode inode : nodes)
+ {
+ if (inode.getName().equals(name) && inode instanceof ISetterNode)
+ return (ISetterNode) inode;
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/ASTestBase.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/ASTestBase.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/ASTestBase.java
new file mode 100644
index 0000000..a5dbc93
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/ASTestBase.java
@@ -0,0 +1,190 @@
+/*
+ *
+ * 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.test;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.driver.as.ASBackend;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IAccessorNode;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IForLoopNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
+import org.apache.flex.compiler.tree.as.INamespaceAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.apache.flex.utils.FilenameNormalization;
+import org.apache.flex.utils.ITestAdapter;
+import org.apache.flex.utils.TestAdapterFactory;
+import org.junit.Ignore;
+
+@Ignore
+public class ASTestBase extends TestBase
+{
+
+ protected ITestAdapter testAdapter;
+
+ @Override
+ public void setUp()
+ {
+ super.setUp();
+
+ testAdapter = TestAdapterFactory.getTestAdapter();
+
+ asEmitter = backend.createEmitter(writer);
+ asBlockWalker = backend.createWalker(project, errors, asEmitter);
+ }
+
+ @Override
+ protected void addLibraries(List<File> libraries)
+ {
+ libraries.addAll(testAdapter.getLibraries(false));
+ // TODO: Make this use the test-adapter
+ libraries.add(new File(FilenameNormalization.normalize(
+ "../externs/GCL/out/bin/GCL.swc")));
+
+ super.addLibraries(libraries);
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new ASBackend();
+ }
+
+ //--------------------------------------------------------------------------
+ // Node "factory"
+ //--------------------------------------------------------------------------
+
+ protected static final int WRAP_LEVEL_MEMBER = 3;
+ protected static final int WRAP_LEVEL_CLASS = 2;
+ protected static final int WRAP_LEVEL_PACKAGE = 1;
+
+ protected IASNode getNode(String code, Class<? extends IASNode> type)
+ {
+ return getNode(code, type, WRAP_LEVEL_MEMBER, false);
+ }
+
+ protected IASNode getNode(String code, Class<? extends IASNode> type,
+ int wrapLevel)
+ {
+ return getNode(code, type, wrapLevel, false);
+ }
+
+ protected IASNode getNode(String code, Class<? extends IASNode> type,
+ int wrapLevel, boolean includePackage)
+ {
+ if (wrapLevel == WRAP_LEVEL_MEMBER)
+ code = "function falconTest_a():void {" + code + "}";
+
+ if (wrapLevel >= WRAP_LEVEL_CLASS)
+ code = "public class FalconTest_A {" + code + "}";
+
+ if (wrapLevel >= WRAP_LEVEL_PACKAGE)
+ code = "package" + ((includePackage) ? " foo.bar" : "") + " {"
+ + code + "}";
+
+ IFileNode node = compileAS(code);
+
+ if (type.isInstance(node))
+ return node;
+
+ return findFirstDescendantOfType(node, type);
+ }
+
+ protected IInterfaceNode getInterfaceNode(String code)
+ {
+ return (IInterfaceNode) getNode(code, IInterfaceNode.class,
+ WRAP_LEVEL_PACKAGE);
+ }
+
+ protected IAccessorNode getAccessor(String code)
+ {
+ return (IAccessorNode) getNode(code, IAccessorNode.class,
+ WRAP_LEVEL_CLASS);
+ }
+
+ protected IVariableNode getField(String code)
+ {
+ return (IVariableNode) getNode(code, IVariableNode.class,
+ WRAP_LEVEL_CLASS);
+ }
+
+ protected IFunctionNode getMethod(String code)
+ {
+ return (IFunctionNode) getNode(code, IFunctionNode.class,
+ WRAP_LEVEL_CLASS);
+ }
+
+ protected IFunctionNode getMethodWithPackage(String code)
+ {
+ return (IFunctionNode) getNode(code, IFunctionNode.class,
+ WRAP_LEVEL_CLASS, true);
+ }
+
+ protected IExpressionNode getExpressionNode(String code,
+ Class<? extends IASNode> type)
+ {
+ return (IExpressionNode) getNode(code, type);
+ }
+
+ protected IBinaryOperatorNode getBinaryNode(String code)
+ {
+ return (IBinaryOperatorNode) getNode(code, IBinaryOperatorNode.class);
+ }
+
+ protected IForLoopNode getForLoopNode(String code)
+ {
+ return (IForLoopNode) getNode(code, IForLoopNode.class);
+ }
+
+ protected INamespaceAccessExpressionNode getNamespaceAccessExpressionNode(
+ String code)
+ {
+ return (INamespaceAccessExpressionNode) getNode(code,
+ INamespaceAccessExpressionNode.class);
+ }
+
+ protected IDynamicAccessNode getDynamicAccessNode(String code)
+ {
+ return (IDynamicAccessNode) getNode(code, IDynamicAccessNode.class);
+ }
+
+ protected IUnaryOperatorNode getUnaryNode(String code)
+ {
+ return (IUnaryOperatorNode) getNode(code, IUnaryOperatorNode.class);
+ }
+
+ protected IUnaryOperatorNode getUnaryNode(String code, int wrapLevel)
+ {
+ return (IUnaryOperatorNode) getNode(code, IUnaryOperatorNode.class, wrapLevel);
+ }
+
+ protected IVariableNode getVariable(String code)
+ {
+ return (IVariableNode) getNode(code, IVariableNode.class);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/FlexJSTestBase.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/FlexJSTestBase.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/FlexJSTestBase.java
new file mode 100644
index 0000000..203d16a
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/FlexJSTestBase.java
@@ -0,0 +1,140 @@
+/*
+ *
+ * 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.test;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.driver.mxml.flexjs.MXMLFlexJSBackend;
+import org.apache.flex.compiler.internal.mxml.MXMLNamespaceMapping;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.mxml.IMXMLNamespaceMapping;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLNode;
+import org.apache.flex.utils.FilenameNormalization;
+import org.apache.flex.utils.ITestAdapter;
+import org.apache.flex.utils.TestAdapterFactory;
+import org.junit.Ignore;
+
+@Ignore
+public class FlexJSTestBase extends TestBase
+{
+ protected static ITestAdapter testAdapter = TestAdapterFactory.getTestAdapter();
+
+ @Override
+ public void setUp()
+ {
+ project = new FlexJSProject(workspace);
+ super.setUp();
+
+ asEmitter = backend.createEmitter(writer);
+ mxmlEmitter = backend.createMXMLEmitter(writer);
+
+ asBlockWalker = backend.createWalker(project, errors, asEmitter);
+ mxmlBlockWalker = backend.createMXMLWalker(project, errors,
+ mxmlEmitter, asEmitter, asBlockWalker);
+ }
+
+ @Override
+ protected void addLibraries(List<File> libraries)
+ {
+ libraries.add(new File(FilenameNormalization.normalize(env.FPSDK
+ + "/" + env.FPVER + "/playerglobal.swc")));
+ libraries.add(new File(FilenameNormalization.normalize(env.SDK
+ + "/frameworks/libs/framework.swc")));
+ libraries.add(new File(FilenameNormalization.normalize(env.SDK
+ + "\\frameworks\\libs\\rpc.swc")));
+ libraries.add(new File(env.ASJS + "/frameworks/libs/Core.swc"));
+ libraries.add(new File(env.ASJS + "/frameworks/libs/HTML.swc"));
+ libraries.add(new File(env.ASJS + "/frameworks/libs/Binding.swc"));
+ libraries.add(new File(env.ASJS + "/frameworks/libs/Network.swc"));
+ libraries.add(new File(env.ASJS + "/frameworks/libs/Collections.swc"));
+
+ super.addLibraries(libraries);
+ }
+
+ @Override
+ protected void addNamespaceMappings(List<IMXMLNamespaceMapping> namespaceMappings)
+ {
+ namespaceMappings
+ .add(new MXMLNamespaceMapping(
+ "library://ns.apache.org/flexjs/basic", new File(
+ env.ASJS + "/frameworks/as/basic-manifest.xml")
+ .getAbsolutePath()));
+
+ super.addNamespaceMappings(namespaceMappings);
+ }
+
+ @Override
+ protected void addSourcePaths(List<File> sourcePaths)
+ {
+ sourcePaths.add(new File(env.ASJS + "/examples/FlexJSTest_basic/src"));
+ sourcePaths.add(new File(testAdapter.getUnitTestBaseDir(), "flexjs/files"));
+
+ super.addSourcePaths(sourcePaths);
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new MXMLFlexJSBackend();
+ }
+
+ //--------------------------------------------------------------------------
+ // Node "factory"
+ //--------------------------------------------------------------------------
+
+ public static final int WRAP_LEVEL_NONE = 0;
+ public static final int WRAP_LEVEL_DOCUMENT = 1;
+
+ protected IMXMLNode getNode(String code, Class<? extends IMXMLNode> type,
+ int wrapLevel)
+ {
+ if (wrapLevel >= WRAP_LEVEL_DOCUMENT)
+ code = ""
+ + "<basic:Application xmlns:fx=\"http://ns.adobe.com/mxml/2009\" xmlns:basic=\"library://ns.apache.org/flexjs/basic\">"
+ + code + "</basic:Application>";
+
+ IMXMLFileNode node = compileMXML(code);
+
+ return findFirstDescendantOfType(node, type);
+ }
+
+ protected IMXMLNode findFirstDescendantOfType(IMXMLNode node,
+ Class<? extends IMXMLNode> nodeType)
+ {
+
+ int n = node.getChildCount();
+ for (int i = 0; i < n; i++)
+ {
+ IMXMLNode child = (IMXMLNode) node.getChild(i);
+ if (nodeType.isInstance(child))
+ return child;
+
+ IMXMLNode found = findFirstDescendantOfType(child,
+ nodeType);
+ if (found != null)
+ return found;
+ }
+
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/ITestBase.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/ITestBase.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/ITestBase.java
new file mode 100644
index 0000000..9096022
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/test/ITestBase.java
@@ -0,0 +1,25 @@
+/*
+ *
+ * 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.test;
+
+public interface ITestBase
+{
+
+}