Beispiel #1
0
        public static void AssertMapping(
            int generatedLine,
            int generatedColumn,
            string originalSource,
            int?originalLine,
            int?originalColumn,
            string name,
            SourceMap map)
        {
            var mapping = map.OriginalPositionFor(generatedLine, generatedColumn);

            Assert.NotNull(mapping);
            Assert.Equal(name, mapping?.OriginalName);
            Assert.Equal(originalLine ?? 0, mapping?.OriginalLineNumber);
            Assert.Equal(originalColumn ?? 0, mapping?.OriginalColumnNumber);

            var expectedSource = (originalSource, map.SourceRoot) switch
            {
                var(source, root) when source?.IndexOf(root) == 0 => source,
                var(source, root) when source != null && root != null => Path.Join(root, source),
                var(source, root) when source != null => source,
                _ => null,
            };

            Assert.Equal(expectedSource, mapping?.OriginalFileName);
        }
        public void Parse_OriginalPositionFor()
        {
            var map = new SourceMap
            {
                Mappings = new List <SourceMapMappingEntry>
                {
                    new SourceMapMappingEntry(2, 2, 1, 1, null,
                                              "foo/bar/bang.coffee"),
                }
            };

            var pos = map.OriginalPositionFor(3, 2).Value;

            Assert.Equal("foo/bar/bang.coffee", pos.OriginalFileName);
            Assert.Equal(1, pos.OriginalLineNumber);
            Assert.Equal(1, pos.OriginalColumnNumber);
        }