Exemplo n.º 1
0
def test_bc_l1_def_first_formatting():
    tree = parse(bigcode)
    path = [0, "first_formatting"]
    assert path_to_bounding_box(tree, path) == ((1, 4), (1, 4))

    path = [0, "first_formatting", 0]
    assert path_to_bounding_box(tree, path) == ((1, 4), (1, 4))

    path = [0, "first_formatting", 0, "value"]
    check_path(bigcode, [(1, 4)], path)
Exemplo n.º 2
0
def test_bc_l1_def_first_formatting():
    tree = parse(bigcode)
    path = [0, "first_formatting"]
    assert path_to_bounding_box(tree, path) == ((1, 4), (1, 4))

    path = [0, "first_formatting", 0]
    assert path_to_bounding_box(tree, path) == ((1, 4), (1, 4))

    path = [0, "first_formatting", 0, "value"]
    check_path(bigcode, [(1, 4)], path)
Exemplo n.º 3
0
def check_path(code, positions, target_path):
    tree = parse(code)

    for position in positions:
        path = position_to_path(tree, position)
        assert path == target_path

        if path is None:
            assert position_to_node(tree, position) is None
            return

        node = path_to_node(tree, path)
        assert isinstance(node, string_instance)

        assert position_to_node(tree, position) is node

    if target_path is not None:
        bounding_box = (positions[0], positions[-1])
        assert path_to_bounding_box(tree, path) == bounding_box
Exemplo n.º 4
0
def check_path(code, positions, target_path):
    tree = parse(code)

    for (line, column) in positions:
        path = position_to_path(tree, line, column)
        assert path == target_path

        if path is None:
            assert position_to_node(tree, line, column) is None
            return

        node = path_to_node(tree, path)
        assert isinstance(node, string_instance)

        assert position_to_node(tree, line, column) is node

    if target_path is not None:
        bounding_box = (positions[0], positions[-1])
        assert path_to_bounding_box(tree, path) == bounding_box
Exemplo n.º 5
0
def test_bc_l1_def_second_formatting():
    path = [0, "second_formatting"]
    tree = parse(bigcode)
    assert path_to_bounding_box(tree, path) == ((1, 8), (1, 7))
Exemplo n.º 6
0
def test_bb_comment():
    node = parse("# comment")[0]
    assert path_to_bounding_box(node, None) == ((1, 1), (1, 9))
Exemplo n.º 7
0
def test_bb_string():
    node = parse("\"hello\"")[0]
    assert path_to_bounding_box(node, []) == ((1, 1), (1, 7))
Exemplo n.º 8
0
def test_bc_l1_def_second_formatting():
    path = [0, "second_formatting"]
    tree = parse(bigcode)
    assert path_to_bounding_box(tree, path) == ((1, 8), (1, 7))
Exemplo n.º 9
0
def test_bb_comment():
    node = parse("# comment")[0]
    assert path_to_bounding_box(node, None) == ((1, 1), (1, 9))
Exemplo n.º 10
0
def test_bb_string():
    node = parse("\"hello\"")[0]
    assert path_to_bounding_box(node, []) == ((1, 1), (1, 7))