示例#1
0
def test_unquote_nested():
    source = '''
    $$var (do_stuff)
    '''
    assert parse(source) == [
        Call(Unquote(Unquote(Ident('var'))), [Call(Ident('do_stuff'))])
    ]
示例#2
0
def test_triple_string_interpolation_single():
    source = r'''
    puts """$greeting"""
    '''
    assert parse(source) == [
        Call(Ident('puts'), [InterpolatedString([Ident('greeting')])])
    ]
示例#3
0
def test_unary_in_call():
    source = '''
    puts (-x)
    '''
    assert parse(source) == [
        Call(Ident('puts'), [Call(Ident('-'), [Ident('x')])])
    ]
示例#4
0
def test_unquote_call():
    source = '''
    $(fn arg) (do_stuff)
    '''
    assert parse(source) == [
        Call(Unquote(Call(Ident('fn'), [Ident('arg')])),
             [Call(Ident('do_stuff'))])
    ]
示例#5
0
def test_empty_tuple():
    source = '''
    tuple = ()
    '''
    assert parse(source) == [
        BinarySlurp([Ident('tuple'), Ident('='),
                     Tuple()])
    ]
示例#6
0
def test_binary_identifier():
    source = '''
    fn = {~and}
    '''
    assert parse(source) == [
        BinarySlurp([Ident('fn'), Ident('='),
                     Ident('and')])
    ]
示例#7
0
def test_int_underscore():
    source = '''
    x = 3_000_000
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(3000000)])
    ]
示例#8
0
def test_ident_exclamation():
    source = '''
    works! = true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works!'),
                     Ident('='), Ident('true')])
    ]
示例#9
0
def test_bigint_small():
    source = '''
    x = 3e-10
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(int(3e-10))])
    ]
示例#10
0
def test_bigint_trailing_underscore():
    source = '''
    x = 3_00_e1_0_
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Int(int(300e10))])
    ]
示例#11
0
def test_symbol():
    source = '''
    x = @thingy
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Symbol('thingy')])
    ]
示例#12
0
def test_ident_question_nospace():
    source = '''
    works?=true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works?'),
                     Ident('='), Ident('true')])
    ]
示例#13
0
def test_bigfloat_underscore():
    source = '''
    x = 3_00.0e1_0
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Float(300e10)])
    ]
示例#14
0
def test_float_trailing_underscore():
    source = '''
    x = 3_000_000.000_000_
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Float(3000000.0)])
    ]
示例#15
0
def test_question_neq():
    source = '''
    works != true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works'),
                     Ident('!='), Ident('true')])
    ]
示例#16
0
def test_bigfloat_small():
    source = '''
    x = 3.0e-10
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'), Ident('='),
                     Float(3e-10)])
    ]
示例#17
0
def test_simple_multiple_singleline_statements():
    source = '''
    puts "Hello!"; puts "World!"
    '''
    assert parse(source) == [
        Call(Ident('puts'), [String('Hello!')]),
        Call(Ident('puts'), [String('World!')]),
    ]
示例#18
0
def test_single_list_trailing():
    source = '''
    list = [1, ]
    '''
    assert parse(source) == [
        BinarySlurp([Ident('list'), Ident('='),
                     List([Int(1)])])
    ]
示例#19
0
def test_ident_neq_nospace():
    source = '''
    works!=true
    '''
    assert parse(source) == [
        BinarySlurp([Ident('works!'),
                     Ident('='), Ident('true')])
    ]
示例#20
0
def test_simple_binary_slurp():
    source = '''
    puts 1+2
    '''
    assert parse(source) == [
        Call(Ident('puts'),
             [BinarySlurp([Int(1), Ident('+'), Int(2)])])
    ]
示例#21
0
def test_op_identifier():
    source = '''
    plus = {+}
    '''
    assert parse(source) == [
        BinarySlurp([Ident('plus'), Ident('='),
                     Ident('+')])
    ]
示例#22
0
def test_whitespace_map():
    source = '''
    {
    fn,
    arg1,
    arg2,
    }
    '''
    assert parse(source) == [Map([Ident('fn'), Ident('arg1'), Ident('arg2')])]
示例#23
0
def test_whitespace_list():
    source = '''
    [
    fn,
    arg1,
    arg2,
    ]
    '''
    assert parse(source) == [List([Ident('fn'), Ident('arg1'), Ident('arg2')])]
示例#24
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')])
    ]
示例#25
0
def test_whitespace_call():
    source = '''
    (
    fn
    arg1
    arg2
    )
    '''
    assert parse(source) == [Call(Ident('fn'), [Ident('arg1'), Ident('arg2')])]
示例#26
0
def test_simple_call_statement():
    source = '''
    puts.("Hello, World!",)
    '''
    assert parse(source) == [
        BinarySlurp(
            [Ident('puts'),
             Ident('.'),
             Tuple([String("Hello, World!")])])
    ]
示例#27
0
def test_comment():
    source = r'''
    puts "Hello!"  # inline
    # prints "Hello\nWorld!"
    puts "World!"
    '''
    assert parse(source) == [
        Call(Ident('puts'), [String('Hello!')]),
        Call(Ident('puts'), [String('World!')]),
    ]
示例#28
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)])])
        ])
    ]
示例#29
0
def test_dots():
    source = '''
    x = 1...3
    '''
    assert parse(source) == [
        BinarySlurp([Ident('x'),
                     Ident('='),
                     Int(1),
                     Ident('...'),
                     Int(3)])
    ]
示例#30
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)])])
    ]