コード例 #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_multiple_op_slot_assignments():
    result = lex_and_parse('(| + b = (). - a = () |)')
    assert result == [
        Object(slots={
            "+": Object(params=["b"]),
            "-": Object(params=["a"]),
        })
    ]
コード例 #3
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"))])]
コード例 #4
0
def test_argument_parser():
    result = lex_and_parse('(| :a |)')
    assert result == [Object(params=["a"])]

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

    result = lex_and_parse('(| :a. :b |)')
    assert result == [Object(params=["a", "b"])]
コード例 #5
0
def test_parse_multiple_slots_assignments():
    result = lex_and_parse('(| asd: a Bsd: b = (). a: p = () |)')

    assert result == [
        Object(slots=OrderedDict((
            ("asd:Bsd:", Object(params=["a", "b"])),
            ("a:", Object(params=["p"])),
        )))
    ]
コード例 #6
0
def test_objects_with_objects_in_slots():
    result = lex_and_parse("""(|
    append: s = (||"Str: ")
|)""")

    assert result == [
        Object(slots=OrderedDict([
            ("append:", Object(params=["s"], code=[String("Str: ")])),
        ]))
    ]
コード例 #7
0
def test_parse_multiple_slot_assignment():
    result = lex_and_parse('(asd <- 2. bsd <- 4 |)')
    assert result == [
        Object(slots=rw_slots(
            OrderedDict((("asd", IntNumber(2)), ("bsd", IntNumber(4))))))
    ]

    result = lex_and_parse('(| asd <- 2. bsd <- 4. |)')
    assert result == [
        Object(slots=rw_slots(
            OrderedDict((("asd", IntNumber(2)), ("bsd", IntNumber(4))))))
    ]
コード例 #8
0
def test_parse_object_with_nil_slot():
    result = lex_and_parse('(| asd |)')
    assert result == [Object(slots=_rw_slot("asd", Nil()))]

    result = lex_and_parse('(| asd. |)')
    assert result == [Object(slots=_rw_slot("asd", Nil()))]

    result = lex_and_parse('(asd |)')
    assert result == [Object(slots=_rw_slot("asd", Nil()))]

    result = lex_and_parse('( asd. |)')
    assert result == [Object(slots=_rw_slot("asd", Nil()))]
コード例 #9
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"))])
    ]
コード例 #10
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"))])
    ]
コード例 #11
0
def test_parse_multiline_comment():
    result = lex_and_parse('''
    # this is example
    # of the multiline comment
        (|| self) # xe
    ''')

    assert result == [Object(code=[Self()])]
コード例 #12
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")))
        ])
    ]
コード例 #13
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)
    ]
コード例 #14
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"))])
    ]
コード例 #15
0
def test_parse_object_with_multiple_nil_slots():
    expected_result = [
        Object(slots=OrderedDict((("asd", Nil()), ("asd:",
                                                   AssignmentPrimitive()),
                                  ("bsd", Nil()), ("bsd:",
                                                   AssignmentPrimitive()))))
    ]

    result = lex_and_parse('(| asd. bsd |)')
    assert result == expected_result

    result = lex_and_parse('(| asd. bsd. |)')
    assert result == expected_result

    result = lex_and_parse('(asd. bsd. |)')
    assert result == expected_result
コード例 #16
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"))})
    ]
コード例 #17
0
def test_parse_slot_definition_with_combination_of_slots():
    result = lex_and_parse("""
        (|
            a.
            asd: b = ().
            asd: a Bsd: b = ().
            + b = ().
            - a = ().
            = a = ().
        |)
    """)

    slots = _rw_slot("a", Nil())
    slots.update(
        OrderedDict((
            ("asd:", Object(params=["b"])),
            ("asd:Bsd:", Object(params=["a", "b"])),
            ("+", Object(params=["b"])),
            ("-", Object(params=["a"])),
            ("=", Object(params=["a"])),
        )))

    assert result[0] == Object(slots=slots)
コード例 #18
0
def test_parse_rw_slot_assignment():
    result = lex_and_parse('( a <- 2 |)')

    assert result == [Object(slots=_rw_slot("a", IntNumber(2)))]
コード例 #19
0
def test_parse_kwd_slot_assignment():
    result = lex_and_parse('(| asd: a = () |)')
    assert result == [Object(slots={"asd:": Object(params=["a"])})]

    result = lex_and_parse('(| asd: a = (). |)')
    assert result == [Object(slots={"asd:": Object(params=["a"])})]
コード例 #20
0
def test_parse_comment():
    result = lex_and_parse('(|| self) # xe')

    assert result == [Object(code=[Self()])]
コード例 #21
0
def test_parse_kwd_slots_assignment_without_openning_slots():
    result = lex_and_parse('(| asd: a Bsd: b = (). |)')
    assert result == [Object(slots={"asd:Bsd:": Object(params=["a", "b"])})]
コード例 #22
0
def test_parse_op_slot_assignment():
    result = lex_and_parse('(| + b = () |)')
    assert result == [Object(slots={"+": Object(params=["b"])})]

    result = lex_and_parse('(+ b = (). |)')
    assert result == [Object(slots={"+": Object(params=["b"])})]
コード例 #23
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"]),
        })
    ]
コード例 #24
0
def test_object_without_slots():
    result = lex_and_parse('(|| a printLine)')

    assert result == [
        Object(code=[Send(Send(Self(), Message("a")), Message("printLine"))])
    ]