Exemplo n.º 1
0
    def test_fuzzy_mapping(self):
        smap_view = view_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=1,
                                                      name=None)
Exemplo n.º 2
0
    def test_simple(self):
        smap_view = view_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')
Exemplo n.º 3
0
    def test_base64_without_padding(self):
        smap_view = fetch_sourcemap(base64_sourcemap.rstrip('='))
        tokens = [Token(1, 0, '/test.js', 0, 0, 0, None)]

        assert list(smap_view) == tokens
        assert smap_view.get_source_contents(0) == 'console.log("hello, World!")'
        assert smap_view.get_source_name(0) == u'/test.js'
Exemplo n.º 4
0
    def test_simple_base64(self):
        smap_view = fetch_sourcemap(base64_sourcemap)
        tokens = [Token(1, 0, '/test.js', 0, 0, 0, None)]

        assert list(smap_view) == tokens
        assert smap_view.get_source_contents(0) == 'console.log("hello, World!")'
        assert smap_view.get_source_name(0) == u'/test.js'
Exemplo n.º 5
0
    def test_exact_mappings(self):
        smap_view = view_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=1,
                                                      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=1,
                                                      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=1,
                                                      name=None)
Exemplo n.º 6
0
    def test_basic(self):
        index = view_from_json(sourcemap)

        assert list(index) == [
            Token(dst_line=0, dst_col=0, src='foo/file1.js', src_line=0, src_col=0, src_id=0, name=None),
            Token(dst_line=0, dst_col=8, src='foo/file1.js', src_line=0, src_col=9, src_id=0, name='add'),
            Token(dst_line=0, dst_col=13, src='foo/file1.js', src_line=0, src_col=13, src_id=0, name='a'),
            Token(dst_line=0, dst_col=15, src='foo/file1.js', src_line=0, src_col=16, src_id=0, name='b'),
            Token(dst_line=0, dst_col=18, src='foo/file1.js', src_line=1, src_col=1, src_id=0, name=None),
            Token(dst_line=0, dst_col=30, src='foo/file1.js', src_line=2, src_col=1, src_id=0, name=None),
            Token(dst_line=0, dst_col=37, src='foo/file1.js', src_line=2, src_col=8, src_id=0, name='a'),
            Token(dst_line=0, dst_col=40, src='foo/file1.js', src_line=2, src_col=12, src_id=0, name='b'),
            Token(dst_line=0, dst_col=42, src='foo/file2.js', src_line=0, src_col=0, src_id=1, name=None),
            Token(dst_line=0, dst_col=50, src='foo/file2.js', src_line=0, src_col=9, src_id=1, name='multiply'),
            Token(dst_line=0, dst_col=60, src='foo/file2.js', src_line=0, src_col=18, src_id=1, name='a'),
            Token(dst_line=0, dst_col=62, src='foo/file2.js', src_line=0, src_col=21, src_id=1, name='b'),
            Token(dst_line=0, dst_col=65, src='foo/file2.js', src_line=1, src_col=1, src_id=1, name=None),
            Token(dst_line=0, dst_col=77, src='foo/file2.js', src_line=2, src_col=1, src_id=1, name=None),
            Token(dst_line=0, dst_col=84, src='foo/file2.js', src_line=2, src_col=8, src_id=1, name='a'),
            Token(dst_line=0, dst_col=87, src='foo/file2.js', src_line=2, src_col=12, src_id=1, name='b'),
            Token(dst_line=0, dst_col=89, src='foo/file2.js', src_line=4, src_col=0, src_id=1, name=None),
            Token(dst_line=0, dst_col=97, src='foo/file2.js', src_line=4, src_col=9, src_id=1, name='divide'),
            Token(dst_line=0, dst_col=105, src='foo/file2.js', src_line=4, src_col=16, src_id=1, name='a'),
            Token(dst_line=0, dst_col=107, src='foo/file2.js', src_line=4, src_col=19, src_id=1, name='b'),
            Token(dst_line=0, dst_col=110, src='foo/file2.js', src_line=5, src_col=1, src_id=1, name=None),
            Token(dst_line=0, dst_col=122, src='foo/file2.js', src_line=6, src_col=1, src_id=1, name=None),
            Token(dst_line=0, dst_col=127, src='foo/file2.js', src_line=7, src_col=2, src_id=1, name=None),
            Token(dst_line=0, dst_col=133, src='foo/file2.js', src_line=7, src_col=9, src_id=1, name='multiply'),
            Token(dst_line=0, dst_col=143, src='foo/file2.js', src_line=7, src_col=18, src_id=1, name='add'),
            Token(dst_line=0, dst_col=147, src='foo/file2.js', src_line=7, src_col=22, src_id=1, name='a'),
            Token(dst_line=0, dst_col=149, src='foo/file2.js', src_line=7, src_col=25, src_id=1, name='b'),
            Token(dst_line=0, dst_col=152, src='foo/file2.js', src_line=7, src_col=29, src_id=1, name='a'),
            Token(dst_line=0, dst_col=154, src='foo/file2.js', src_line=7, src_col=32, src_id=1, name='b'),
            Token(dst_line=0, dst_col=157, src='foo/file2.js', src_line=7, src_col=37, src_id=1, name='c'),
            Token(dst_line=0, dst_col=159, src='foo/file2.js', src_line=8, src_col=3, src_id=1, name=None),
            Token(dst_line=0, dst_col=165, src='foo/file2.js', src_line=8, src_col=10, src_id=1, name='e'),
            Token(dst_line=0, dst_col=168, src='foo/file2.js', src_line=9, src_col=2, src_id=1, name='Raven'),
            Token(dst_line=0, dst_col=174, src='foo/file2.js', src_line=9, src_col=8, src_id=1, name='captureException'),
            Token(dst_line=0, dst_col=191, src='foo/file2.js', src_line=9, src_col=25, src_id=1, name='e'),
        ]