コード例 #1
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_whitespace_single_tuple():
    source = '''
    (
    fn,
    )
    '''
    assert parse(source) == [Tuple([Ident('fn')])]
コード例 #3
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_empty_tuple():
    source = '''
    tuple = ()
    '''
    assert parse(source) == [
        BinarySlurp([Ident('tuple'), Ident('='),
                     Tuple()])
    ]
コード例 #4
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_simple_call_statement():
    source = '''
    puts.("Hello, World!",)
    '''
    assert parse(source) == [
        BinarySlurp(
            [Ident('puts'),
             Ident('.'),
             Tuple([String("Hello, World!")])])
    ]
コード例 #5
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_whitespace_tuple():
    source = '''
    (
    fn,
    arg1,
    arg2,
    )
    '''
    assert parse(source) == [
        Tuple([Ident('fn'), Ident('arg1'),
               Ident('arg2')])
    ]
コード例 #6
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_single_tuple():
    source = '''
    tuple = ("thing" -> "place",)
    '''
    assert parse(source) == [
        BinarySlurp([
            Ident('tuple'),
            Ident('='),
            Tuple([
                BinarySlurp([String('thing'),
                             Ident('->'),
                             String('place')]),
            ])
        ])
    ]
コード例 #8
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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')])
                ])
            ])
        ])
    ]