Esempio n. 1
0
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)])
                ])
            ])
        ])
    ]
Esempio n. 2
0
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)])
            ])
        ])
    ]
Esempio n. 3
0
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)]),
        ])
    ]
Esempio n. 4
0
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)])
            ])
        ])
    ]
Esempio n. 5
0
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)])
        ])
    ]
Esempio n. 6
0
def test_single_map():
    source = '''
    map = {"thing" -> "place", }
    '''
    assert parse(source) == [
        BinarySlurp([
            Ident('map'),
            Ident('='),
            Map([
                BinarySlurp([String('thing'),
                             Ident('->'),
                             String('place')]),
            ])
        ])
    ]
Esempio n. 7
0
def test_single_tuple():
    source = '''
    tuple = ("thing" -> "place",)
    '''
    assert parse(source) == [
        BinarySlurp([
            Ident('tuple'),
            Ident('='),
            Tuple([
                BinarySlurp([String('thing'),
                             Ident('->'),
                             String('place')]),
            ])
        ])
    ]
Esempio n. 8
0
def test_float_sigil():
    source = r'''
    10 + 3.0i
    '''
    assert parse(source) == [
        BinarySlurp([Int(10), Ident('+'), Float(3.0, 'i')])
    ]
Esempio n. 9
0
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!')])])
                ])
            ])
        ])
    ]
Esempio n. 10
0
def test_bigint_small():
    source = '''
    x = 3e-10
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(int(3e-10))])
    ]
Esempio n. 11
0
def test_int_underscore():
    source = '''
    x = 3_000_000
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(3000000)])
    ]
Esempio n. 12
0
def test_simple_binary_slurp():
    source = '''
    puts 1+2
    '''
    assert parse(source) == [
        Call(Ident('puts'),
             [BinarySlurp([Int(1), Ident('+'), Int(2)])])
    ]
Esempio n. 13
0
def test_empty_tuple():
    source = '''
    tuple = ()
    '''
    assert parse(source) == [
        BinarySlurp([Ident('tuple'), Ident('='),
                     Tuple()])
    ]
Esempio n. 14
0
def test_bigint_trailing_underscore():
    source = '''
    x = 3_00_e1_0_
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(int(300e10))])
    ]
Esempio n. 15
0
def test_single_list_trailing():
    source = '''
    list = [1, ]
    '''
    assert parse(source) == [
        BinarySlurp([Ident('list'), Ident('='),
                     List([Int(1)])])
    ]
Esempio n. 16
0
def test_op_identifier():
    source = '''
    plus = {+}
    '''
    assert parse(source) == [
        BinarySlurp([Ident('plus'), Ident('='),
                     Ident('+')])
    ]
Esempio n. 17
0
def test_binary_identifier():
    source = '''
    fn = {~and}
    '''
    assert parse(source) == [
        BinarySlurp([Ident('fn'), Ident('='),
                     Ident('and')])
    ]
Esempio n. 18
0
def test_ident_neq_nospace():
    source = '''
    works!=true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works!'),
                     Ident('='), Ident('true')])
    ]
Esempio n. 19
0
def test_question_neq():
    source = '''
    works != true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works'),
                     Ident('!='), Ident('true')])
    ]
Esempio n. 20
0
def test_ident_question_nospace():
    source = '''
    works?=true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works?'),
                     Ident('='), Ident('true')])
    ]
Esempio n. 21
0
def test_ident_exclamation():
    source = '''
    works! = true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works!'),
                     Ident('='), Ident('true')])
    ]
Esempio n. 22
0
def test_symbol():
    source = '''
    x = @thingy
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Symbol('thingy')])
    ]
Esempio n. 23
0
def test_float_trailing_underscore():
    source = '''
    x = 3_000_000.000_000_
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Float(3000000.0)])
    ]
Esempio n. 24
0
def test_bigfloat_underscore():
    source = '''
    x = 3_00.0e1_0
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Float(300e10)])
    ]
Esempio n. 25
0
def test_bigfloat_small():
    source = '''
    x = 3.0e-10
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Float(3e-10)])
    ]
Esempio n. 26
0
def test_int_nonsigil():
    source = r'''
    puts 10 + 3 i
    '''
    assert parse(source) == [
        Call(Ident('puts'),
             [BinarySlurp([Int(10), Ident('+'), Int(3)]),
              Ident('i')])
    ]
Esempio n. 27
0
def test_simple_call_statement():
    source = '''
    puts.("Hello, World!",)
    '''
    assert parse(source) == [
        BinarySlurp(
            [Ident('puts'),
             Ident('.'),
             Tuple([String("Hello, World!")])])
    ]
Esempio n. 28
0
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)])])
    ]
Esempio n. 29
0
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)])])
        ])
    ]
Esempio n. 30
0
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')])
            ])
        ])
    ]