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

[((74, 105), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', (['"""foo = 42"""'], {}), "('foo = 42')\n", (93, 105), True, 'from vyper import ast as vy_ast\n'), ((121, 162), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (['old_node'], {'value': '(666)'}), '(old_node, value=666)\n', (141, 162), True, 'from vyper import ast as vy_ast\n'), ((244, 275), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', (['"""foo = 42"""'], {}), "('foo = 42')\n", (263, 275), True, 'from vyper import ast as vy_ast\n'), ((291, 332), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (['old_node'], {'value': '(666)'}), '(old_node, value=666)\n', (311, 332), True, 'from vyper import ast as vy_ast\n'), ((531, 572), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (['old_node'], {'value': '(666)'}), '(old_node, value=666)\n', (551, 572), True, 'from vyper import ast as vy_ast\n'), ((682, 713), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', (['"""foo = 42"""'], {}), "('foo = 42')\n", (701, 713), True, 'from vyper import ast as vy_ast\n'), ((729, 770), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (['old_node'], {'value': '(666)'}), '(old_node, value=666)\n', (749, 770), True, 'from vyper import ast as vy_ast\n'), ((880, 911), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', (['"""foo = 42"""'], {}), "('foo = 42')\n", (899, 911), True, 'from vyper import ast as vy_ast\n'), ((927, 968), 'vyper.ast.Int.from_node', 'vy_ast.Int.from_node', (['old_node'], {'value': '(666)'}), '(old_node, value=666)\n', (947, 968), True, 'from vyper import ast as vy_ast\n'), ((787, 827), 'vyper.ast.compare_nodes', 'vy_ast.compare_nodes', (['old_node', 'new_node'], {}), '(old_node, new_node)\n', (807, 827), True, 'from vyper import ast as vy_ast\n'), ((476, 501), 'vyper.ast.parse_to_ast', 'vy_ast.parse_to_ast', (['"""42"""'], {}), "('42')\n", (495, 501), True, 'from vyper import ast as vy_ast\n')]