Exemplo n.º 1
0
def test_if_2():
    template = '''
    {% if z > x > y %}
    {% endif %}
    {% if x == y and x == 'asd' and z == 5 %}
    {% endif %}
    {{ x }}
    '''
    struct = infer_from_ast(parse(template))
    expected_struct = Dictionary({
        'x': Scalar(label='x', linenos=[2, 4, 6]),
        'y': Unknown(label='y', linenos=[2, 4]),
        'z': Unknown(label='z', linenos=[2, 4]),
    })
    assert struct == expected_struct
Exemplo n.º 2
0
def test_if_2():
    template = '''
    {% if z > x > y %}
    {% endif %}
    {% if x == y and x == 'asd' and z == 5 %}
    {% endif %}
    {{ x }}
    '''
    struct = infer_from_ast(parse(template))
    expected_struct = Dictionary({
        'x': Scalar(label='x', linenos=[2, 4, 6]),
        'y': Unknown(label='y', linenos=[2, 4]),
        'z': Unknown(label='z', linenos=[2, 4]),
    })
    assert struct == expected_struct
Exemplo n.º 3
0
def test_for_2():
    template = '''
    {% for x in xs %}
        {{ x }}
        {% for y in ys %}
            {{ loop.index0 }}
        {% endfor %}
        {{ loop.length }}
    {% endfor %}
    '''
    ast = parse(template)
    struct = infer_from_ast(ast)

    expected_struct = Dictionary({
        'xs': List(Scalar(label='x', linenos=[3]), label='xs', linenos=[2]),
        'ys': List(Unknown(linenos=[4]), label='ys', linenos=[4]),
    })
    assert struct == expected_struct
Exemplo n.º 4
0
def test_for_2():
    template = '''
    {% for x in xs %}
        {{ x }}
        {% for y in ys %}
            {{ loop.index0 }}
        {% endfor %}
        {{ loop.length }}
    {% endfor %}
    '''
    ast = parse(template)
    struct = infer_from_ast(ast)

    expected_struct = Dictionary({
        'xs': List(Scalar(label='x', linenos=[3]), label='xs', linenos=[2]),
        'ys': List(Unknown(linenos=[4]), label='ys', linenos=[4]),
    })
    assert struct == expected_struct
Exemplo n.º 5
0
def test_elif():
    template = '''
    {% if kenny.sick %}
    Kenny is sick.
    {% elif kenny.dead %}
    You killed Kenny!  You bastard!!!
    {% else %}
    Kenny looks okay --- so far
    {% endif %}
    '''
    struct = infer_from_ast(parse(template))
    expected_struct = Dictionary({
        'kenny': Dictionary({
            'sick': Unknown(label='sick', linenos=[2]),
            'dead': Unknown(label='dead', linenos=[4]),
        },label='kenny', linenos=[2, 4]),
    })
    assert struct == expected_struct