Example #1
0
 def test_positive_unary_tests(self):
     # self.check_parser('%s in null' % ARITHMETIC_EXPRESSION_STR,
     #                   AST.In(ARITHMETIC_EXPRESSION_AST, AST.PositiveUnaryTests([AST.Null()])))
     self.check_parser('%s  in  null' % ARITHMETIC_EXPRESSION_STR,
                       AST.In(ARITHMETIC_EXPRESSION_AST, AST.PositiveUnaryTests([AST.Null()])))
     self.check_parser(POSITIVE_UNARY_TESTS_STR,
                       POSITIVE_UNARY_TESTS_AST)
Example #2
0
 def test_comparison(self):
     self.check_operator_parser('=', AST.Eq)
     self.check_operator_parser('!=', AST.Neq)
     self.check_operator_parser('<', AST.Lt)
     self.check_operator_parser('<=', AST.Lte)
     self.check_operator_parser('>', AST.Gt)
     self.check_operator_parser('>=', AST.Gte)
     self.check_parser('%s between %s and %s' % (DATE_STR, CONTEXT_STR, LIST_STR),
                       AST.Between(DATE_AST, CONTEXT_AST, LIST_AST))
     # self.check_parser('%s between %s and %s' % (FILTER_EXPRESSION_STR, INSTANCE_OF_STR, LIST_STR),
     #                   AST.Between(FILTER_EXPRESSION_AST, INSTANCE_OF_AST, LIST_AST),
     #                   debug=True)
     self.check_parser('%s in  null' % DATE_STR,
                       AST.In(DATE_AST, AST.PositiveUnaryTests([AST.Null()])))
     self.check_parser('%s in  null' % FILTER_EXPRESSION_STR,
                       AST.In(FILTER_EXPRESSION_AST, AST.PositiveUnaryTests([AST.Null()])))
     # self.check_parser('%s in null' % FILTER_EXPRESSION_STR, AST.In(FILTER_EXPRESSION_AST, [AST.Null]))
     self.check_parser('%s in (null, null)' % FILTER_EXPRESSION_STR,
                       AST.In(FILTER_EXPRESSION_AST, AST.PositiveUnaryTests([AST.Null()] * 2)))
Example #3
0
 def test_unary_tests(self):
     self.check_table_parser('null', AST.PositiveUnaryTests([AST.Null()]))
     self.check_table_parser(NOT_STR, NOT_AST)
     self.check_table_parser('-', AST.NoTest())
Example #4
0
 def test_literal(self):
     self.check_parser('"ala"', AST.StringLiteral('ala'))
     self.check_parser('null', AST.Null())
Example #5
0
FOR_AST = AST.For([(AST.Name('ala'), IF_AST)], QUANTIFIED_AST)

PATH_STR = '%s.ala' % DATE_STR
PATH_AST = AST.Path(DATE_AST, AST.Name('ala'))

INVOCATION_STR = '%s(%s, %s)' % (PATH_STR, FOR_STR, IF_STR)
INVOCATION_AST = AST.Invocation(PATH_AST, [FOR_AST, IF_AST])

NEGATION_STR = '-?A_zÊÝĄͼൺ⁶Ⰲ〠邏2𐎅'
NEGATION_AST = AST.Negation(AST.Name('?A_zÊÝĄͼൺ⁶Ⰲ〠邏2𐎅'))

ARITHMETIC_EXPRESSION_STR = '1.2-%s  /true  **%s' % (NEGATION_STR, NAME_STR)
ARITHMETIC_EXPRESSION_AST = AST.Dif(AST.Number(1.2), AST.Div(NEGATION_AST, AST.Exp(AST.Boolean(True), NAME_AST)))

NOT_STR = 'not (null)'
NOT_AST = AST.Not(AST.PositiveUnaryTests([AST.Null()]))

POSITIVE_UNARY_TESTS_STR = '%s  in (null, null)' % ARITHMETIC_EXPRESSION_STR
POSITIVE_UNARY_TESTS_AST = AST.In(ARITHMETIC_EXPRESSION_AST, AST.PositiveUnaryTests([AST.Null()] * 2))

POSITIVE_UNARY_TEST_STR = '%s in (null, %s)' % (POSITIVE_UNARY_TESTS_STR, DATE_STR)
POSITIVE_UNARY_TEST_AST = AST.In(POSITIVE_UNARY_TESTS_AST, AST.PositiveUnaryTests([AST.Null(), AST.Endpoint(DATE_AST)]))

SIMPLE_POSITIVE_UNARY_TESTS_STR = 'ala, "ala"'
SIMPLE_POSITIVE_UNARY_TESTS_AST = AST.PositiveUnaryTests([AST.Endpoint([AST.Name('ala')]),
                                                          AST.Endpoint(AST.StringLiteral('ala'))])


class TestParser(unittest.TestCase):

    # noinspection PyPep8Naming
Example #6
0
 def p_null(self, p):
     """null : NULL"""
     p[0] = AST.Null()
Example #7
0
 def p_missing_else_error(self, p):
     """missing_else_error : IF expression THEN expression error"""
     missing_token_error("missing 'else' branch in 'if' expression", p[5], self.logger)
     self.parser.errok()
     p[0] = AST.If(p[2], p[4], AST.Null())
Example #8
0
 def p_missing_then_error(self, p):
     """missing_then_error : IF expression error ELSE"""
     missing_token_error("missing 'then' branch in 'if' expression", p[3], self.logger)
     self.parser.errok()
     p[0] = AST.If(p[2], AST.Null(), AST.Null())