def test_react_dom_memdb(): source, min_map = get_fixtures('react-dom') index = View.from_json(min_map) mem_index = View.from_memdb(index.dump_memdb()) verify_index(mem_index, source) verify_react_token_search(mem_index) verify_token_equivalence(index, mem_index)
def test_memdb_dumping(): source, min_map = get_fixtures('react-dom-full') index = View.from_json(min_map) full_mem_index = View.from_memdb(index.dump_memdb()) nosource_mem_index = View.from_memdb( index.dump_memdb(with_source_contents=False)) nonames_mem_index = View.from_memdb(index.dump_memdb(with_names=False)) for t1, t2, t3 in zip(full_mem_index, nosource_mem_index, nonames_mem_index): if t1.name is None: continue assert t1.name == t2.name assert t3.name is None assert full_mem_index.get_source_contents(0) is not None assert full_mem_index.get_source_contents(0) == \ nonames_mem_index.get_source_contents(0) assert nosource_mem_index.get_source_contents(0) is None
def test_source_access(): source, min_map = get_fixtures('react-dom-full') index = View.from_json(min_map) assert index.get_source_contents(0) is not None assert index.has_source_contents(0) assert index.get_source_contents(1) is None assert not index.has_source_contents(1) mem_index = View.from_memdb(index.dump_memdb()) assert mem_index.get_source_contents(0) is not None assert mem_index.has_source_contents(0) assert mem_index.get_source_contents(1) is None assert not mem_index.has_source_contents(1)
def test_source_iteration(): source, min_map = get_fixtures('react-dom') index = View.from_json(min_map) mem_index = View.from_memdb(index.dump_memdb()) assert list(index.iter_sources()) == [(0, u'react-dom.js')] assert list(mem_index.iter_sources()) == [(0, u'react-dom.js')]
def test_unicode_names_memdb(): source, min_map = get_fixtures('unicode') index = View.from_json(min_map) mem_index = View.from_memdb(index.dump_memdb()) verify_index(mem_index, source) verify_token_equivalence(index, mem_index)
def test_coolstuff_memdb(): source, min_map = get_fixtures('coolstuff') index = View.from_json(min_map) mem_index = View.from_memdb(index.dump_memdb()) verify_index(mem_index, source) verify_token_equivalence(index, mem_index)
def load_memdb(filename): with open(filename) as f: return View.from_memdb(f.read())