Exemple #1
0
    def test_writer_use_strict(self):
        # this mimicks calmjs.rjs umd header/footer
        stream = StringIO()
        writer = vlqsm.SourceWriter(stream)
        writer.write_padding('define(\n')
        writer.write_padding('    function(require, exports, module) {\n')
        writer.write('"use strict";\n')
        writer.write_padding('        var exports = {}\n')
        writer.write('console.log("hello world");\n')
        writer.write('console.log("welcome");\n')
        writer.write('console.log("goodbye world");\n')
        writer.write_padding('});\n')

        self.assertEqual(writer.mappings, [
            [],
            [],
            [(0, 0, 0, 0,)],
            [],
            [(0, 0, 1, 0,)],
            [(0, 0, 1, 0,)],
            [(0, 0, 1, 0,)],
            [],
            [],
        ])

        self.assertEqual(stream.getvalue(), (
            'define(\n'
            '    function(require, exports, module) {\n'
            '"use strict";\n'
            '        var exports = {}\n'
            'console.log("hello world");\n'
            'console.log("welcome");\n'
            'console.log("goodbye world");\n'
            '});\n'
        ))
Exemple #2
0
    def test_writer_hf_discarded_indented_source(self):
        stream = StringIO()
        writer = vlqsm.SourceWriter(stream)
        writer.write_padding('define(function(require, exports, module) {\n')
        writer.discard('\n')
        writer.write('console.log("hello world");\n')
        writer.write('console.log("welcome");\n')
        writer.write('console.log("goodbye world");\n')
        writer.write_padding('});\n')

        self.assertEqual(writer.mappings, [
            [],
            [(0, 0, 1, 0,)],
            [(0, 0, 1, 0,)],
            [(0, 0, 1, 0,)],
            [],
            [],
        ])

        self.assertEqual(stream.getvalue(), (
            'define(function(require, exports, module) {\n'
            'console.log("hello world");\n'
            'console.log("welcome");\n'
            'console.log("goodbye world");\n'
            '});\n'
        ))
Exemple #3
0
    def test_writer_write_padding(self):
        stream = StringIO()
        writer = vlqsm.SourceWriter(stream)
        writer.write_padding('hello\n')
        writer.write_padding('hello\n')
        writer.write_padding('hello\n')

        self.assertEqual(stream.getvalue(), 'hello\nhello\nhello\n')
        self.assertEqual(writer.mappings, [
            [], [], [], []
        ])
Exemple #4
0
    def test_writer_single_line(self):
        # just documenting the partial support for line tracking.
        stream = StringIO()
        writer = vlqsm.SourceWriter(stream)
        writer.write('hello ')
        writer.write('hello ')
        writer.write('hello ')

        self.assertEqual(stream.getvalue(), 'hello hello hello ')
        self.assertEqual(writer.mappings, [
            [(0, 0, 0, 0,), (6, 0, 0, 6,), (6, 0, 0, 6,)]
        ])
Exemple #5
0
    def test_writer_base(self):
        stream = StringIO()
        writer = vlqsm.SourceWriter(stream)
        writer.write('hello\n')
        writer.write('hello\n')
        writer.write('hello\n')

        self.assertEqual(stream.getvalue(), 'hello\nhello\nhello\n')
        self.assertEqual(writer.mappings, [
            [(0, 0, 0, 0,)],
            [(0, 0, 1, 0,)],
            [(0, 0, 1, 0,)],
            [],
        ])
Exemple #6
0
    def test_writer_hf_deindented_source(self):
        stream = StringIO()
        writer = vlqsm.SourceWriter(stream)
        writer.write_padding('define(function(require, exports, module) {\n')

        with pretty_logging(stream=StringIO()) as s:
            writer.discard('    ')
            writer.write('console.log("hello world");\n')
            writer.discard('    ')
            writer.write('console.log("welcome");\n')
            writer.discard('    ')
            writer.write('console.log("goodbye world");\n')
            writer.write_padding('});\n')

        self.assertIn('partial line discard UNSUPPORTED;', s.getvalue())
        self.assertEqual(1, len(s.getvalue().splitlines()))

        self.assertEqual(writer.mappings, [
            [],
            # if this is supported, it should be this:
            # [(0, 0, 0, 4,)],
            # with remaining
            # [(0, 0, 1, 0,)],
            # however, to track this it will take more work than I
            # care to give to figure this out for all the possible
            # cases
            [(0, 0, 0, 0,)],
            [(0, 0, 1, 0,)],
            [(0, 0, 1, 0,)],
            [],
            [],
        ])

        self.assertEqual(stream.getvalue(), (
            'define(function(require, exports, module) {\n'
            'console.log("hello world");\n'
            'console.log("welcome");\n'
            'console.log("goodbye world");\n'
            '});\n'
        ))