示例#1
0
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)
示例#2
0
def test_jquery_mmap():
    source, min_map = get_fixtures('jquery')
    index = View.from_json(min_map)

    with tempfile.NamedTemporaryFile() as f:
        f.write(index.dump_memdb())
        f.flush()

        mem_index = View.from_memdb_file(f.name)
        verify_index(mem_index, source)
        verify_token_equivalence(index, mem_index)
        verify_token_search(mem_index)
示例#3
0
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)
示例#4
0
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
示例#5
0
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')]
示例#6
0
def test_react_dom():
    source, min_map = get_fixtures('react-dom')
    index = View.from_json(min_map)
    verify_index(index, source)
    verify_react_token_search(index)
示例#7
0
def test_jquery():
    source, min_map = get_fixtures('jquery')
    index = View.from_json(min_map)
    verify_index(index, source)
示例#8
0
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)
示例#9
0
def test_unicode_names():
    source, min_map = get_fixtures('unicode')
    index = View.from_json(min_map)
    verify_index(index, source)
示例#10
0
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)
示例#11
0
def test_coolstuff():
    source, min_map = get_fixtures('coolstuff')
    index = View.from_json(min_map)
    verify_index(index, source)
示例#12
0
def parse_json(filename):
    with open(filename, 'rb') as f:
        return View.from_json(f.read())