from vyper import ast as vy_ast


def test_output_class():
    old_node = vy_ast.parse_to_ast("foo = 42")
    new_node = vy_ast.Int.from_node(old_node, value=666)

    assert isinstance(new_node, vy_ast.Int)


def test_source():
    old_node = vy_ast.parse_to_ast("foo = 42")
    new_node = vy_ast.Int.from_node(old_node, value=666)

    assert old_node.src == new_node.src
    assert old_node.node_source_code == new_node.node_source_code


def test_kwargs():
    old_node = vy_ast.parse_to_ast("42").body[0].value
    new_node = vy_ast.Int.from_node(old_node, value=666)

    assert old_node.value == 42
    assert new_node.value == 666


def test_compare_nodes():
    old_node = vy_ast.parse_to_ast("foo = 42")
    new_node = vy_ast.Int.from_node(old_node, value=666)

    assert not vy_ast.compare_nodes(old_node, new_node)


def test_new_node_has_no_parent():
    old_node = vy_ast.parse_to_ast("foo = 42")
    new_node = vy_ast.Int.from_node(old_node, value=666)

    assert new_node._parent is None
    assert new_node._depth == 0

[((5, 15, 5, 46), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', ({(5, 35, 5, 45): '"""foo = 42"""'}, {}), "('foo = 42')", True, 'from vyper import ast as vy_ast\n'), ((6, 15, 6, 56), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (), '', True, 'from vyper import ast as vy_ast\n'), ((12, 15, 12, 46), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', ({(12, 35, 12, 45): '"""foo = 42"""'}, {}), "('foo = 42')", True, 'from vyper import ast as vy_ast\n'), ((13, 15, 13, 56), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (), '', True, 'from vyper import ast as vy_ast\n'), ((21, 15, 21, 56), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (), '', True, 'from vyper import ast as vy_ast\n'), ((28, 15, 28, 46), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', ({(28, 35, 28, 45): '"""foo = 42"""'}, {}), "('foo = 42')", True, 'from vyper import ast as vy_ast\n'), ((29, 15, 29, 56), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (), '', True, 'from vyper import ast as vy_ast\n'), ((35, 15, 35, 46), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', ({(35, 35, 35, 45): '"""foo = 42"""'}, {}), "('foo = 42')", True, 'from vyper import ast as vy_ast\n'), ((36, 15, 36, 56), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (), '', True, 'from vyper import ast as vy_ast\n'), ((31, 15, 31, 55), 'vyper.ast.compare_nodes', 'vy_ast.compare_nodes', ({(31, 36, 31, 44): 'old_node', (31, 46, 31, 54): 'new_node'}, {}), '(old_node, new_node)', True, 'from vyper import ast as vy_ast\n'), ((20, 15, 20, 40), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', ({(20, 35, 20, 39): '"""42"""'}, {}), "('42')", True, 'from vyper import ast as vy_ast\n')]