コード例 #1
0
        public void FlattenMap_MultipleOriginalLineToSameGeneratedLine_ReturnsFirstOriginalLine()
        {
            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 2);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 2);
            MappingEntry   mappingEntry = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceOne.js");

            SourcePosition generated2    = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 3);
            SourcePosition original2     = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5);
            MappingEntry   mappingEntry2 = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js");

            SourceMap map = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mappingEntry, mappingEntry2
                }
            };

            // Act
            SourceMap linesOnlyMap = SourceMapTransformer.Flatten(map);

            // Assert
            Assert.IsNotNull(linesOnlyMap);
            Assert.AreEqual(1, linesOnlyMap.Sources.Count);
            Assert.AreEqual(1, linesOnlyMap.ParsedMappings.Count);
            Assert.AreEqual(1, linesOnlyMap.ParsedMappings[0].GeneratedSourcePosition.ZeroBasedLineNumber);
            Assert.AreEqual(0, linesOnlyMap.ParsedMappings[0].GeneratedSourcePosition.ZeroBasedColumnNumber);
            Assert.AreEqual(2, linesOnlyMap.ParsedMappings[0].OriginalSourcePosition.ZeroBasedLineNumber);
            Assert.AreEqual(0, linesOnlyMap.ParsedMappings[0].OriginalSourcePosition.ZeroBasedColumnNumber);
        }
コード例 #2
0
        public void FlattenMap_ReturnsOnlyLineInformation()
        {
            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 2);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 2);
            MappingEntry   mappingEntry = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceOne.js");

            SourceMap map = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mappingEntry
                },
                SourcesContent = new List <string> {
                    "var a = b"
                }
            };

            // Act
            SourceMap linesOnlyMap = SourceMapTransformer.Flatten(map);

            // Assert
            Assert.NotNull(linesOnlyMap);
            Assert.Equal(1, linesOnlyMap.Sources.Count);
            Assert.Equal(1, linesOnlyMap.SourcesContent.Count);
            Assert.Equal(1, linesOnlyMap.ParsedMappings.Count);
            Assert.Equal(1, linesOnlyMap.ParsedMappings[0].GeneratedSourcePosition.ZeroBasedLineNumber);
            Assert.Equal(0, linesOnlyMap.ParsedMappings[0].GeneratedSourcePosition.ZeroBasedColumnNumber);
            Assert.Equal(2, linesOnlyMap.ParsedMappings[0].OriginalSourcePosition.ZeroBasedLineNumber);
            Assert.Equal(0, linesOnlyMap.ParsedMappings[0].OriginalSourcePosition.ZeroBasedColumnNumber);
        }
コード例 #3
0
        public void ApplyMap_ExactMatchDeep_ReturnsCorrectMappingEntry()
        {
            // Arrange
            SourcePosition generated1 = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5);
            SourcePosition original1  = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 10);
            MappingEntry   mapLevel2  = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceThree.js");

            SourceMap grandChildMap = new SourceMap
            {
                File    = "sourceTwo.js",
                Sources = new List <string> {
                    "sourceThree.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapLevel2
                }
            };

            SourcePosition generated2 = UnitTestUtils.generateSourcePosition(lineNumber: 4, colNumber: 3);
            SourcePosition original2  = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5);
            MappingEntry   mapLevel1  = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceTwo.js");

            SourceMap childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapLevel1
                }
            };

            SourcePosition generated3 = UnitTestUtils.generateSourcePosition(lineNumber: 5, colNumber: 5);
            SourcePosition original3  = UnitTestUtils.generateSourcePosition(lineNumber: 4, colNumber: 3);
            MappingEntry   mapLevel0  = UnitTestUtils.getSimpleEntry(generated3, original3, "sourceOne.js");

            SourceMap parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapLevel0
                }
            };

            // Act
            SourceMap firstCombinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(firstCombinedMap);
            SourceMap secondCombinedMap = firstCombinedMap.ApplySourceMap(grandChildMap);

            Assert.IsNotNull(secondCombinedMap);
            MappingEntry rootMapping = secondCombinedMap.GetMappingEntryForGeneratedSourcePosition(generated3);

            Assert.AreEqual(0, rootMapping.OriginalSourcePosition.CompareTo(mapLevel2.OriginalSourcePosition));
        }
コード例 #4
0
        public void FlattenMap_ReturnsOnlyLineInformation()
        {
            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 2);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 2);
            MappingEntry   mappingEntry = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceOne.js");

            SourceMap map = new SourceMap(
                version: default,
コード例 #5
0
        public void ApplyMap_PartialMatchingSources_ReturnsCorrectMap()
        {
            // Expect mappings with same source filename as the applied source-map to be replaced
            // mappings with a different source filename should stay the same

            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 10);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 5);
            MappingEntry   childMapping = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceTwo.js");

            SourceMap childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    childMapping
                }
            };

            SourcePosition generated2 = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 2);
            SourcePosition original2  = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 10);
            MappingEntry   mapping    = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js");

            SourcePosition generated3 = UnitTestUtils.generateSourcePosition(lineNumber: 4, colNumber: 3);
            SourcePosition original3  = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 2);
            MappingEntry   mapping2   = UnitTestUtils.getSimpleEntry(generated3, original3, "noMapForThis.js");

            SourceMap parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js", "noMapForThis.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapping, mapping2
                }
            };

            // Act
            SourceMap combinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(combinedMap);
            Assert.AreEqual(2, combinedMap.ParsedMappings.Count);
            Assert.AreEqual(2, combinedMap.Sources.Count);
            MappingEntry firstCombinedMapping = combinedMap.GetMappingEntryForGeneratedSourcePosition(generated3);

            Assert.IsTrue(firstCombinedMapping.IsValueEqual(mapping2));
            MappingEntry secondCombinedMapping = combinedMap.GetMappingEntryForGeneratedSourcePosition(generated2);

            Assert.AreEqual(0, secondCombinedMapping.OriginalSourcePosition.CompareTo(childMapping.OriginalSourcePosition));
        }
