コード例 #1
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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)])
                ])
            ])
        ])
    ]
コード例 #2
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_simple_binary_slurp():
    source = '''
    puts 1+2
    '''
    assert parse(source) == [
        Call(Ident('puts'),
             [BinarySlurp([Int(1), Ident('+'), Int(2)])])
    ]
コード例 #3
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_int_nonsigil():
    source = r'''
    puts 10 + 3 i
    '''
    assert parse(source) == [
        Call(Ident('puts'),
             [BinarySlurp([Int(10), Ident('+'), Int(3)]),
              Ident('i')])
    ]
コード例 #4
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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)])])
        ])
    ]
コード例 #5
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_dots():
    source = '''
    x = 1...3
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'),
                     Ident('='),
                     Int(1),
                     Ident('...'),
                     Int(3)])
    ]
コード例 #6
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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)])])
    ]
コード例 #7
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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)])
            ])
        ])
    ]
コード例 #8
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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)])
            ])
        ])
    ]
コード例 #9
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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')])])
        ])
    ]
コード例 #10
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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)]),
            ])
        ]),
    ]
コード例 #11
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_float_sigil():
    source = r'''
    10 + 3.0i
    '''
    assert parse(source) == [
        BinarySlurp([Int(10), Ident('+'), Float(3.0, 'i')])
    ]
コード例 #12
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_single_list_trailing():
    source = '''
    list = [1, ]
    '''
    assert parse(source) == [
        BinarySlurp([Ident('list'), Ident('='),
                     List([Int(1)])])
    ]
コード例 #13
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_bigint_trailing_underscore():
    source = '''
    x = 3_00_e1_0_
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(int(300e10))])
    ]
コード例 #14
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_bigint_small():
    source = '''
    x = 3e-10
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(int(3e-10))])
    ]
コード例 #15
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_int_underscore():
    source = '''
    x = 3_000_000
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(3000000)])
    ]
コード例 #16
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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')])])
    ]
コード例 #17
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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')])
                ])
            ])
        ])
    ]
コード例 #18
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')])
                ])
            ])
        ])
    ]
コード例 #19
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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)])
        ])
    ]
コード例 #20
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_toplevel_expression():
    source = '''
    3 + 4
    '''
    assert parse(source) == [BinarySlurp([Int(3), Ident('+'), Int(4)])]
コード例 #21
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_int():
    source = '''
    x = 3
    '''
    assert parse(source) == [BinarySlurp([Ident('x'), Ident('='), Int(3)])]
コード例 #22
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_int_sigil():
    source = r'''
    10 + 3i
    '''
    assert parse(source) == [BinarySlurp([Int(10), Ident('+'), Int(3, 'i')])]