コード例 #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_curly_expression():
    source = '''
    puts 3 * {4 + 1}
    '''
    assert parse(source) == [
        Call(Ident('puts'), [
            BinarySlurp([
                Int(3),
                Ident('*'),
                BinarySlurp([Int(4), Ident('+'), Int(1)])
            ])
        ])
    ]
コード例 #3
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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)]),
        ])
    ]
コード例 #4
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)])
            ])
        ])
    ]
コード例 #5
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)])
        ])
    ]
コード例 #6
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_single_map():
    source = '''
    map = {"thing" -> "place", }
    '''
    assert parse(source) == [
        BinarySlurp([
            Ident('map'),
            Ident('='),
            Map([
                BinarySlurp([String('thing'),
                             Ident('->'),
                             String('place')]),
            ])
        ])
    ]
コード例 #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_float_sigil():
    source = r'''
    10 + 3.0i
    '''
    assert parse(source) == [
        BinarySlurp([Int(10), Ident('+'), Float(3.0, 'i')])
    ]
コード例 #9
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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!')])])
                ])
            ])
        ])
    ]
コード例 #10
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))])
    ]
コード例 #11
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_int_underscore():
    source = '''
    x = 3_000_000
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(3000000)])
    ]
コード例 #12
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)])])
    ]
コード例 #13
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_empty_tuple():
    source = '''
    tuple = ()
    '''
    assert parse(source) == [
        BinarySlurp([Ident('tuple'), Ident('='),
                     Tuple()])
    ]
コード例 #14
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))])
    ]
コード例 #15
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_single_list_trailing():
    source = '''
    list = [1, ]
    '''
    assert parse(source) == [
        BinarySlurp([Ident('list'), Ident('='),
                     List([Int(1)])])
    ]
コード例 #16
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_op_identifier():
    source = '''
    plus = {+}
    '''
    assert parse(source) == [
        BinarySlurp([Ident('plus'), Ident('='),
                     Ident('+')])
    ]
コード例 #17
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_binary_identifier():
    source = '''
    fn = {~and}
    '''
    assert parse(source) == [
        BinarySlurp([Ident('fn'), Ident('='),
                     Ident('and')])
    ]
コード例 #18
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_ident_neq_nospace():
    source = '''
    works!=true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works!'),
                     Ident('='), Ident('true')])
    ]
コード例 #19
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_question_neq():
    source = '''
    works != true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works'),
                     Ident('!='), Ident('true')])
    ]
コード例 #20
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_ident_question_nospace():
    source = '''
    works?=true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works?'),
                     Ident('='), Ident('true')])
    ]
コード例 #21
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_ident_exclamation():
    source = '''
    works! = true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works!'),
                     Ident('='), Ident('true')])
    ]
コード例 #22
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_symbol():
    source = '''
    x = @thingy
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Symbol('thingy')])
    ]
コード例 #23
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_float_trailing_underscore():
    source = '''
    x = 3_000_000.000_000_
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Float(3000000.0)])
    ]
コード例 #24
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_bigfloat_underscore():
    source = '''
    x = 3_00.0e1_0
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Float(300e10)])
    ]
コード例 #25
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
def test_bigfloat_small():
    source = '''
    x = 3.0e-10
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Float(3e-10)])
    ]
コード例 #26
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')])
    ]
コード例 #27
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!")])])
    ]
コード例 #28
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)])])
    ]
コード例 #29
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)])])
        ])
    ]
コード例 #30
0
ファイル: test_parser.py プロジェクト: agajews/Obsidian
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')])
            ])
        ])
    ]