[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
app[simulator] expressions
Expressions to test exception management on S8Simulator
"Ensure S8Simulator is loaded"
self require: #( S8Simulator )
in: (#(Bindings Scripting ScriptCompiler ScriptSteps) collect: [:each|
'u8:aleReimondo/s8/library/scripting/',each,'.st.js' ])
"Expressions to test exceptions'
S8Simulator testAll: #(
'[ 3 + 4 ] ensure: [ self note: 77 ]'
'[^10] ifCurtailed: [ self note: ''We see this''. 77 ]'
'[ self error: #test ] ifCurtailed: [ self note: #Abandoned. 77 ]'
'[1 / 0 - 2] ifCurtailed: [ self note: #Abandoned. 77 ]'
'([[ self error: #error1 ] on: Exception do: [ self error: #error2 ]] on: Exception do: [:ex | ex description ]) = #error2.
([|result| result := 3 + 4. self error: #test. result ] on: Error do: [:ex| ex description ]) = #test'
)
"Expressions to test loop shortcuts'
S8Simulator testAll: #(
'3 timesRepeat: [:i| self note: i ].'
'1 timesRepeat: [:i| self note: i ].'
'0 timesRepeat: [:i| self note: i ].'
'-3 timesRepeat: [:i| self note: i ].'
'#( 1 2 3 ) do: [:x| self note: x ].'
'#() do: [:x| self note: x ].'
'(1 to: 3) do: [:x| self note: x ].'
'#hello do: [:x| self note: x ].'
'#( 1 2 3 ) reverseDo: [:x| self note: x ].'
'#() reverseDo: [:x| self note: x ].'
'#hello reverseDo: [:x| self note: x ].'
'#( 1 2 3 ) withIndexDo: [:x :i| self note: $#,i ,$ ,x ].'
'#() withIndexDo: [:x :i| self note: $#,i ,$ ,x ].'
'#hello withIndexDo: [:x :i| self note: $#,i ,$ ,x ].'
'1 to: 10 by: 5 do: [:i| self note: i ]'
'1 to: 10 by: -7 do: [:i| self note: i ]'
'10 to: 1 by: -3 do: [:i| self note: i ]'
'10 to: 1 by: 33 do: [:i| self note: i ]'
'1 to: 2 do: [:i| self note: i ]'
'1 to: 1 do: [:i| self note: i ]'
'10 to: 1 do: [:i| self note: i ]'
)
"Expressions to test inlinned shortcuts'
S8Simulator testAll: #(
'3 > 2 ifTrue: [#hello size]'
'2 > 3 ifFalse: [#world size]'
'3@5 instVarAt: #x'
'(#hello -> #world) json'
'#(1 2 3 4 5) asLiteral size'
)
"Expressions to test inlinned shortcuts'
S8Simulator testAll: #(
'3 > 2 ifTrue: [#hello size]'
'2 > 3 ifFalse: [#world size]'
'3@5 instVarAt: #x'
'(#hello -> #world) json'
'#(1 2 3 4 5) asLiteral size'
'JS @ (#hello -> #world) json @ #hello = #world'
)