def test_valid_match_argument_types(self):
     a = ast.ForbidConvention(ast.Node(descriptor=ast.NodeTypeDescriptor(type_='property'),
                                       constraint=ast.MatchExpr(ast.StringExpr('t'),
                                                                ast.StringExpr('m'))), '')
     convention_set = self.wrap_convention_in_set(a)
     error_log = checker.TypeChecker.check(convention_set)
     assert not error_log.contain_errors()
 def test_invalid_in_argument_types(self):
     a = ast.ForbidConvention(ast.Node(descriptor=ast.NodeTypeDescriptor(type_='property'),
                                       constraint=ast.InExpr(ast.ListExpr([ast.StringExpr('p')]),
                                                             ast.StringExpr('t'), '')), '')
     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 test_diff_ineq_argument_types(self):
     a = ast.ForbidConvention(ast.Node(descriptor=ast.NodeTypeDescriptor(type_='property'),
                                       constraint=ast.NotEqualExpr(ast.StringExpr('t'), 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 visitCall_expr(self, context):
     identifier = context.call.text.lower()
     line = context.call.line
     if identifier in self.identifiers or identifier == 'stylesheet':
         return ast.VariableExpr(identifier, line)
     if identifier == 'lowercase':
         return ast.StringExpr('^[^A-Z]+$', line)
     if identifier == 'shorten':
         return ast.StringExpr('(?P<gr1>[0-9a-f])(?P=gr1)(?P<gr2>[0-9a-f])(?P=gr2)(?P<gr3>[0-9a-f])(?P=gr3)', line)
     operand = ast.VariableExpr.DEFAULT
     if context.operand:
         operand = self.visitCall_expr(context.operand)
     argument = self.visit_argument(context)
     if not argument:
         return self.visit_property_call(identifier, operand, line)
     return self.visit_method_call(identifier, operand, argument, line)
 def visitList_element(self, ctx):
     if ctx.element_dec:
         return ast.DecimalExpr(float(ctx.element_dec.text))
     if ctx.element_int:
         return ast.IntegerExpr(int(ctx.element_int.text))
     if ctx.element_str:
         return ast.StringExpr(self.unescape_quotes(ctx.element_str.text))
     if ctx.element_desc:
         return self.visitSemantic_node(ctx.element_desc)
     raise ValueError('Unknown list element')
 def visitElement(self, context):
     if context.primary_bool:
         return ast.BooleanExpr(bool(context.primary_bool.text.lower() != 'false'), context.primary_bool.line)
     if context.primary_dec:
         return ast.DecimalExpr(float(context.primary_dec.text), context.primary_dec.line)
     if context.primary_int:
         return ast.IntegerExpr(int(context.primary_int.text), context.primary_int.line)
     if context.primary_str:
         return ast.StringExpr(self.unescape_quotes(context.primary_str.text), context.primary_str.line)
     if context.primary_list:
         return self.visitList_(context.primary_list)
     raise ValueError('Unknown element')
 def test_same_ineq_argument_types_string(self):
     a = ast.ForbidConvention(ast.Node(descriptor=ast.NodeTypeDescriptor(type_='property'),
                                       constraint=ast.NotEqualExpr(ast.StringExpr('n'), ast.StringExpr('m'), 3)), '')
     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