Beispiel #1
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()))]
Beispiel #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"))])
    ]
Beispiel #3
0
def rw_slots(slot_dict):
    slots = (_rw_slot(k, v) for k, v in slot_dict.iteritems())

    out = OrderedDict()
    for i in slots:
        out.update(i)

    return out
Beispiel #4
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"))
              ])
    ]
Beispiel #5
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"))])
    ]
Beispiel #6
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)
Beispiel #7
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"]),
        })
    ]
Beispiel #8
0
def test_parse_rw_slot_assignment():
    result = lex_and_parse('( a <- 2 |)')

    assert result == [Object(slots=_rw_slot("a", IntNumber(2)))]