コード例 #6
0
        public void ApplyMap_MatchingSources_ReturnsCorrectMap()
        {
            // Expect mapping with same source filename as the applied source-map to be replaced

            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 4);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 3);
            MappingEntry   childMapping = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceTwo.js");

            SourceMap childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    childMapping
                }
            };

            SourcePosition generated2    = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5);
            SourcePosition original2     = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 4);
            MappingEntry   parentMapping = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js");

            SourceMap parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    parentMapping
                }
            };

            // Act
            SourceMap combinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(combinedMap);
            Assert.AreEqual(1, combinedMap.ParsedMappings.Count);
            Assert.AreEqual(1, combinedMap.Sources.Count);
            MappingEntry rootMapping = combinedMap.GetMappingEntryForGeneratedSourcePosition(generated2);

            Assert.AreEqual(0, rootMapping.OriginalSourcePosition.CompareTo(childMapping.OriginalSourcePosition));
        }
コード例 #7
0
        public void ApplyMap_NoMatchingMappings_ReturnsSameMap()
        {
            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 2);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 10);
            MappingEntry   childMapping = UnitTestUtils.getSimpleEntry(generated1, original1, "sourceTwo.js");

            SourceMap childMap = new SourceMap
            {
                File    = "sourceOne.js",
                Sources = new List <string> {
                    "sourceTwo.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    childMapping
                }
            };

            SourcePosition generated2    = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 4);
            SourcePosition original2     = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 5);
            MappingEntry   parentMapping = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js");

            SourceMap parentMap = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    parentMapping
                }
            };

            // Act
            SourceMap combinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.IsNotNull(combinedMap);
            MappingEntry firstMapping = combinedMap.ParsedMappings[0];

            Assert.IsTrue(firstMapping.IsValueEqual(parentMapping));
        }
コード例 #8
0
        public void ApplyMap_NoMatchingSources_ReturnsSameMap()
        {
            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 3);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 2);
            MappingEntry   childMapping = UnitTestUtils.getSimpleEntry(generated1, original1, "someOtherSource.js");

            SourceMap childMap = CreateSourceMap(
                file: "notSourceOne.js",
                sources: new List <string>()
            {
                "someOtherSource.js"
            },
                parsedMappings: new List <MappingEntry> {
                childMapping
            });

            SourcePosition generated2    = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 7);
            SourcePosition original2     = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 3);
            MappingEntry   parentMapping = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js");

            SourceMap parentMap = CreateSourceMap(
                file: "generated.js",
                sources: new List <string>()
            {
                "sourceOne.js"
            },
                parsedMappings: new List <MappingEntry> {
                parentMapping
            });

            // Act
            SourceMap combinedMap = parentMap.ApplySourceMap(childMap);

            // Assert
            Assert.NotNull(combinedMap);
            MappingEntry firstMapping = combinedMap.ParsedMappings[0];

            Assert.True(firstMapping.Equals(parentMapping));
        }
コード例 #9
0
        public void ApplyMap_NullSubmap_ThrowsException()
        {
            // Arrange
            SourcePosition generated2 = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5);
            SourcePosition original2  = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 5);
            MappingEntry   mapping    = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js");

            SourceMap map = CreateSourceMap(
                file: "generated.js",
                sources: new List <string>()
            {
                "sourceOne.js"
            },
                parsedMappings: new List <MappingEntry> {
                mapping
            });

            // Act
            Assert.Throws <ArgumentNullException>(() => map.ApplySourceMap(null));

            // Assert (decorated expected exception)
        }
コード例 #10
0
        public void GetRootMappingEntryForGeneratedSourcePosition_NoChildren_ReturnsSameEntry()
        {
            // Arrange
            SourcePosition generated1   = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 5);
            SourcePosition original1    = UnitTestUtils.generateSourcePosition(lineNumber: 1, colNumber: 5);
            MappingEntry   mappingEntry = UnitTestUtils.getSimpleEntry(generated1, original1, "generated.js");

            SourceMap sourceMap = CreateSourceMap(
                sources: new List <string>()
            {
                "generated.js"
            },
                parsedMappings: new List <MappingEntry> {
                mappingEntry
            });

            // Act
            MappingEntry?rootEntry = sourceMap.GetMappingEntryForGeneratedSourcePosition(generated1);

            // Assert
            Assert.Equal(rootEntry, mappingEntry);
        }
コード例 #11
0
        public void ApplyMap_NullSubmap_ThrowsException()
        {
            // Arrange
            SourcePosition generated2 = UnitTestUtils.generateSourcePosition(lineNumber: 3, colNumber: 5);
            SourcePosition original2  = UnitTestUtils.generateSourcePosition(lineNumber: 2, colNumber: 5);
            MappingEntry   mapping    = UnitTestUtils.getSimpleEntry(generated2, original2, "sourceOne.js");

            SourceMap map = new SourceMap
            {
                File    = "generated.js",
                Sources = new List <string> {
                    "sourceOne.js"
                },
                ParsedMappings = new List <MappingEntry> {
                    mapping
                }
            };

            // Act
            SourceMap combinedMap = map.ApplySourceMap(null);

            // Assert (decorated expected exception)
        }