예제 #1
0
def test_expr_compare_order():
    assert parse_expr('a AND b = c') == OpBox(
        op='OP_AND',
        left=NameBox('a'),
        right=OpBox(
            op='OP_EQ',
            left=NameBox('b'),
            right=NameBox('c'),
        ),
    )
예제 #2
0
def test_expr_mul_order():
    assert parse_expr('a + b * c') == OpBox(
        op='OP_ADD',
        left=NameBox('a'),
        right=OpBox(
            op='OP_MUL',
            left=NameBox('b'),
            right=NameBox('c'),
        ),
    )
예제 #3
0
def test_expr_logic_order():
    assert parse_expr('a * b AND c') == OpBox(
        op='OP_AND',
        left=OpBox(
            op='OP_MUL',
            left=NameBox('a'),
            right=NameBox('b'),
        ),
        right=NameBox('c'),
    )
예제 #4
0
def test_expr_braces():
    assert parse_expr('a * (b + c)') == OpBox(
        op='OP_MUL',
        left=NameBox('a'),
        right=OpBox(
            op='OP_ADD',
            left=NameBox('b'),
            right=NameBox('c'),
        ),
    )
예제 #5
0
def test_expr_multi_add_sub():
    assert parse_expr('a + b - c') == OpBox(
        op='OP_SUB',
        left=OpBox(
            op='OP_ADD',
            left=NameBox('a'),
            right=NameBox('b'),
        ),
        right=NameBox('c'),
    )
예제 #6
0
def test_group_by():
    query = parse('SELECT a FROM z GROUP BY foo + bar, foo')
    assert query.group_by == [
        OpBox(
            op='OP_ADD',
            left=NameBox('foo'),
            right=NameBox('bar'),
        ),
        NameBox('foo'),
    ]
예제 #7
0
def test_expr_add():
    assert parse_expr('a + b') == OpBox(
        op='OP_ADD',
        left=NameBox('a'),
        right=NameBox('b'),
    )
예제 #8
0
def test_expr_lshift():
    assert parse_expr('a << b') == OpBox(
        left=NameBox('a'),
        right=NameBox('b'),
        op='OP_LSHIFT',
    )
예제 #9
0
def test_expr_rshift():
    assert parse_expr('a >> b') == OpBox(
        left=NameBox('a'),
        right=NameBox('b'),
        op='OP_RSHIFT',
    )
예제 #10
0
def test_expr_not_in():
    assert parse_expr('a NOT IN b') == OpBox(
        left=NameBox('a'),
        right=NameBox('b'),
        op='OP_NOT_IN',
    )
예제 #11
0
def test_expr_not_like():
    assert parse_expr('a NOT LIKE b') == OpBox(
        left=NameBox('a'),
        right=NameBox('b'),
        op='OP_NOT_LIKE',
    )
예제 #12
0
def test_expr_module():
    assert parse_expr('a % b') == OpBox(
        left=NameBox('a'),
        right=NameBox('b'),
        op='OP_MOD',
    )
예제 #13
0
def test_expr_bitwise_xor():
    assert parse_expr('a ^ b') == OpBox(
        left=NameBox('a'),
        right=NameBox('b'),
        op='OP_BITWISE_XOR',
    )
예제 #14
0
def test_expr_bitwise_and():
    assert parse_expr('a & b') == OpBox(
        left=NameBox('a'),
        right=NameBox('b'),
        op='OP_BITWISE_AND',
    )
예제 #15
0
def test_parser_where():
    assert parse('SELECT a FROM z WHERE a = b').where == OpBox(
        op='OP_EQ',
        left=NameBox('a'),
        right=NameBox('b'),
    )
예제 #16
0
def expr_as_op(left: ExprBox, op: Token, right: ExprBox) -> OpBox:
    return OpBox(op=op.gettokentype(), left=left, right=right)