def test_callable_type_with_default_args(self): c = Callable([self.x, self.y], [ARG_POS, ARG_OPT], [None, None], Any(), False) assert_equal(str(c), 'def (X?, Y?=) -> any') c2 = Callable([self.x, self.y], [ARG_OPT, ARG_OPT], [None, None], Any(), False) assert_equal(str(c2), 'def (X?=, Y?=) -> any')
def test_callable_type(self): c = Callable([self.x, self.y], [ARG_POS, ARG_POS], [None, None], Any(), False) assert_equal(str(c), 'def (X?, Y?) -> any') c2 = Callable([], [], [], Void(None), False) assert_equal(str(c2), 'def ()')
def assert_expand(self, orig, map_items, result): lower_bounds = {} for id, t in map_items: lower_bounds[id] = t exp = expand_type(orig, lower_bounds) # Remove erased tags (asterisks). assert_equal(str(exp).replace('*', ''), str(result))
def assert_vararg_map(self, caller_kinds, callee_kinds, expected, vararg_type): result = map_actuals_to_formals( caller_kinds, [], callee_kinds, [], lambda i: vararg_type) assert_equal(result, expected)
def assert_solve(self, vars, constraints, results): res = [] for r in results: if isinstance(r, tuple): res.append(r[0]) else: res.append(r) actual = solve_constraints(vars, constraints, self.fx.basic) assert_equal(str(actual), str(res))
def assert_map(self, caller_kinds, callee_kinds, expected): caller_kinds, caller_names = expand_caller_kinds(caller_kinds) callee_kinds, callee_names = expand_callee_kinds(callee_kinds) result = map_actuals_to_formals( caller_kinds, caller_names, callee_kinds, callee_names, lambda i: Any()) assert_equal(result, expected)
def test_generic_function_type(self): c = Callable([self.x, self.y], [ARG_POS, ARG_POS], [None, None], self.y, False, None, TypeVars([TypeVarDef('X', -1)])) assert_equal(str(c), 'def <X> (X?, Y?) -> Y?') v = TypeVars([TypeVarDef('Y', -1, UnboundType('X')), TypeVarDef('X', -2)]) c2 = Callable([], [], [], Void(None), False, None, v) assert_equal(str(c2), 'def <Y is X?, X> ()')
def assert_simple_join(self, s, t, join): result = join_types(s, t, self.fx.basic) actual = str(result) expected = str(join) assert_equal(actual, expected, 'join({}, {}) == {{}} ({{}} expected)'.format(s, t)) if not isinstance(s, ErrorType) and not isinstance(result, ErrorType): assert_true(is_subtype(s, result), '{} not subtype of {}'.format(s, result)) if not isinstance(t, ErrorType) and not isinstance(result, ErrorType): assert_true(is_subtype(t, result), '{} not subtype of {}'.format(t, result))
def assert_simple_meet(self, s, t, meet): result = meet_types(s, t, self.fx.basic) actual = str(result) expected = str(meet) assert_equal(actual, expected, 'meet({}, {}) == {{}} ({{}} expected)'.format(s, t)) if not isinstance(s, ErrorType) and not isinstance(result, ErrorType): assert_true(is_subtype(result, s), '{} not subtype of {}'.format(result, s)) if not isinstance(t, ErrorType) and not isinstance(result, ErrorType): assert_true(is_subtype(result, t), '{} not subtype of {}'.format(result, t))
def assert_line(self, s, a): s = s.replace('\\n', '\n') s = s.replace('\\r', '\r') tt = lex(s) r = [] for t in tt: r.append(t.line) if len(r) == len(a) + 2: a = a[:] a.append(a[-1]) a.append(a[-1]) assert_equal(r, a)
def assert_lex(self, src, lexed): src = src.replace('\\n', '\n') src = src.replace('\\r', '\r') if lexed.endswith(' ...'): lexed = lexed[:-3] + 'Break() Eof()' l = lex(src) r = [] for t in l: r.append(str(t)) act = ' '.join(r) if act != lexed: print('Actual: ', act) print('Expected:', lexed) assert_equal(act, lexed)
def test_callable_type_with_var_args(self): c = Callable([self.x], [ARG_STAR], [None], Any(), False) assert_equal(str(c), 'def (*X?) -> any') c2 = Callable([self.x, self.y], [ARG_POS, ARG_STAR], [None, None], Any(), False) assert_equal(str(c2), 'def (X?, *Y?) -> any') c3 = Callable([self.x, self.y], [ARG_OPT, ARG_STAR], [None, None], Any(), False) assert_equal(str(c3), 'def (X?=, *Y?) -> any')
def test_generic_unbound_type(self): u = UnboundType('Foo', [UnboundType('T'), Any()]) assert_equal(str(u), 'Foo?<T?, any>')
def test_type_variable_binding(self): assert_equal(str(TypeVarDef('X', 1)), 'X') assert_equal(str(TypeVarDef('X', 1, UnboundType('Y'))), 'X is Y?')
def test_tuple_type(self): assert_equal(str(TupleType([])), 'tuple<>') assert_equal(str(TupleType([self.x])), 'tuple<X?>') assert_equal(str(TupleType([self.x, Any()])), 'tuple<X?, any>')
def assert_replace(self, orig, result): assert_equal(str(replace_type_vars(orig)), str(result))
def assert_erase(self, orig, result): assert_equal(str(erase_type(orig, self.fx.basic)), str(result))
def test_any(self): assert_equal(str(Any()), 'any')
def test_simple_unbound_type(self): u = UnboundType('Foo') assert_equal(str(u), 'Foo?')
def test_void_type(self): assert_equal(str(Void(None)), 'void')