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

test[scripting] 140 - Contexts

"locals in a context"
| result |
result := (ScriptParser new parse: ' | var outside steps middle inside |
	steps := #().
	var := #out. outside := #outside.
	steps add: (Array with: var with: outside).
	#(1 2 3) do: [:i| "| middle |"
		middle := i.
		var := #middle.
		steps add: (Array with: var with: middle with: outside).
		[:j|	"| inside |"
			inside := i + middle. var := #inside.
			steps add: (Array with: var with: middle with: outside with: #inside).
		] value: 10.
		middle := 2.
		steps add: (Array with: var with: middle with: outside).
	].
	steps
') evaluate.
result = #(
	#(#out #outside)
	#(#middle 1 #outside)
	#(#inside 1 #outside #inside)
	#(#inside 2 #outside)
	#(#middle 2 #outside)
	#(#inside 2 #outside #inside)
	#(#inside 2 #outside)
	#(#middle 3 #outside)
	#(#inside 3 #outside #inside)
	#(#inside 2 #outside)
) ifFalse: [ self error: 'Wrong result'].
#Ok 


"assignment to index"
| code |
code := '| steps |
	steps := #().
	#(1 2 3 4 5 6 7 8 9 0) do: [:i|
		i := i + 3. steps add: i
	]. steps'.
code evaluate = (ScriptParser new parse: code) evaluate ifFalse: [
	self error: 'Wrong result'
].


"exiting method context"
| url code |
url := 'https://www.facebook.com/groups/s8smalltalk'.
code := 'U8 absolutePathFor: ' ,url printString.
code evaluate = (ScriptParser new parse: code) evaluate ifFalse: [
	self error: 'Wrong result - exiting method context'
].