Пример #1
0
def test_object_with_parents():
    result = lex_and_parse('(| p* = traits | a printLine)')

    assert result == [
        Object(parents={"p": Send(Self(), Message("traits"))},
               code=[Send(Send(Self(), Message("a")), Message("printLine"))])
    ]
Пример #2
0
def test_obj_with_code_with_dot():
    result = lex_and_parse('(| a | a printLine.)')

    assert result == [
        Object(slots=_rw_slot("a", Nil()),
               code=[Send(Send(Self(), Message("a")), Message("printLine"))])
    ]
Пример #3
0
def test_parse_cascade_to_self():
    result = lex_and_parse('a; b')

    assert result == [
        Cascade(obj=Self(), msgs=[
            Message("a"),
            Message("b"),
        ])
    ]
Пример #4
0
def test_block_with_just_code():
    result = lex_and_parse('[ a printLine. a print. test]')

    assert result == [
        Block(code=[
            Send(Send(Self(), Message("a")), Message("printLine")),
            Send(Send(Self(), Message("a")), Message("print")),
            Send(Self(), Message("test"))
        ])
    ]
Пример #5
0
def test_return_in_block():
    result = lex_and_parse('[ a printLine. a print. ^test]')

    assert result == [
        Block(code=[
            Send(Send(Self(), Message("a")), Message("printLine")),
            Send(Send(Self(), Message("a")), Message("print")),
            Return(Send(Self(), Message("test")))
        ])
    ]
Пример #6
0
def test_parse_cascade():
    result = lex_and_parse('a b; c')

    assert result == [
        Cascade(obj=Send(Self(), Message("a")),
                msgs=[
                    Message("b"),
                    Message("c"),
                ])
    ]
Пример #7
0
def test_return_in_object():
    result = lex_and_parse('(|| a printLine. a print. ^test)')

    assert result == [
        Object(code=[
            Send(Send(Self(), Message("a")), Message("printLine")),
            Send(Send(Self(), Message("a")), Message("print")),
            Return(Send(Self(), Message("test")))
        ])
    ]
Пример #8
0
def test_parse_chained_messages():
    result = lex_and_parse('2 minus minus')

    assert result == [
        Send(obj=Send(
            obj=IntNumber(2),
            msg=Message('minus'),
        ),
             msg=Message('minus'))
    ]
Пример #9
0
def test_block_empty_slots_and_code():
    result = lex_and_parse('[|| a printLine. a print. test]')

    assert result == [
        Block(code=[
            Send(Send(Self(), Message("a")), Message("printLine")),
            Send(Send(Self(), Message("a")), Message("print")),
            Send(Self(), Message("test"))
        ])
    ]
Пример #10
0
def test_multiple_cascades():
    result = lex_and_parse('obj a; b; c')

    assert result == [
        Cascade(obj=Send(Self(), Message("obj")),
                msgs=[
                    Message("a"),
                    Message("b"),
                    Message("c"),
                ])
    ]
Пример #11
0
def test_parse_cascade_kw():
    result = lex_and_parse('s a: 1 B: 2; b')

    assert result == [
        Cascade(obj=Send(Self(), Message("s")),
                msgs=[
                    KeywordMessage("a:B:",
                                   [IntNumber(1), IntNumber(2)]),
                    Message("b"),
                ])
    ]
Пример #12
0
def test_block_with_code_statements():
    result = lex_and_parse('[| a. :b | a printLine. a print. test]')

    assert result == [
        Block(slots=_rw_slot("a", Nil()),
              params=["b"],
              code=[
                  Send(Send(Self(), Message("a")), Message("printLine")),
                  Send(Send(Self(), Message("a")), Message("print")),
                  Send(Self(), Message("test"))
              ])
    ]
Пример #13
0
def test_parse_chained_kw_and_unary_msgs():
    result = lex_and_parse('ifTrue: [] not not')

    assert result == [
        Send(obj=Self(),
             msg=KeywordMessage(name='ifTrue:',
                                parameters=[
                                    Send(obj=Send(obj=Block(),
                                                  msg=Message('not')),
                                         msg=Message('not'))
                                ])),
    ]
