Esempio n. 1
0
def test_invalid_coerce():
    from stilus.nodes.null import null

    node_1 = Node()
    node_2 = null
    with pytest.raises(CoercionError) as excinfo:
        node_1.coerce(node_2)
    assert "cannot coerce null to node" in str(excinfo.value)
Esempio n. 2
0
def test_atblock():
    atblock = Atblock()
    assert atblock.node_name == "atblock"
    assert atblock.block is None
    assert atblock.nodes == []
    block = Block(Node(), Node())
    block.append(null)
    block.append(Node())
    block.append(true)
    atblock.block = block
    assert atblock.nodes == [null, Node(), true]
Esempio n. 3
0
    def bubble(self, node: Node):
        props = []
        others = []

        def filter_props(block):
            for node in block.nodes:
                node = self.visit(node)
                if node.node_name == "property":
                    props.append(node)
                elif node.node_name == "block":
                    filter_props(node)
                else:
                    others.append(node)

        filter_props(node.block)

        if props:
            selector = Selector([Literal("&")])
            selector.lineno = node.lineno
            selector.column = node.column
            selector.filename = node.filename
            selector.value = "&"

            group = Group(lineno=self.parser.lineno, column=self.parser.column)
            group.lineno = node.lineno
            group.column = node.column
            group.filename = node.filename

            block = Block(node.block, group)
            block.lineno = node.lineno
            block.column = node.column
            block.filename = node.filename

            for prop in props:
                block.append(prop)

            group.append(selector)
            group.block = block

            node.block.nodes = []
            node.block.append(group)
            for other in others:
                node.block.append(other)

            group = self.closest_group(node.block)
            if group:
                node.group = group.clone()

            node.bubbled = True
Esempio n. 4
0
def test_node():
    node = Node(value="value")
    assert node.value == "value"
    # assert node.filename is None  fixme!
    assert node.lineno == 1
    assert node.column == 1

    node = Node(value="value", filename="filename")
    assert node.value == "value"
    assert node.filename == "filename"
    assert node.lineno == 1
    assert node.column == 1

    node = Node(value="value", filename="filename", lineno=10)
    assert node.value == "value"
    assert node.filename == "filename"
    assert node.lineno == 10
    assert node.column == 1

    node = Node(value="value", filename="filename", lineno=10, column=42)
    assert node.value == "value"
    assert node.filename == "filename"
    assert node.lineno == 10
    assert node.column == 42
Esempio n. 5
0
def test_valid_coerce():
    node_1 = Node()
    node_2 = Node()
    assert node_1.coerce(node_2) == node_2
Esempio n. 6
0
def test_first():
    node = Node()
    assert node.first() is node
Esempio n. 7
0
def test_to_boolean():
    node = Node()
    from stilus.nodes.boolean import true

    assert node.to_boolean() == true
Esempio n. 8
0
def test_name():
    node = Node()
    assert node.node_name == "node"
Esempio n. 9
0
def test_hash():
    node = Node()
    assert node.hash() is None
    node = Node(42)
    assert node.hash() == 42