def test_same_eq_argument_types_list(self): a = ast.ForbidConvention(ast.Node(descriptor=ast.NodeTypeDescriptor(type_='property'), constraint=ast.EqualExpr(ast.ListExpr([]), ast.ListExpr([]), 3)), '') convention_set = self.wrap_convention_in_set(a) error_log = checker.TypeChecker.check(convention_set) assert not error_log.contain_errors()
def test_diff_eq_argument_types(self): a = ast.ForbidConvention(ast.Node(descriptor=ast.NodeTypeDescriptor(type_='property'), constraint=ast.EqualExpr(ast.StringExpr('test'), ast.IntegerExpr(5), 3)), '') convention_set = self.wrap_convention_in_set(a) error_log = checker.TypeChecker.check(convention_set) assert error_log.contain_errors() assert len(error_log.get_errors_for_convention(a)) == 1
def test_valid_minus_argument_types(self): a = ast.ForbidConvention(ast.Node(descriptor=ast.NodeTypeDescriptor(type_='property'), constraint=ast.EqualExpr(ast.UnaryMinusExpr(ast.IntegerExpr(1)), ast.IntegerExpr(2))), '') convention_set = self.wrap_convention_in_set(a) error_log = checker.TypeChecker.check(convention_set) assert not error_log.contain_errors()
def test_list_with_diff_elements(self): a = ast.ForbidConvention(ast.Node(descriptor=ast.NodeTypeDescriptor(type_='property'), constraint=ast.EqualExpr(ast.ListExpr([ast.IntegerExpr(1), ast.StringExpr('')]), ast.IntegerExpr(2))), '') convention_set = self.wrap_convention_in_set(a) error_log = checker.TypeChecker.check(convention_set) assert error_log.contain_errors() assert len(error_log.get_errors()) == 1
def binary_arithmetic_expr(self, context, left, right, line): operator = context.operator.text if operator == '==': return ast.EqualExpr(left, right, line) if operator == '!=': return ast.NotEqualExpr(left, right, line) if operator == '<': return ast.LessThanExpr(left, right, line) if operator == '>': return ast.GreaterThanExpr(left, right, line) if operator == '<=': return ast.LessThanOrEqualExpr(left, right, line) if operator == '>=': return ast.GreaterThanOrEqualExpr(left, right, line) if operator == 'in': return ast.InExpr(left, right, line) if operator == 'not in': return ast.NotExpr(ast.InExpr(left, right, line)) if operator == 'match': return ast.MatchExpr(left, right, line) if operator == 'not match': return ast.NotExpr(ast.MatchExpr(left, right, line)) raise ValueError('Unknown expression')