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'), ), )
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'), ), )
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'), )
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'), ), )
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'), )
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'), ]
def test_expr_add(): assert parse_expr('a + b') == OpBox( op='OP_ADD', left=NameBox('a'), right=NameBox('b'), )
def test_expr_lshift(): assert parse_expr('a << b') == OpBox( left=NameBox('a'), right=NameBox('b'), op='OP_LSHIFT', )
def test_expr_rshift(): assert parse_expr('a >> b') == OpBox( left=NameBox('a'), right=NameBox('b'), op='OP_RSHIFT', )
def test_expr_not_in(): assert parse_expr('a NOT IN b') == OpBox( left=NameBox('a'), right=NameBox('b'), op='OP_NOT_IN', )
def test_expr_not_like(): assert parse_expr('a NOT LIKE b') == OpBox( left=NameBox('a'), right=NameBox('b'), op='OP_NOT_LIKE', )
def test_expr_module(): assert parse_expr('a % b') == OpBox( left=NameBox('a'), right=NameBox('b'), op='OP_MOD', )
def test_expr_bitwise_xor(): assert parse_expr('a ^ b') == OpBox( left=NameBox('a'), right=NameBox('b'), op='OP_BITWISE_XOR', )
def test_expr_bitwise_and(): assert parse_expr('a & b') == OpBox( left=NameBox('a'), right=NameBox('b'), op='OP_BITWISE_AND', )
def test_parser_where(): assert parse('SELECT a FROM z WHERE a = b').where == OpBox( op='OP_EQ', left=NameBox('a'), right=NameBox('b'), )
def expr_as_op(left: ExprBox, op: Token, right: ExprBox) -> OpBox: return OpBox(op=op.gettokentype(), left=left, right=right)