def test_expand_source_map(): compressed = "-1:-1:0:-;;13:42:1;:21;::0:o;:::-;1::1;" expanded = [ [-1, -1, 0, "-"], [-1, -1, 0, None], [13, 42, 1, None], [13, 21, 1, None], [13, 21, 0, "o"], [13, 21, 0, "-"], [1, 21, 1, None], ] assert expand_source_map(compressed) == expanded
def test_pos_map_offsets(): source_map = compile_code(TEST_CODE, ["source_map"])["source_map"] expanded = expand_source_map(source_map["pc_pos_map_compressed"]) pc_iter = iter(source_map["pc_pos_map"][i] for i in sorted(source_map["pc_pos_map"])) jump_iter = iter(source_map["pc_jump_map"][i] for i in sorted(source_map["pc_jump_map"])) code_lines = [i + "\n" for i in TEST_CODE.split("\n")] for item in expanded: if item[-1] is not None: assert next(jump_iter) == item[-1] if item[:2] != [-1, -1]: start, length = item[:2] lineno, col_offset, end_lineno, end_col_offset = next(pc_iter) assert code_lines[lineno - 1][col_offset] == TEST_CODE[start] assert length == ( sum(len(i) for i in code_lines[lineno - 1:end_lineno]) - col_offset - (len(code_lines[end_lineno - 1]) - end_col_offset))