You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ms...@apache.org on 2012/12/28 14:06:22 UTC
svn commit: r1426493 - in
/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen:
TestGoogEmiter.java goog/TestGoogEmiter.java
Author: mschmalle
Date: Fri Dec 28 13:06:22 2012
New Revision: 1426493
URL: http://svn.apache.org/viewvc?rev=1426493&view=rev
Log:
Flex:FalconJx
- Missed TestGoogEmiter.java move, now in goog package
Added:
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java (with props)
Removed:
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/TestGoogEmiter.java
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java?rev=1426493&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java Fri Dec 28 13:06:22 2012
@@ -0,0 +1,235 @@
+/*
+ *
+ * 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.js.codegen.goog;
+
+import org.apache.flex.compiler.clients.IBackend;
+import org.apache.flex.compiler.internal.as.codegen.TestWalkerBase;
+import org.apache.flex.compiler.internal.js.codegen.JSSharedData;
+import org.apache.flex.compiler.internal.js.driver.goog.GoogBackend;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Ignore;
+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 TestWalkerBase
+{
+ // emitPackageHeader()
+ // emitImports()
+ // emitClass()
+
+ @Test
+ public void testSimple()
+ {
+ String code = "package com.example.components {"
+ + "import org.apache.flex.html.staticControls.TextButton;"
+ + "public class MyTextButton extends TextButton {"
+ + "public function MyTextButton() {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 = getFileNode(code);
+ visitor.visitFile(node);
+ //assertOut("");
+ }
+
+ @Test
+ public void testSimpleMethod()
+ {
+ JSSharedData.OUTPUT_JSDOC = false;
+ IFunctionNode node = getMethodSimple("function method1():void{\n}");
+ visitor.visitFunction(node);
+ assertOut("A.method1 = function() {\n}");
+ JSSharedData.OUTPUT_JSDOC = true;
+ }
+
+ @Test
+ public void testSimpleParameterReturnType()
+ {
+ JSSharedData.OUTPUT_JSDOC = false;
+ IFunctionNode node = getMethod("function method1(bar:int):int{\n}");
+ visitor.visitFunction(node);
+ assertOut("foo.bar.A.method1 = function(bar) {\n}");
+ JSSharedData.OUTPUT_JSDOC = true;
+ }
+
+ @Test
+ public void testSimpleMultipleParameter()
+ {
+ JSSharedData.OUTPUT_JSDOC = false;
+ IFunctionNode node = getMethod("function method1(bar:int, baz:String, goo:A):void{\n}");
+ visitor.visitFunction(node);
+ assertOut("foo.bar.A.method1 = function(bar, baz, goo) {\n}");
+ JSSharedData.OUTPUT_JSDOC = true;
+ }
+
+ @Ignore
+ @Test
+ public void testSimpleMultipleParameter_JSDoc()
+ {
+ // jsdoc still needs to be sorted out before tests are executing
+ IFunctionNode node = getMethod("function method1(bar:int, baz:String, goo:A):void{\n}");
+ visitor.visitFunction(node);
+ assertOut("/**\n * @this {foo.bar.A}\n * @param {int} bar\n * @param {String} baz\n"
+ + " * @param {A} goo\n * @return {void}\n */\nfoo.bar.A.method1 = "
+ + "function(bar, baz, goo) {\n}");
+ }
+
+ @Test
+ public void testDefaultParameter_NoBody()
+ {
+ /*
+ foo.bar.A.method1 = function(bar, bax) {
+ if (arguments.length < 2) {
+ if (arguments.length < 1) {
+ bar = 42;
+ }
+ bax = 4;
+ }
+ }
+ */
+ JSSharedData.OUTPUT_JSDOC = false;
+ IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{\n}");
+ visitor.visitFunction(node);
+ assertOut("foo.bar.A.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t"
+ + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n}");
+ JSSharedData.OUTPUT_JSDOC = true;
+ }
+
+ @Test
+ public void testDefaultParameter_Body()
+ {
+ /*
+ foo.bar.A.method1 = function(bar, bax) {
+ if (arguments.length < 2) {
+ if (arguments.length < 1) {
+ bar = 42;
+ }
+ bax = 4;
+ }
+ }
+ */
+ JSSharedData.OUTPUT_JSDOC = false;
+ IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{if (a) foo();}");
+ visitor.visitFunction(node);
+ assertOut("foo.bar.A.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t"
+ + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n\t"
+ + "if (a)\n\t\tfoo();\n}");
+ JSSharedData.OUTPUT_JSDOC = true;
+ }
+
+ @Test
+ public void testDefaultParameter()
+ {
+ /*
+ foo.bar.A.method1 = function(p1, p2, p3, p4) {
+ if (arguments.length < 4) {
+ if (arguments.length < 3) {
+ p3 = 3;
+ }
+ p4 = 4;
+ }
+ return p1 + p2 + p3 + p4;
+ }
+ */
+ JSSharedData.OUTPUT_JSDOC = false;
+ IFunctionNode node = getMethod("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{return p1 + p2 + p3 + p4;}");
+ visitor.visitFunction(node);
+ assertOut("foo.bar.A.method1 = function(p1, p2, p3, p4) {\n\tif (arguments.length < 4) "
+ + "{\n\t\tif (arguments.length < 3) {\n\t\t\tp3 = 3;\n\t\t}\n\t\tp4 = 4;\n\t}"
+ + "\n\treturn p1 + p2 + p3 + p4;\n}");
+ JSSharedData.OUTPUT_JSDOC = true;
+ }
+
+ @Test
+ public void testDefaultParameter_Alternate()
+ {
+ /*
+ foo.bar.A.method1 = function(p1, p2, p3, p4) {
+ p3 = typeof p3 !== 'undefined' ? p3 : 3;
+ p4 = typeof p4 !== 'undefined' ? p4 : 4;
+
+ return p1 + p2 + p3 + p4;
+ }
+ */
+ JSSharedData.OUTPUT_JSDOC = false;
+ JSSharedData.OUTPUT_ALTERNATE = true;
+ IFunctionNode node = getMethod("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{return p1 + p2 + p3 + p4;}");
+ visitor.visitFunction(node);
+ assertOut("foo.bar.A.method1 = function(p1, p2, p3, p4) {\n"
+ + "\tp3 = typeof p3 !== 'undefined' ? p3 : 3;\n"
+ + "\tp4 = typeof p4 !== 'undefined' ? p4 : 4;\n"
+ + "\treturn p1 + p2 + p3 + p4;\n}");
+ JSSharedData.OUTPUT_ALTERNATE = false;
+ JSSharedData.OUTPUT_JSDOC = true;
+ }
+
+ @Test
+ public void testDefaultParameter_AlternateNoBody()
+ {
+ /*
+ foo.bar.A.method1 = function(p1, p2, p3, p4) {
+ p3 = typeof p3 !== 'undefined' ? p3 : 3;
+ p4 = typeof p4 !== 'undefined' ? p4 : 4;
+ }
+ */
+ JSSharedData.OUTPUT_JSDOC = false;
+ JSSharedData.OUTPUT_ALTERNATE = true;
+ IFunctionNode node = getMethod("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{}");
+ visitor.visitFunction(node);
+ assertOut("foo.bar.A.method1 = function(p1, p2, p3, p4) {\n"
+ + "\tp3 = typeof p3 !== 'undefined' ? p3 : 3;\n"
+ + "\tp4 = typeof p4 !== 'undefined' ? p4 : 4;\n}");
+ JSSharedData.OUTPUT_ALTERNATE = false;
+ JSSharedData.OUTPUT_JSDOC = true;
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+
+ protected IFunctionNode getMethodSimple(String code)
+ {
+ String source = "package {public class A {" + code + "}}";
+ IFileNode node = getFileNode(source);
+ IFunctionNode child = (IFunctionNode) findFirstDescendantOfType(node,
+ IFunctionNode.class);
+ return child;
+ }
+
+ protected IFunctionNode getMethod(String code)
+ {
+ String source = "package foo.bar {public class A {" + code + "}}";
+ IFileNode node = getFileNode(source);
+ IFunctionNode child = (IFunctionNode) findFirstDescendantOfType(node,
+ IFunctionNode.class);
+ return child;
+ }
+}
Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java
------------------------------------------------------------------------------
svn:eol-style = native