Beispiel #1
0
def test_empty_expression():
    from stilus.nodes.null import null
    from stilus.nodes.boolean import false

    expression = Expression()
    assert len(expression) == 0
    assert expression.is_empty()
    assert expression.first() is null
    assert expression.to_boolean() is false
Beispiel #2
0
def test_expression_string_first_boolean():
    from stilus.nodes.boolean import true
    from stilus.nodes.boolean import false
    from stilus.nodes.null import null

    expression = Expression()
    expression.append(true)
    expression.append(false)
    expression.append(null)
    assert str(expression) == "(true false null)"
    expression.is_list = True
    assert str(expression) == "(true, false, null)"
    assert expression.first() is true
    assert expression.to_boolean().value is True
Beispiel #3
0
 def castable(self, expr: Expression):
     return (len(expr.nodes) == 2 and expr.first().node_name == "unit"
             and expr.nodes[1] and hasattr(expr.nodes[1], "name")
             and expr.nodes[1].name in units)
Beispiel #4
0
 def cast(self, expr: Expression):
     return Unit(expr.first().value, expr.nodes[1].name)