예제 #1
0
def test_attribute_arithmetic_add_mul():
    result = parse(
        {
            "op": "eq",
            "args": [
                {"property": "attr"},
                {
                    "op": "+",
                    "args": [
                        3,
                        {"op": "*", "args": [5, 2]},
                    ],
                },
            ],
        }
    )
    assert result == ast.Equal(
        ast.Attribute("attr"),
        ast.Add(
            3,
            ast.Mul(
                5,
                2,
            ),
        ),
    )
예제 #2
0
def test_arithmetic():
    # test possible optimizations
    result = optimize(parse("attr = 10 + 10"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        20
    )

    result = optimize(parse("attr = 30 - 10"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        20
    )

    result = optimize(parse("attr = 10 * 2"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        20
    )

    result = optimize(parse("attr = 40 / 2"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        20
    )

    # test imppossible optimizations
    result = optimize(parse("attr = other + 10"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Add(
            ast.Attribute('other'), 10
        ),
    )

    result = optimize(parse("attr = other - 10"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Sub(
            ast.Attribute('other'), 10
        ),
    )

    result = optimize(parse("attr = other * 2"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Mul(
            ast.Attribute('other'), 2
        ),
    )

    result = optimize(parse("attr = other / 2"))
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Div(
            ast.Attribute('other'), 2
        ),
    )
예제 #3
0
def test_attribute_arithmetic_mul():
    result = parse('attr = 5 * 2')
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Mul(
            5,
            2,
        ),
    )
예제 #4
0
def test_attribute_arithmetic_mul():
    result = parse(['==', ['get', 'attr'], ['*', 5, 2]])
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Mul(
            5,
            2,
        ),
    )
예제 #5
0
def test_attribute_arithmetic_mul():
    result = parse({
        "eq": [
            {"property": "attr"},
            {"*": [5, 2]}
        ]
    })
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Mul(
            5,
            2,
        ),
    )