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_simple_binary_slurp(): source = ''' puts 1+2 ''' assert parse(source) == [ Call(Ident('puts'), [BinarySlurp([Int(1), Ident('+'), Int(2)])]) ]
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_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_dots(): source = ''' x = 1...3 ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Int(1), Ident('...'), Int(3)]) ]
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_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_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_list(): source = ''' list = [1, 2, (compute "number")] ''' assert parse(source) == [ BinarySlurp([ Ident('list'), Ident('='), List([Int(1), Int(2), Call(Ident('compute'), [String('number')])]) ]) ]
def test_single_block(): source = ''' run thing 1 thing 2 ''' assert parse(source) == [ Call(Ident('run'), [ Block([ Call(Ident('thing'), [Int(1)]), Call(Ident('thing'), [Int(2)]), ]) ]), ]
def test_float_sigil(): source = r''' 10 + 3.0i ''' assert parse(source) == [ BinarySlurp([Int(10), Ident('+'), Float(3.0, 'i')]) ]
def test_single_list_trailing(): source = ''' list = [1, ] ''' assert parse(source) == [ BinarySlurp([Ident('list'), Ident('='), List([Int(1)])]) ]
def test_bigint_trailing_underscore(): source = ''' x = 3_00_e1_0_ ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Int(int(300e10))]) ]
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_whitespace_slurp(): source = ''' x = 1 + 2 puts x . y ''' assert parse(source) == [ BinarySlurp([Ident('x'), Ident('='), Int(1), Ident('+'), Int(2)]), Call(Ident('puts'), [BinarySlurp([Ident('x'), Ident('.'), Ident('y')])]) ]
def test_map_trailing(): source = ''' map = {"thing" -> "place", 2 -> 3, 5 -> (compute "number"), } ''' assert parse(source) == [ BinarySlurp([ Ident('map'), Ident('='), Map([ BinarySlurp([String('thing'), Ident('->'), String('place')]), BinarySlurp([Int(2), Ident('->'), Int(3)]), BinarySlurp([ Int(5), Ident('->'), Call(Ident('compute'), [String('number')]) ]) ]) ]) ]
def test_tuple_trailing(): source = ''' tuple = ("thing" -> "place", 2 -> 3, 5 -> (compute "number"),) ''' assert parse(source) == [ BinarySlurp([ Ident('tuple'), Ident('='), Tuple([ BinarySlurp([String('thing'), Ident('->'), String('place')]), BinarySlurp([Int(2), Ident('->'), Int(3)]), BinarySlurp([ Int(5), Ident('->'), Call(Ident('compute'), [String('number')]) ]) ]) ]) ]
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_toplevel_expression(): source = ''' 3 + 4 ''' assert parse(source) == [BinarySlurp([Int(3), Ident('+'), Int(4)])]
def test_int(): source = ''' x = 3 ''' assert parse(source) == [BinarySlurp([Ident('x'), Ident('='), Int(3)])]
def test_int_sigil(): source = r''' 10 + 3i ''' assert parse(source) == [BinarySlurp([Int(10), Ident('+'), Int(3, 'i')])]