示例#1
0
 def test_literal(self):
     self.check_parser('"ala"', AST.StringLiteral('ala'))
     self.check_parser('null', AST.Null())
示例#2
0
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
    def __init__(self, methodName='runTest'):
        super(TestParser, self).__init__(methodName)
        self.logger = StoreLogger()
        self.parser = Parser(self.logger)
        self.table_parser = TableParser(self.logger)
        self.simple_parser = SimpleParser(self.logger)

    def check_parser(self, str_input, ast, debug=False):
        self.assertEqual(ast, self.parser.parse(str_input, debug=debug))
示例#3
0
 def test_string_literal(self):
     self.check_parser('"ala"', AST.StringLiteral('ala'))
示例#4
0
 def p_string_literal(self, p):
     """string_literal : STRING_LITERAL"""
     p[0] = AST.StringLiteral(p[1])