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:36 UTC
[09/50] git commit: [flex-falcon]
[refs/heads/feature/maven-migration] - compiler.jx.tests: source map tests
now include destination file positions,
and added some more expressions to tests
compiler.jx.tests: source map tests now include destination file positions, and added some more expressions to tests
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/de367914
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/de367914
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/de367914
Branch: refs/heads/feature/maven-migration
Commit: de3679146286bb5a9daa7fba1f26790d9c90866c
Parents: 285ada9
Author: Josh Tynjala <jo...@apache.org>
Authored: Wed Mar 30 11:38:14 2016 -0700
Committer: Josh Tynjala <jo...@apache.org>
Committed: Wed Mar 30 11:38:14 2016 -0700
----------------------------------------------------------------------
.../js/sourcemaps/TestSourceMapExpressions.java | 258 +++++++++++++++++--
.../internal/test/SourceMapTestBase.java | 27 +-
2 files changed, 261 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/de367914/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
index 7615f25..7b06cc7 100644
--- 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
@@ -23,7 +23,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a + b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
}
@Test
@@ -31,7 +31,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a - b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
}
@Test
@@ -39,7 +39,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a / b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
}
@Test
@@ -47,7 +47,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a % b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
}
@Test
@@ -55,7 +55,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a * b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
}
@Test
@@ -63,7 +63,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IUnaryOperatorNode node = getUnaryNode("a++");
asBlockWalker.visitUnaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getOperandNode().getEnd() - node.getOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 3);
}
@Test
@@ -71,7 +71,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IUnaryOperatorNode node = getUnaryNode("++a");
asBlockWalker.visitUnaryOperator(node);
- assertMapping(node.getLine(), node.getColumn());
+ assertMapping(node, 0, 0, 0, 0, 0, 2);
}
@Test
@@ -79,7 +79,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IUnaryOperatorNode node = getUnaryNode("a--");
asBlockWalker.visitUnaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getOperandNode().getEnd() - node.getOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 3);
}
@Test
@@ -87,7 +87,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IUnaryOperatorNode node = getUnaryNode("--a");
asBlockWalker.visitUnaryOperator(node);
- assertMapping(node.getLine(), node.getColumn());
+ assertMapping(node, 0, 0, 0, 0, 0, 2);
}
//----------------------------------
@@ -99,7 +99,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a += b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
}
@Test
@@ -107,7 +107,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a -= b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
}
@Test
@@ -115,7 +115,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a /= b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
}
@Test
@@ -123,7 +123,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a %= b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
}
@Test
@@ -131,7 +131,7 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a *= b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
}
//----------------------------------
@@ -143,7 +143,235 @@ public class TestSourceMapExpressions extends SourceMapTestBase
{
IBinaryOperatorNode node = getBinaryNode("a = b");
asBlockWalker.visitBinaryOperator(node);
- assertMapping(node.getLine(), node.getColumn() + node.getLeftOperandNode().getEnd() - node.getLeftOperandNode().getStart());
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
+ }
+
+ //----------------------------------
+ // Bitwise
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseAnd()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a & b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseLeftShift()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a << b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_BitwiseNot()
+ {
+ IUnaryOperatorNode node = getUnaryNode("~a");
+ asBlockWalker.visitUnaryOperator(node);
+ assertMapping(node, 0, 0, 0, 0, 0, 1);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseOr()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a | b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseRightShift()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >> b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseUnsignedRightShift()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >>> b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 6);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseXOR()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ^ b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
+ }
+
+ //----------------------------------
+ // Bitwise compound assignment
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseAndAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a &= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseLeftShiftAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a <<= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 6);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseOrAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a |= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseRightShiftAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >>= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 6);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseUnsignedRightShiftAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >>>= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 7);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseXORAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ^= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ //----------------------------------
+ // Comparison
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_Equal()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a == b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_GreaterThan()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a > b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_GreaterThanEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_NotEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a != b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LessThan()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a < b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LessThanEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a <= b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_StrictEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a === b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 6);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_StrictNotEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a !== b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 6);
+ }
+
+ //----------------------------------
+ // Logical
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalAnd()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a && b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalAndAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a &&= b");
+ asBlockWalker.visitBinaryOperator(node);
+ //a = a && b
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
+ assertMapping(node, 0, 1, 0, 5, 0, 9);
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_LogicalNot()
+ {
+ IUnaryOperatorNode node = getUnaryNode("!a");
+ asBlockWalker.visitUnaryOperator(node);
+ assertMapping(node, 0, 0, 0, 0, 0, 1);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalOr()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a || b");
+ asBlockWalker.visitBinaryOperator(node);
+ assertMapping(node, 0, 1, 0, 1, 0, 5);
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalOrAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ||= b");
+ asBlockWalker.visitBinaryOperator(node);
+ //a = a || b
+ assertMapping(node, 0, 1, 0, 1, 0, 4);
+ assertMapping(node, 0, 1, 0, 5, 0, 9);
}
protected IBackend createBackend()
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/de367914/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
index f1c1c25..756674b 100644
--- 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
@@ -1,12 +1,12 @@
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;
+import org.apache.flex.compiler.tree.as.IASNode;
+
+import com.google.debugging.sourcemap.FilePosition;
+import static org.junit.Assert.assertTrue;
public class SourceMapTestBase extends ASTestBase
{
@@ -20,20 +20,29 @@ public class SourceMapTestBase extends ASTestBase
jsEmitter = (IJSEmitter) asEmitter;
}
- protected void assertMapping(int sourceStartLine, int sourceStartColumn)
+ protected void assertMapping(IASNode node, int nodeStartLine, int nodeStartColumn,
+ int outStartLine, int outStartColumn, int outEndLine, int outEndColumn)
{
+ int sourceStartLine = nodeStartLine + node.getLine();
+ int sourceStartColumn = nodeStartColumn + node.getColumn();
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)
+ FilePosition sourcePosition = mapping.sourceStartPosition;
+ FilePosition startPosition = mapping.destStartPosition;
+ FilePosition endPosition = mapping.destEndPosition;
+ if (sourcePosition.getLine() == sourceStartLine
+ && sourcePosition.getColumn() == sourceStartColumn
+ && startPosition.getLine() == outStartLine
+ && startPosition.getColumn() == outStartColumn
+ && endPosition.getLine() == outEndLine
+ && endPosition.getColumn() == outEndColumn)
{
foundMapping = true;
}
}
- assertTrue(foundMapping);
+ assertTrue("Mapping not found for node " + node.toString(), foundMapping);
}
}