[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[scripting] 020 - Messages

"message sends"
(ScriptParser new parse: 'Smalltalk selectors sorted') evaluate = Smalltalk selectors sorted
    ifFalse: [ self error: 'Error evaluating simple message sends' ]


"3+4"
(ScriptParser new parse: '3+4') evaluate = (3+4)
    ifFalse: [ self error: 'Error evaluating 3+4' ]


"0@0 + 5"
(ScriptParser new parse: '0@0 + 5') evaluate = (5@5)
    ifFalse: [ self error: 'Wrong result' ]


"12 class"
(ScriptParser new parse: '12 class') evaluate = 12 class
    ifFalse: [ self error: 'Wrong result' ]


"Simple message sends"
#(  '#new size + 5'
    '3 + 4 * 5'
    '12 between: 2*5 and: 12000000 - 300'
    'Smalltalk classes'
    'Smalltalk at: #Point'
    '(Smalltalk at: (''Po'',''int'') asSymbol) selectors asArray '
    'Association key: #key value: 123'
    '(Association key: #key value: 123) key = #key'
) do: [:code|
    (ScriptParser new parse: code) evaluate = code evaluate
    ifFalse: [ self error: 'Error evaluating ' ,code asLiteral ]
]


"DateTime expressions"
(Smalltalk includesKey: #DateTime) ifFalse: [ ^false ].

(ScriptParser new
        parse: 'DateTime now hours > 10 ifTrue: [ DateTime today ] ifFalse: [''es muyyy temprano'']'
        onError: [:error| self error: error description ]
) evaluate.

(ScriptParser new parse: '
            DateTime now hours > 10
                ifTrue: [ ^DateTime today ]
                ifFalse: [^''too early''].
             12 must not be running here. '
        onError: [:error| self error: error description ]
) evaluate.