/*
*
* 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.flexjs;
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.flexjs.FlexJSBackend;
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 TestFlexJSStatements extends TestGoogStatements
{
@Override
public void setUp()
{
project = new FlexJSProject(workspace);
super.setUp();
}
@Test
public void testVarDeclaration_withTypeAssignedStringWithNewLine()
{
IVariableNode node = (IVariableNode) getNode("var a:String = \"\\n\"",
IVariableNode.class);
asBlockWalker.visitVariable(node);
assertOut("var /** @type {string} */ a = \"\\n\"");
}
//----------------------------------
// 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;");
}
@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