예제 #1
0
def test_attribute_all_operands():
    assert DefaultParser().parse(
        '"foo".length + {foo: "bar"}.foo') == BinaryExpression(
            operator=_ops['+'],
            left=Identifier('length', subject=Literal('foo')),
            right=Identifier(value='foo',
                             subject=ObjectLiteral({'foo': Literal('bar')})))
예제 #2
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))
예제 #3
0
def test_transforms():
    assert DefaultParser().parse(
        'foo|tr1|tr2.baz|tr3({bar:"tek"})') == Transform(
            name='tr3',
            args=[ObjectLiteral({'bar': Literal('tek')})],
            subject=Identifier('baz',
                               subject=Transform(
                                   name='tr2',
                                   args=[],
                                   subject=Transform(
                                       name='tr1',
                                       args=[],
                                       subject=Identifier('foo')))))
예제 #4
0
def test_filters():
    assert DefaultParser().parse('foo[1][.bar[0]=="tek"].baz') == Identifier(
        value='baz',
        subject=FilterExpression(
            relative=True,
            expression=BinaryExpression(operator=_ops['=='],
                                        left=FilterExpression(
                                            relative=False,
                                            expression=Literal(0),
                                            subject=Identifier('bar',
                                                               relative=True)),
                                        right=Literal('tek')),
            subject=FilterExpression(relative=False,
                                     expression=Literal(1),
                                     subject=Identifier('foo'))))
예제 #5
0
def test_complex_binary_operator_balancing():
    assert DefaultParser().parse('a.b == c.d') == BinaryExpression(
        operator=_ops['=='],
        left=Identifier('b', subject=Identifier('a')),
        right=Identifier('d', subject=Identifier('c')))
예제 #6
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'))
예제 #7
0
def test_ternary_expression():
    assert DefaultParser().parse('foo ? 1 : 0') == ConditionalExpression(
        test=Identifier('foo'), consequent=Literal(1), alternate=Literal(0))
예제 #8
0
def test_identifier_filter_expression():
    assert DefaultParser().parse('foo.bar["baz"]') == FilterExpression(
        expression=Literal('baz'),
        subject=Identifier(value='bar', subject=Identifier(value='foo')))
예제 #9
0
def test_attribute_array():
    assert DefaultParser().parse('["foo", "bar"].length') == Identifier(
        value='length', subject=ArrayLiteral([Literal('foo'),
                                              Literal('bar')]))
예제 #10
0
def test_attribute_subexpression():
    assert DefaultParser().parse('("foo" + "bar").length') == Identifier(
        value='length',
        subject=BinaryExpression(operator=_ops['+'],
                                 left=Literal('foo'),
                                 right=Literal('bar')))
예제 #11
0
def test_transforms_multiple_arguments():
    assert DefaultParser().parse('foo|bar("tek", 5, true)') == Transform(
        name='bar',
        args=[Literal('tek'), Literal(5),
              Literal(True)],
        subject=Identifier('foo'))
예제 #12
0
def test_chained_identifiers():
    assert DefaultParser().parse('foo.bar.baz + 1') == BinaryExpression(
        operator=_ops['+'],
        left=Identifier('baz',
                        subject=Identifier('bar', subject=Identifier('foo'))),
        right=Literal(1))