示例#1
0
def test_nested_non_grouped_ternary_expression():
    assert DefaultParser().parse(
        'foo ? bar ? 1 : 2 : 3') == ConditionalExpression(
            test=Identifier('foo'),
            consequent=ConditionalExpression(test=Identifier('bar'),
                                             consequent=Literal(1),
                                             alternate=Literal(2)),
            alternate=Literal(3))
示例#2
0
def test_object_ternary_expression():
    assert DefaultParser().parse(
        'foo ? {bar: "tek"} : "baz"') == ConditionalExpression(
            test=Identifier('foo'),
            consequent=ObjectLiteral({'bar': Literal('tek')}),
            alternate=Literal('baz'))
示例#3
0
def test_ternary_expression():
    assert DefaultParser().parse('foo ? 1 : 0') == ConditionalExpression(
        test=Identifier('foo'), consequent=Literal(1), alternate=Literal(0))