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()])) ])) ]) ]
def test_parse_multiple_op_slot_assignments(): result = lex_and_parse('(| + b = (). - a = () |)') assert result == [ Object(slots={ "+": Object(params=["b"]), "-": Object(params=["a"]), }) ]
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"))])]
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"])]
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"])), ))) ]
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: ")])), ])) ]
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)))))) ]
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()))]
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"))]) ]
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"))]) ]
def test_parse_multiline_comment(): result = lex_and_parse(''' # this is example # of the multiline comment (|| self) # xe ''') assert result == [Object(code=[Self()])]
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"))) ]) ]
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) ]
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"))]) ]
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
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"))}) ]
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)
def test_parse_rw_slot_assignment(): result = lex_and_parse('( a <- 2 |)') assert result == [Object(slots=_rw_slot("a", IntNumber(2)))]
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"])})]
def test_parse_comment(): result = lex_and_parse('(|| self) # xe') assert result == [Object(code=[Self()])]
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"])})]
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"])})]
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"]), }) ]
def test_object_without_slots(): result = lex_and_parse('(|| a printLine)') assert result == [ Object(code=[Send(Send(Self(), Message("a")), Message("printLine"))]) ]