예제 #1
0
def test_attribute_arithmetic_div_sub_bracketted():
    result = parse(
        {
            "op": "eq",
            "args": [
                {"property": "attr"},
                {
                    "op": "/",
                    "args": [
                        3,
                        {"op": "-", "args": [5, 2]},
                    ],
                },
            ],
        }
    )
    assert result == ast.Equal(
        ast.Attribute("attr"),
        ast.Div(
            3,
            ast.Sub(
                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_sub():
    result = parse('attr = 5 - 2')
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Sub(
            5,
            2,
        ),
    )
예제 #4
0
def test_attribute_arithmetic_sub():
    result = parse(['==', ['get', 'attr'], ['-', 5, 2]])
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Sub(
            5,
            2,
        ),
    )
예제 #5
0
def test_attribute_arithmetic_div_sub_bracketted():
    result = parse('attr = 3 / (5 - 2)')
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Div(
            3,
            ast.Sub(
                5,
                2,
            ),
        ),
    )
예제 #6
0
def test_attribute_arithmetic_div_sub():
    result = parse('attr = 3 / 5 - 2')
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Sub(
            ast.Div(
                3,
                5,
            ),
            2,
        ),
    )
예제 #7
0
def test_attribute_arithmetic_div_sub_bracketted():
    result = parse(['==', ['get', 'attr'], ['/', 3, ['-', 5, 2]]])
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Div(
            3,
            ast.Sub(
                5,
                2,
            ),
        ),
    )
예제 #8
0
def test_attribute_arithmetic_sub():
    result = parse({
        "eq": [
            {"property": "attr"},
            {"-": [5, 2]}
        ]
    })
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Sub(
            5,
            2,
        ),
    )
예제 #9
0
def test_attribute_arithmetic_sub():
    result = parse(
        {
            "op": "eq",
            "args": [{"property": "attr"}, {"op": "-", "args": [5, 2]}],
        }
    )
    assert result == ast.Equal(
        ast.Attribute("attr"),
        ast.Sub(
            5,
            2,
        ),
    )
예제 #10
0
def test_attribute_arithmetic_div_sub():
    result = parse({
        "eq": [
            {"property": "attr"},
            {"-": [
                {"/": [3, 5]},
                2,
            ]},
        ],
    })
    assert result == ast.Equal(
        ast.Attribute('attr'),
        ast.Sub(
            ast.Div(
                3,
                5,
            ),
            2,
        ),
    )