def test_multiple_call(self): stream = StringIO() fragments1 = [ ('a', 1, 1, 'console', 'demo1.js'), ('.', 1, 8, None, 'demo1.js'), ('log', 1, 9, None, 'demo1.js'), ('(', 1, 12, None, 'demo1.js'), ('"hello world"', 1, 13, None, 'demo1.js'), (')', 1, 26, None, 'demo1.js'), (';', 1, 27, None, 'demo1.js'), ] fragments2 = [ ('a', 1, 1, 'console', 'demo2.js'), ('.', 1, 8, None, 'demo2.js'), ('log', 1, 9, None, 'demo2.js'), ('(', 1, 12, None, 'demo2.js'), ('"hello world"', 1, 13, None, 'demo2.js'), (')', 1, 26, None, 'demo2.js'), (';', 1, 27, None, 'demo2.js'), ] book = sourcemap.default_book() sources = sourcemap.Names() names = sourcemap.Names() mappings, _, _ = sourcemap.write( fragments1, stream, book=book, sources=sources, names=names, # Note that normalization is NOT supported until the last # step. normalize=False, ) mappings, sources, namelist = sourcemap.write(fragments2, stream, book=book, sources=sources, names=names, mappings=mappings) self.assertEqual(stream.getvalue(), 'a.log("hello world");a.log("hello world");') self.assertEqual(namelist, ['console']) self.assertEqual(sources, ['demo1.js', 'demo2.js']) self.assertEqual(mappings, [ [(0, 0, 0, 0, 0), (1, 0, 0, 7), (20, 1, 0, -7, 0), (1, 0, 0, 7)], ])
def test_null(self): names = sourcemap.Names() self.assertIs(names.update(None), None) self.assertEqual(list(names), []) self.assertEqual(names.update('hello'), 0) self.assertEqual(names.update('hello'), 0) self.assertIs(names.update(None), None) self.assertEqual(names.update('goodbye'), 1) self.assertEqual(names.update('goodbye'), 0)
def test_name_update(self): names = sourcemap.Names() self.assertEqual(names.update('hello'), 0) self.assertEqual(names.update('hello'), 0) self.assertEqual(names.update('world'), 1) self.assertEqual(names.update('world'), 0) self.assertEqual(names.update('hello'), -1) self.assertEqual(names.update('hello'), 0) self.assertEqual(names.update('goodbye'), 2) self.assertEqual(names.update('hello'), -2) self.assertEqual(names.update('goodbye'), 2) self.assertEqual(names.update('goodbye'), 0) self.assertEqual(names.update('goodbye'), 0) self.assertEqual(names.update('goodbye'), 0) self.assertEqual(names.update('world'), -1) self.assertEqual(names.update('person'), 2) self.assertEqual(names.update('people'), 1) self.assertEqual(names.update('people'), 0) self.assertEqual(names.update('hello'), -4) self.assertEqual( list(names), ['hello', 'world', 'goodbye', 'person', 'people'])
def test_not_implemented(self): names = sourcemap.Names() self.assertEqual(names.update(NotImplemented), 0) self.assertEqual(list(names), [NotImplemented])