This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit b615ab4692298c1c3227dfece73dbb90211c7e7e
Author: Josh Tynjala <[email protected]>
AuthorDate: Wed Sep 18 08:37:58 2024 -0700

    royale.dependent.tests: fix source maps test
---
 .../mxml/sourcemaps/TestSourceMapMXMLScript.java   |  8 +++--
 .../internal/test/RoyaleSourceMapTestBase.java     | 35 ++++++++++++++++++++--
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git 
a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/mxml/sourcemaps/TestSourceMapMXMLScript.java
 
b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/mxml/sourcemaps/TestSourceMapMXMLScript.java
index 6416831e5..ca4ccbae2 100644
--- 
a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/mxml/sourcemaps/TestSourceMapMXMLScript.java
+++ 
b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/mxml/sourcemaps/TestSourceMapMXMLScript.java
@@ -45,7 +45,8 @@ public class TestSourceMapMXMLScript extends 
RoyaleSourceMapTestBase
         assertTrue(definitionName.startsWith(getClass().getSimpleName()));
         int endColumn = definitionName.length() + 14;
         ///**\n * @package\n * @type {*}\n */\nRoyaleTest_A.prototype.foo
-        assertMapping(node, 0, 4, 43, 0, 43, endColumn);  // foo
+        assertMapping(node, 0, 4, 43, 0, 43, endColumn - 3);  // 
RoyaleTest_A.prototype.
+        assertMapping(node, 0, 4, 43, endColumn - 3, 43, endColumn);  // foo
     }
 
     @Test
@@ -63,9 +64,10 @@ public class TestSourceMapMXMLScript extends 
RoyaleSourceMapTestBase
         assertTrue(definitionName.startsWith(getClass().getSimpleName()));
         int nameEndColumn = definitionName.length() + 14;
         ///**\n * @export\n * @type {*}\n */\nRoyaleTest_A.prototype.foo
-        assertMapping(node, 0, 9, 39, 0, 39, nameEndColumn);  // foo
+        assertMapping(node, 0, 9, 39, 0, 39, nameEndColumn - 3);  // 
RoyaleTest_A.prototype.
+        assertMapping(node, 0, 9, 39, nameEndColumn - 3, 39, nameEndColumn);  
// foo
         assertMapping(node, 0, 0, 39, nameEndColumn, 39, nameEndColumn + 11);  
// = function
-        assertMapping(node, 0, 12, 39, nameEndColumn + 11, 39, nameEndColumn + 
12);  // (
+        assertMapping(node, 0, 12, 39, nameEndColumn + 11, 39, nameEndColumn + 
12, "foo");  // (
         assertMapping(node, 0, 13, 39, nameEndColumn + 12, 39, nameEndColumn + 
13);  // )
         assertMapping(node, 0, 14, 39, nameEndColumn + 14, 39, nameEndColumn + 
15);  // {
         assertMapping(node, 0, 15, 40, 0, 40, 1);  // }
diff --git 
a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/RoyaleSourceMapTestBase.java
 
b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/RoyaleSourceMapTestBase.java
index 749df0ef7..cc37c752e 100644
--- 
a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/RoyaleSourceMapTestBase.java
+++ 
b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/RoyaleSourceMapTestBase.java
@@ -29,7 +29,13 @@ import static org.junit.Assert.assertTrue;
 public class RoyaleSourceMapTestBase extends RoyaleTestBase
 {
     protected void assertMapping(IASNode node, int nodeStartLine, int 
nodeStartColumn,
-                                 int outStartLine, int outStartColumn, int 
outEndLine, int outEndColumn)
+        int outStartLine, int outStartColumn, int outEndLine, int outEndColumn)
+    {
+        assertMapping(node, nodeStartLine, nodeStartColumn, outStartLine, 
outStartColumn, outEndLine, outEndColumn, null);
+    }
+
+    protected void assertMapping(IASNode node, int nodeStartLine, int 
nodeStartColumn,
+        int outStartLine, int outStartColumn, int outEndLine, int 
outEndColumn, String symbolName)
     {
         int sourceStartLine = nodeStartLine + node.getLine();
         int sourceStartColumn = nodeStartColumn;
@@ -50,12 +56,37 @@ public class RoyaleSourceMapTestBase extends RoyaleTestBase
                     && startPosition.getLine() == outStartLine
                     && startPosition.getColumn() == outStartColumn
                     && endPosition.getLine() == outEndLine
-                    && endPosition.getColumn() == outEndColumn)
+                    && endPosition.getColumn() == outEndColumn
+                    && ((symbolName == null && mapping.name == null) || 
(symbolName != null && symbolName.equals(mapping.name))))
             {
                 foundMapping = true;
                 break;
             }
         }
+        // uncomment for debugging
+        // if (!foundMapping)
+        // {
+        //     System.err.println("generated code:");
+        //     System.err.println(writer.toString());
+        //     System.err.println("expected mapping:");
+        //     System.err.println("  name: " + symbolName);
+        //     System.err.println("  node: " + nodeStartLine + ", " + 
nodeStartColumn);
+        //     System.err.println("  source: " + sourceStartLine + ", " + 
sourceStartColumn);
+        //     System.err.println("  start:  " + outStartLine + ", " + 
outStartColumn);
+        //     System.err.println("  end:    " + outEndLine + ", " + 
outEndColumn);
+        //     for (int i = 0; i < mappings.size(); i++)
+        //     {
+        //         IMappingEmitter.SourceMapMapping mapping = mappings.get(i);
+        //         System.err.println("actual mapping (" + i + "):");
+        //         FilePosition sourcePosition = mapping.sourceStartPosition;
+        //         FilePosition startPosition = mapping.destStartPosition;
+        //         FilePosition endPosition = mapping.destEndPosition;
+        //         System.err.println("  name: " + mapping.name);
+        //         System.err.println("  source: " + sourcePosition.getLine() 
+ ", " + sourcePosition.getColumn());
+        //         System.err.println("  start:  " + startPosition.getLine() + 
", " + startPosition.getColumn());
+        //         System.err.println("  end:    " + endPosition.getLine() + 
", " + endPosition.getColumn());
+        //     }
+        // }
         assertTrue("Mapping not found for node " + node.getNodeID() + ". 
Expected "
                         + "source: (" + nodeStartLine + ", " + nodeStartColumn 
+ "), dest: (" + outStartLine + ", " + outStartColumn + ") to (" + outEndLine + 
", " + outEndColumn + ")",
                 foundMapping);

Reply via email to