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/11 15:59:33 UTC

[06/50] git commit: [flex-falcon] [refs/heads/feature/maven-migration] - compiler.jx.tests: starting to test source maps

compiler.jx.tests: starting to test source maps


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/74cb4439
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/74cb4439
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/74cb4439

Branch: refs/heads/feature/maven-migration
Commit: 74cb443907cd374d4f6f77ed4e47f93b3baa942f
Parents: 1aba54f
Author: Josh Tynjala <jo...@apache.org>
Authored: Tue Mar 29 16:20:14 2016 -0700
Committer: Josh Tynjala <jo...@apache.org>
Committed: Tue Mar 29 16:20:14 2016 -0700

----------------------------------------------------------------------
 .../js/sourcemaps/TestSourceMapExpressions.java | 153 +++++++++++++++++++
 .../internal/test/SourceMapTestBase.java        |  39 +++++
 2 files changed, 192 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/74cb4439/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapExpressions.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapExpressions.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapExpressions.java
new file mode 100644
index 0000000..7615f25
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapExpressions.java
@@ -0,0 +1,153 @@
+package org.apache.flex.compiler.internal.codegen.js.sourcemaps;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
+import org.apache.flex.compiler.internal.test.SourceMapTestBase;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
+
+import org.junit.Test;
+
+public class TestSourceMapExpressions extends SourceMapTestBase
+{
+    //----------------------------------
+    // Primary expression keywords
+    //----------------------------------
+
+    //----------------------------------
+    // Arithmetic
+    //----------------------------------
+
+    @Test
+    public void testVisitBinaryOperatorNode_Plus()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a + b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_Minus()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a - b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_Divide()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a / b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_Modulo()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a % b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_Multiply()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a * b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitUnaryOperatorNode_PostIncrement()
+    {
+        IUnaryOperatorNode node = getUnaryNode("a++");
+        asBlockWalker.visitUnaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getOperandNode().getEnd() - node.getOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitUnaryOperatorNode_PreIncrement()
+    {
+        IUnaryOperatorNode node = getUnaryNode("++a");
+        asBlockWalker.visitUnaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn());
+    }
+
+    @Test
+    public void testVisitUnaryOperatorNode_PostDecrement()
+    {
+        IUnaryOperatorNode node = getUnaryNode("a--");
+        asBlockWalker.visitUnaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getOperandNode().getEnd() - node.getOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitUnaryOperatorNode_PreDecrement()
+    {
+        IUnaryOperatorNode node = getUnaryNode("--a");
+        asBlockWalker.visitUnaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn());
+    }
+
+    //----------------------------------
+    // Arithmetic compound assignment
+    //----------------------------------
+
+    @Test
+    public void testVisitBinaryOperatorNode_PlusAssignment()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a += b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_MinusAssignment()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a -= b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_DivideAssignment()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a /= b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_ModuloAssignment()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a %= b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_MultiplyAssignment()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a *= b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    //----------------------------------
+    // Assignment
+    //----------------------------------
+
+    @Test
+    public void testVisitBinaryOperatorNode_Assignment()
+    {
+        IBinaryOperatorNode node = getBinaryNode("a = b");
+        asBlockWalker.visitBinaryOperator(node);
+        assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+    }
+
+    protected IBackend createBackend()
+    {
+        return new FlexJSBackend();
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/74cb4439/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/SourceMapTestBase.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/SourceMapTestBase.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/SourceMapTestBase.java
new file mode 100644
index 0000000..f1c1c25
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/SourceMapTestBase.java
@@ -0,0 +1,39 @@
+package org.apache.flex.compiler.internal.test;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import com.google.debugging.sourcemap.FilePosition;
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+
+public class SourceMapTestBase extends ASTestBase
+{
+    protected IJSEmitter jsEmitter;
+    
+    @Override
+    public void setUp()
+    {
+        super.setUp();
+
+        jsEmitter = (IJSEmitter) asEmitter;
+    }
+
+    protected void assertMapping(int sourceStartLine, int sourceStartColumn)
+    {
+        boolean foundMapping = false;
+        List<IJSEmitter.SourceMapMapping> mappings = jsEmitter.getSourceMapMappings();
+        for (IJSEmitter.SourceMapMapping mapping : mappings)
+        {
+            FilePosition position = mapping.sourceStartPosition;
+            if(position.getLine() == sourceStartLine
+                    && position.getColumn() == sourceStartColumn)
+            {
+                foundMapping = true;
+            }
+        }
+        assertTrue(foundMapping);
+    }
+    
+}