def test_curly_expression_compound_multiline_nosemi(): source = ''' puts 3 * { x = 4 x + 1 } ''' assert parse(source) == [ Call(Ident('puts'), [ BinarySlurp([ Int(3), Ident('*'), Block([ BinarySlurp([Ident('x'), Ident('='), Int(4)]), BinarySlurp([Ident('x'), Ident('+'), Int(1)]) ]) ]) ]) ]
def test_curly_expression(): source = ''' puts 3 * {4 + 1} ''' assert parse(source) == [ Call(Ident('puts'), [ BinarySlurp([ Int(3), Ident('*'), BinarySlurp([Int(4), Ident('+'), Int(1)]) ]) ]) ]
def test_kwargs(): source = ''' train model l2: 0.5 alpha: 0.01 ''' assert parse(source) == [ Call(Ident('train'), [ Ident('model'), BinarySlurp([Ident('l2'), Ident(':'), Float(0.5)]), BinarySlurp([Ident('alpha'), Ident(':'), Float(0.01)]), ]) ]
def test_list_dot_slice(): source = ''' puts list.{3..5} ''' assert parse(source) == [ Call(Ident('puts'), [ BinarySlurp([ Ident('list'), Ident('.'), BinarySlurp([Int(3), Ident('..'), Int(5)]) ]) ]) ]
def test_defop(): source = ''' defop {+} assoc: @left priority: 5 ''' assert parse(source) == [ Call(Ident('defop'), [ Ident('+'), BinarySlurp([Ident('assoc'), Ident(':'), Symbol('left')]), BinarySlurp([Ident('priority'), Ident(':'), Int(5)]) ]) ]
def test_single_map(): source = ''' map = {"thing" -> "place", } ''' assert parse(source) == [ BinarySlurp([ Ident('map'), Ident('='), Map([ BinarySlurp([String('thing'), Ident('->'), String('place')]), ]) ]) ]
def test_single_tuple(): source = ''' tuple = ("thing" -> "place",) ''' assert parse(source) == [ BinarySlurp([ Ident('tuple'), Ident('='), Tuple([ BinarySlurp([String('thing'), Ident('->'), String('place')]), ]) ]) ]
def test_float_sigil(): source = r''' 10 + 3.0i ''' assert parse(source) == [ BinarySlurp([Int(10), Ident('+'), Float(3.0, 'i')]) ]
def test_class(): source = ''' class Dog def (new breed) self.breed = breed def (bark) puts "Woof!" ''' assert parse(source) == [ Call(Ident('class'), [ Ident('Dog'), Block([ Call(Ident('def'), [ Call(Ident('new'), [Ident('breed')]), Block([ BinarySlurp([ Ident('self'), Ident('.'), Ident('breed'), Ident('='), Ident('breed') ]) ]) ]), Call(Ident('def'), [ Call(Ident('bark')), Block([Call(Ident('puts'), [String('Woof!')])]) ]) ]) ]) ]
def test_bigint_small(): source = ''' x = 3e-10 ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Int(int(3e-10))]) ]
def test_int_underscore(): source = ''' x = 3_000_000 ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Int(3000000)]) ]
def test_simple_binary_slurp(): source = ''' puts 1+2 ''' assert parse(source) == [ Call(Ident('puts'), [BinarySlurp([Int(1), Ident('+'), Int(2)])]) ]
def test_empty_tuple(): source = ''' tuple = () ''' assert parse(source) == [ BinarySlurp([Ident('tuple'), Ident('='), Tuple()]) ]
def test_bigint_trailing_underscore(): source = ''' x = 3_00_e1_0_ ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Int(int(300e10))]) ]
def test_single_list_trailing(): source = ''' list = [1, ] ''' assert parse(source) == [ BinarySlurp([Ident('list'), Ident('='), List([Int(1)])]) ]
def test_op_identifier(): source = ''' plus = {+} ''' assert parse(source) == [ BinarySlurp([Ident('plus'), Ident('='), Ident('+')]) ]
def test_binary_identifier(): source = ''' fn = {~and} ''' assert parse(source) == [ BinarySlurp([Ident('fn'), Ident('='), Ident('and')]) ]
def test_ident_neq_nospace(): source = ''' works!=true ''' assert parse(source) == [ BinarySlurp([Ident('works!'), Ident('='), Ident('true')]) ]
def test_question_neq(): source = ''' works != true ''' assert parse(source) == [ BinarySlurp([Ident('works'), Ident('!='), Ident('true')]) ]
def test_ident_question_nospace(): source = ''' works?=true ''' assert parse(source) == [ BinarySlurp([Ident('works?'), Ident('='), Ident('true')]) ]
def test_ident_exclamation(): source = ''' works! = true ''' assert parse(source) == [ BinarySlurp([Ident('works!'), Ident('='), Ident('true')]) ]
def test_symbol(): source = ''' x = @thingy ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Symbol('thingy')]) ]
def test_float_trailing_underscore(): source = ''' x = 3_000_000.000_000_ ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Float(3000000.0)]) ]
def test_bigfloat_underscore(): source = ''' x = 3_00.0e1_0 ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Float(300e10)]) ]
def test_bigfloat_small(): source = ''' x = 3.0e-10 ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Float(3e-10)]) ]
def test_int_nonsigil(): source = r''' puts 10 + 3 i ''' assert parse(source) == [ Call(Ident('puts'), [BinarySlurp([Int(10), Ident('+'), Int(3)]), Ident('i')]) ]
def test_simple_call_statement(): source = ''' puts.("Hello, World!",) ''' assert parse(source) == [ BinarySlurp( [Ident('puts'), Ident('.'), Tuple([String("Hello, World!")])]) ]
def test_compound_binary_slurp(): source = ''' puts 1+2 * 3 ''' assert parse(source) == [ Call(Ident('puts'), [BinarySlurp( [Int(1), Ident('+'), Int(2), Ident('*'), Int(3)])]) ]
def test_triple_string_interpolation_nested(): source = r''' puts """Hello, ${1 + {2}}""" ''' assert parse(source) == [ Call(Ident('puts'), [ InterpolatedString( [String('Hello, '), BinarySlurp([Int(1), Ident('+'), Int(2)])]) ]) ]
def test_op_def(): source = ''' def (+ x: int y: int) x.add_int y ''' assert parse(source) == [ Call(Ident('def'), [ Call(Ident('+'), [ BinarySlurp([Ident('x'), Ident(':'), Ident('int')]), BinarySlurp([Ident('y'), Ident(':'), Ident('int')]), ]), Block([ Call(BinarySlurp([Ident('x'), Ident('.'), Ident('add_int')]), [Ident('y')]) ]) ]) ]