Ejemplo n.º 1
0
def lark_to_name_node(tree: "Tree") -> "NameNode":
    """
    Creates and returns a NameNode instance extracted from the parsing of the
    tree instance.
    :param tree: the Tree to parse in order to extract the proper node
    :type tree: Tree
    :return: a NameNode instance extracted from the parsing of the tree
    :rtype: NameNode
    """
    return NameNode(value=tree.children[0].value,
                    location=lark_to_location_node(tree.meta))
Ejemplo n.º 2
0
def _parse_name(name_ast: dict) -> "NameNode":
    """
    Creates and returns a NameNode instance from a name's JSON AST
    libgraphqlparser representation.
    :param name_ast: name's JSON AST libgraphqlparser representation
    :type name_ast: dict
    :return: a NameNode instance equivalent to the JSON AST representation
    :rtype: NameNode
    """
    return NameNode(value=name_ast["value"],
                    location=_parse_location(name_ast["loc"]))
Ejemplo n.º 3
0
def test_namenode__init__():
    name_node = NameNode(value="nameValue", location="nameLocation")
    assert name_node.value == "nameValue"
    assert name_node.location == "nameLocation"
Ejemplo n.º 4
0
import pytest

from tartiflette.language.ast import NameNode


def test_namenode__init__():
    name_node = NameNode(value="nameValue", location="nameLocation")
    assert name_node.value == "nameValue"
    assert name_node.location == "nameLocation"


@pytest.mark.parametrize(
    "name_node,other,expected",
    [
        (
            NameNode(value="nameValue", location="nameLocation"),
            Ellipsis,
            False,
        ),
        (
            NameNode(value="nameValue", location="nameLocation"),
            NameNode(value="nameValueBis", location="nameLocation"),
            False,
        ),
        (
            NameNode(value="nameValue", location="nameLocation"),
            NameNode(value="nameValue", location="nameLocationBis"),
            False,
        ),
        (
            NameNode(value="nameValue", location="nameLocation"),