Пример #14
0
def test_parse_chained_messages_kw():
    result = lex_and_parse('2 minus ifTrue: []')

    assert result == [
        Send(obj=Send(obj=IntNumber(2), msg=Message('minus')),
             msg=KeywordMessage(name='ifTrue:', parameters=[Block()]))
    ]
Пример #15
0
def test_parse_keyword_message_to_obj_with_parameters():
    result = lex_and_parse('asd set: 1')

    assert result == [
        Send(obj=Send(obj=Self(), msg=Message('asd')),
             msg=KeywordMessage(name='set:', parameters=[IntNumber(1)]))
    ]
Пример #16
0
def test_self_kw():
    result = lex_and_parse('(|| self)')

    assert result == [Object(code=[Self()])]

    result = lex_and_parse('(|| self xe)')

    assert result == [Object(code=[Send(Self(), Message("xe"))])]
Пример #17
0
def test_resend():
    result = lex_and_parse('''(| p* = xe. |
        p.msg.
        p.kwd: x Msg: y.
    )''')

    assert result == [
        Object(code=[
            Resend(parent_name="p", msg=Message("msg")),
            Resend(parent_name="p",
                   msg=KeywordMessage(name="kwd:Msg:",
                                      parameters=[
                                          Send(obj=Self(), msg=Message("x")),
                                          Send(obj=Self(), msg=Message("y"))
                                      ]))
        ],
               parents={"p": Send(obj=Self(), msg=Message("xe"))})
    ]
Пример #18
0
def test_parse_cascade_kw_to_self():
    result = lex_and_parse('a: 1; b')

    assert result == [
        Cascade(obj=Self(),
                msgs=[
                    KeywordMessage("a:", [IntNumber(1)]),
                    Message("b"),
                ])
    ]
Пример #19
0
def test_multiple_statements_make_code():
    result = lex_and_parse('''
        xe.
        (|| self).
        1''')

    assert result == [
        Send(obj=Self(), msg=Message('xe')),
        Object(code=[Self()]),
        IntNumber(1)
    ]
Пример #20
0
def test_recursive_obj_definition():
    result = lex_and_parse("""
        (|
            a = (| var | var printLine. var).
            b <- nil.
        | nil.)
    """)

    assert result == [
        Object(slots=join_dicts(
            {
                "a":
                Object(slots=_rw_slot("var", Nil()),
                       code=[
                           Send(Send(Self(), Message("var")),
                                Message("printLine")),
                           Send(Self(), Message("var")),
                       ])
            }, _rw_slot("b", Send(Self(), Message("nil")))),
               code=[Send(Self(), Message("nil"))])
    ]
Пример #21
0
def test_parse_keyword_message_to_obj_with_multiple_parameters():
    result = lex_and_parse('asd set: 1 And: 2 Also: 3 So: 4')

    assert result == [
        Send(obj=Send(obj=Self(), msg=Message('asd')),
             msg=KeywordMessage(name='set:And:Also:So:',
                                parameters=[
                                    IntNumber(1),
                                    IntNumber(2),
                                    IntNumber(3),
                                    IntNumber(4)
                                ]))
    ]
Пример #22
0
def test_parse_multiple_sends():
    result = lex_and_parse('a b c d e f g')

    assert result == [
        Send(obj=Send(obj=Send(obj=Send(obj=Send(obj=Send(obj=Send(
            obj=Self(), msg=Message('a')),
                                                          msg=Message('b')),
                                                 msg=Message('c')),
                                        msg=Message('d')),
                               msg=Message('e')),
                      msg=Message('f')),
             msg=Message('g'))
    ]
Пример #23
0
def test_parse_send():
    result = lex_and_parse('asd')

    assert result == [Send(obj=Self(), msg=Message('asd'))]
Пример #24
0
def test_object_without_slots():
    result = lex_and_parse('(|| a printLine)')

    assert result == [
        Object(code=[Send(Send(Self(), Message("a")), Message("printLine"))])
    ]
Пример #25
0
def test_parse_send_to_object():
    result = lex_and_parse('a b')

    assert result == [
        Send(obj=Send(obj=Self(), msg=Message('a')), msg=Message('b'))
    ]