示例#1
0
def test_parens_for_priority():
    result = lex_and_parse('(|| 1 > (2 xex: 1) ifTrue: [] )')

    assert result == [
        Object(code=[
            Send(obj=Send(obj=IntNumber(1),
                          msg=BinaryMessage(
                              name='>',
                              parameter=Send(obj=IntNumber(2),
                                             msg=KeywordMessage(
                                                 name='xex:',
                                                 parameters=[IntNumber(1)])))),
                 msg=KeywordMessage(name='ifTrue:', parameters=[Block()]))
        ])
    ]

    # and now without parens
    result = lex_and_parse('(|| 1 > 2 xex: 1 ifTrue: [] )')

    assert result == [
        Object(code=[
            Send(obj=Send(obj=IntNumber(1),
                          msg=BinaryMessage(name='>', parameter=IntNumber(2))),
                 msg=KeywordMessage(name='xex:',
                                    parameters=[
                                        Send(obj=IntNumber(1),
                                             msg=KeywordMessage(
                                                 name='ifTrue:',
                                                 parameters=[Block()]))
                                    ]))
        ])
    ]
示例#2
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()]))
    ]
示例#3
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")))
        ])
    ]
示例#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_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"))
        ])
    ]
示例#6
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"))
              ])
    ]
示例#7
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'))
                                ])),
    ]
示例#8
0
def test_block_slots():
    # result = lex_and_parse('[ asd. |]')
    # assert result == Block(slots={"asd": None})

    result = lex_and_parse('[| asd <- 2 |]')
    assert result == [Block(slots=_rw_slot("asd", IntNumber(2)))]

    result = lex_and_parse('[| asd <- 2. |]')
    assert result == [Block(slots=_rw_slot("asd", IntNumber(2)))]

    result = lex_and_parse('[asd <- 2. bsd <- 4 |]')
    assert result == [
        Block(slots=rw_slots(
            OrderedDict((("asd", IntNumber(2)), ("bsd", IntNumber(4))))))
    ]

    result = lex_and_parse('[| asd <- 2. bsd <- 4. |]')
    assert result == [
        Block(slots=rw_slots(
            OrderedDict((("asd", IntNumber(2)), ("bsd", IntNumber(4))))))
    ]

    result = lex_and_parse('[| asd: a = () |]')
    assert result == [Block(slots={"asd:": Object(params=["a"])})]

    result = lex_and_parse('[| asd: a = (). |]')
    assert result == [Block(slots={"asd:": Object(params=["a"])})]

    result = lex_and_parse('[| asd: a Bsd: b = () |]')
    assert result == [Block(slots={"asd:Bsd:": Object(params=["a", "b"])})]

    result = lex_and_parse('[| :a |]')
    assert result == [Block(params=["a"])]

    result = lex_and_parse('[| :a. |]')
    assert result == [Block(params=["a"])]

    result = lex_and_parse('[| :a. :b |]')
    assert result == [Block(params=["a", "b"])]

    result = lex_and_parse('[:a |]')
    assert result == [Block(params=["a"])]

    result = lex_and_parse('[ :a. |]')
    assert result == [Block(params=["a"])]

    result = lex_and_parse('[:a. :b |]')
    assert result == [Block(params=["a", "b"])]

    result = lex_and_parse('[| + b = () |]')
    assert result == [Block(slots={"+": Object(params=["b"])})]

    result = lex_and_parse('[+ b = (). |]')
    assert result == [Block(slots={"+": Object(params=["b"])})]

    result = lex_and_parse('[| + b = (). - a = () |]')
    assert result == [
        Block(slots={
            "+": Object(params=["b"]),
            "-": Object(params=["a"]),
        })
    ]
示例#9
0
def test_empty_block():
    result = lex_and_parse('[]')
    assert result == [Block()]