示例#1
0
def test_tuple_deconstruction():
    source = '''
    (name, occupation) = ("John Smith", @farmer)
    '''
    assert parse(source) == [
        BinarySlurp([
            Tuple([Ident('name'), Ident('occupation')]),
            Ident('='),
            Tuple([String('John Smith'),
                   Symbol('farmer')])
        ])
    ]
示例#2
0
def test_whitespace_single_tuple():
    source = '''
    (
    fn,
    )
    '''
    assert parse(source) == [Tuple([Ident('fn')])]
示例#3
0
def test_empty_tuple():
    source = '''
    tuple = ()
    '''
    assert parse(source) == [
        BinarySlurp([Ident('tuple'), Ident('='),
                     Tuple()])
    ]
示例#4
0
def test_simple_call_statement():
    source = '''
    puts.("Hello, World!",)
    '''
    assert parse(source) == [
        BinarySlurp(
            [Ident('puts'),
             Ident('.'),
             Tuple([String("Hello, World!")])])
    ]
示例#5
0
def test_whitespace_tuple():
    source = '''
    (
    fn,
    arg1,
    arg2,
    )
    '''
    assert parse(source) == [
        Tuple([Ident('fn'), Ident('arg1'),
               Ident('arg2')])
    ]
示例#6
0
def test_if_not():
    source = '''
    if (not thing.())
        puts "badness"
    '''
    assert parse(source) == [
        Call(Ident('if'), [
            Call(Ident('not'),
                 [BinarySlurp([Ident('thing'),
                               Ident('.'), Tuple()])]),
            Block([Call(Ident('puts'), [String('badness')])])
        ])
    ]
示例#7
0
def test_single_tuple():
    source = '''
    tuple = ("thing" -> "place",)
    '''
    assert parse(source) == [
        BinarySlurp([
            Ident('tuple'),
            Ident('='),
            Tuple([
                BinarySlurp([String('thing'),
                             Ident('->'),
                             String('place')]),
            ])
        ])
    ]
示例#8
0
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')])
                ])
            ])
        ])
    ]