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

test[scripting] 450 - Primitives

Primitive support tests.
Note:primitive support/customization is handled by ScriptParser class methods when Scripting framework is used.
In case of using S8 Compiler framework for scripting, directives/primitives are customized by events on SmalltalkParser (see SmalltalkParser>>#directive:ws:)

"testing primitive support"
(ScriptParser new parse: '
    <primitive: #hello>
    ^#ok
' onError: [:error| ^self note: 'NIY - ',error description ]) evaluate notNil ifTrue: [ self error: 'This should not happen' ]


"Implement basic primitive support (for testing)"
ScriptParser defaultPrimitiveHandler: [:parser :context :type|
    self note: 'Missing primitive support for ',type.
    nil
].
ScriptParser primitiveHandlers at: #basic: put: [:parser :context :type|
    | literal |
    literal := parser nextStringConstant: context.
    literal isNil ifTrue: [ literal := parser nextSymbolConstant: context. ].
    literal isNil
    ifTrue: [ parser expected: 'String constant' ]
    ifFalse: [ PrimitiveNode doing: [:ctx :node | node exitWith: (literal evaluateIn: ctx) ] ]
] 


"testing basic primitive support"
(ScriptParser new parse: '
    < basic: #hello >
    ^#ok
' onError: [:error| ^self note: 'NIY - ',error description ]) evaluate = #hello ifFalse: [ self error: 'Wrong result' ]