def test_fuzzy_mapping(self): smap_view = NativeView.from_json(indexed_sourcemap_example) # one.js assert smap_view.lookup_token(0, 20) == \ Token(dst_line=0, dst_col=18, src='/the/root/one.js', src_line=0, src_col=21, src_id=0, name='bar') assert smap_view.lookup_token(0, 30) == \ Token(dst_line=0, dst_col=28, src='/the/root/one.js', src_line=1, src_col=10, src_id=0, name='baz') assert smap_view.lookup_token(1, 12) == \ Token(dst_line=1, dst_col=9, src='/the/root/two.js', src_line=0, src_col=11, src_id=0, name=None)
def test_indexed_inline(self): smap_view = NativeView.from_json(indexed_sourcemap_example) assert smap_view.get_source_contents((0, 0)) == ( ' ONE.foo = function (bar) {\n' + ' return baz(bar);\n' + ' };') assert smap_view.get_source_contents((1, 0)) == ( ' TWO.inc = function (n) {\n' + ' return n + 1;\n' + ' };')
def test_exact_mappings(self): smap_view = NativeView.from_json(indexed_sourcemap_example) # one.js assert smap_view.lookup_token(0, 1) == \ Token(dst_line=0, dst_col=1, src='/the/root/one.js', src_line=0, src_col=1, src_id=0, name=None) assert smap_view.lookup_token(0, 18) == \ Token(dst_line=0, dst_col=18, src='/the/root/one.js', src_line=0, src_col=21, src_id=0, name='bar') assert smap_view.lookup_token(0, 28) == \ Token(dst_line=0, dst_col=28, src='/the/root/one.js', src_line=1, src_col=10, src_id=0, name='baz') # two.js assert smap_view.lookup_token(1, 18) == \ Token(dst_line=1, dst_col=18, src='/the/root/two.js', src_line=0, src_col=21, src_id=0, name='n') assert smap_view.lookup_token(1, 21) == \ Token(dst_line=1, dst_col=21, src='/the/root/two.js', src_line=1, src_col=3, src_id=0, name=None) assert smap_view.lookup_token(1, 21) == \ Token(dst_line=1, dst_col=21, src='/the/root/two.js', src_line=1, src_col=3, src_id=0, name=None)
def test_simple(self): smap_view = NativeView.from_json(sourcemap) result = smap_view.lookup_token(0, 56) assert result == Token(dst_line=0, dst_col=50, src='foo/file2.js', src_line=0, src_col=9, src_id=1, name='multiply') # Start of minified file (exact match first line/col tuple) result = smap_view.lookup_token(0, 0) assert result == Token(dst_line=0, dst_col=0, src='foo/file1.js', src_line=0, src_col=0, src_id=0, name=None) # Last character in mapping result = smap_view.lookup_token(0, 36) assert result == Token(dst_line=0, dst_col=30, src='foo/file1.js', src_line=2, src_col=1, src_id=0, name=None) # First character in mapping (exact match line/col tuple) result = smap_view.lookup_token(0, 37) assert result == Token(dst_line=0, dst_col=37, src='foo/file1.js', src_line=2, src_col=8, src_id=0, name='a') # End of minified file (character *beyond* last line/col tuple) result = smap_view.lookup_token(0, 192) assert result == Token(dst_line=0, dst_col=191, src='foo/file2.js', src_line=9, src_col=25, src_id=1, name='e')
def test_no_inline(self): # basic sourcemap fixture has no inlined sources, so expect None smap_view = NativeView.from_json(sourcemap) source = smap_view.get_source_contents((0, 0)) assert source is None
def test_basic(self): smap_view = NativeView.from_json(sourcemap) assert list(smap_view.iter_sources()) == [ ((0, 0), 'foo/file1.js'), ((0, 1), 'foo/file2.js'), ]