def test_if_some_arg(): inc_type = Func[[IntType], IntType] foo_type1 = None # to simulate TypeVar[None] foo_type2 = Record[{'bar': Option[IntType]}] env = {'inc': inc_type, 'foo': foo_type1} check_expr_type( """ if-some [x #foo.bar] (inc x) """, Tuple.typed(Option[IntType], [ Symbol.typed(IF_SOME1_TYPE, 'if-some'), List([ Symbol('x'), Tuple.typed(Option[IntType], [ Symbol.typed(GET_TYPE, 'get'), Placeholder.typed(foo_type2, 'foo'), Symbol('bar'), ]), ]), Tuple.typed(IntType, [ Symbol.typed(inc_type, 'inc'), Symbol.typed(IntType, 'x'), ]), ]), env, )
def test_placeholder(): check_parse( 'print #foo #foo.bar #foo.bar.baz', List([ Tuple([ Symbol('print'), Placeholder('foo'), Tuple([Symbol('get'), Placeholder('foo'), Symbol('bar')]), Tuple([ Symbol('get'), Tuple([Symbol('get'), Placeholder('foo'), Symbol('bar')]), Symbol('baz') ]) ]), ]), )
def testGet(self): self.assertPrints( Tuple([Symbol('html'), Keyword('foo'), Tuple([Symbol('get'), Symbol('bar'), Symbol('baz')])]), """ html :foo bar.baz """, ) self.assertPrints( Tuple([Symbol('html'), Keyword('foo'), Tuple([Symbol('get'), Placeholder('bar'), Symbol('baz')])]), """ html :foo #bar.baz """, )
def test_infer(): inc_type = Func[[IntType], IntType] foo_type = Func[[NamedArg['arg', IntType]], IntType] check_expr_type( """ def foo inc #arg """, Tuple.typed(foo_type, [ Symbol.typed(DEF_TYPE, 'def'), Symbol('foo'), Tuple.typed(IntType, [ Symbol.typed(inc_type, 'inc'), Placeholder.typed(IntType, 'arg'), ]) ]), {'inc': inc_type}, )
def test_record_infer(): bar_type = Record[{'baz': IntType}] inc_type = Func[[IntType], IntType] foo_type = Func[[NamedArg['bar', bar_type]], IntType] check_expr_type( """ def foo inc #bar.baz """, Tuple.typed(foo_type, [ Symbol.typed(DEF_TYPE, 'def'), Symbol('foo'), Tuple.typed(IntType, [ Symbol.typed(inc_type, 'inc'), Tuple.typed(IntType, [ Symbol.typed(GET_TYPE, 'get'), Placeholder.typed(bar_type, 'bar'), Symbol('baz'), ]), ]) ]), {'inc': inc_type}, )