[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
test[sharing] S8-VSE 03 series
Tests for multiple objects (in a series).
Note that the following expression must be run in VSE, pasting the next code to workspace by hand
"Read objects in a series"
self cancelFileIn!
| series objectifier sample object tag point tab stringifier |
series := #( '{"origin":"S8","id":11,"contents":{"id":2,"class":{"id":3,"global":"Array"},"contents":[{"id":4,"class":" 3","contents":[" 2",{"1":700,"2":" 4","id":5,"class":{"id":6,"global":"Point","allInstVarNames":["x","y"]}},{"1":"hello\nworld / crude\tworld \bČ","2":" 4","id":7,"class":{"id":8,"global":"Association","allInstVarNames":["key","value"]}},{"id":9,"global":"String"}," ",600,700.7,"x",null," "," hello"]}," 5","A",{"id":10,"class":{"id":11,"global":"Set","allInstVarNames":["contents"]},"contents":["print:","fileIn:","fileInJS:","smalltalk","nativeLanguage","halt","note:","notImplementedYet","notImplementedYet:","accept:","=","~=","initialize","yourself","class","size","copy","shallowCopy","deepCopyOf:","deepCopy","->","asString","toString","asNative:","asNative","asJSON","escapedCode","perform:","perform:with:","perform:withArguments:","basicAt:","basicAt:ifAbsent:","basicAt:ifAbsentPut:","instVarAt:","instVarAt:put:","basicAt:put:","error:","subclassResponsibility","implementedBySubclass","shouldNotImplement","invalidMessage","subclassResponsibility:","implementedBySubclass:","shouldNotImplement:","invalidMessage:","smalltalkErrorOf:","inspect","basicInspect","printString","isKindOf:","isMemberOf:","ifNil:","ifNil:ifNotNil:","ifNotNil:","ifNotNil:ifNil:","isNil","notNil","isClass","isMetaclass","isNumber","isString","isArray","isObject:","typeOf:","methodFor:","respondsTo:","basicDelete:","doesNotUnderstand:","dnu:withArguments:","basicPerform:withArguments:","json","asJson:","asJSONObject","jsonHiddenNames","jsonFieldsDo:ignoring:","jsonExportNil","mustBeBoolean","mustBeNumber","isBoolean","asLiteral","isCharacter","isAssociation","isDictionary","isRectangle","isMessage","argumentCount","numberOfArguments","evaluate","evaluateDeferred","evaluateWithArguments:","evaluateWith:","logEvaluate:","asActionSequence","eventTable","eventTableForEdit","releaseEventTable","release","eventTableCreate","canTriggerEvent:","invalidEvent:","when:evaluate:","actionListForEvent:","setActionList:forEvent:","removeActionsSatisfying:forEvent:","removeActionsWithReceiver:forEvent:","removeAction:forEvent:","when:do:","when:send:to:withArguments:","when:send:to:","triggerEvent:ifNotHandled:","actionForEvent:","triggerEvent:","triggerEvent:withArguments:","triggerEvent:with:","triggerEvent:with:with:","triggerEvent:withArguments:ifNotHandled:","triggerEvent:with:ifNotHandled:","hasActionForEvent:","eventsHandled","removeAllActionsWithReceiver:","removeActionsForEvent:","addDependent:","changed","updateEvent:selector:arguments:","changed:","changed:with:","changed:with:with:","dependents","update:with:","update:","printingWith:do:","isParseFailure","asParser","ifUndefined:","orNil","scanFrom:","javascriptCodeFollows","cancelFileIn","ignoreFileInUpTo:","==","~~","isFile:olderThan:","emmit:startingWith:","emmit:","asJS","asNativeHandle","handleOf:","asJavascript","alert:","confirm:","prompt:","prompt:default:","promptValue:","inspectorSupport"]}]}}' '{"origin":"S8","id":11,"contents":" 5"}' '{"origin":"S8","id":11,"contents":" 7"}' '{"origin":"S8","id":11,"contents":" 9"}' '{"origin":"S8","id":11,"contents":" "}' '{"origin":"S8","id":11,"contents":600}' '{"origin":"S8","id":11,"contents":700.7}' '{"origin":"S8","id":11,"contents":"x"}' '{"origin":"S8","id":11,"contents":null}' '{"origin":"S8","id":11,"contents":" "}' '{"origin":"S8","id":11,"contents":" hello"}' ).
objectifier := Objectifier new.
sample := series collect: [:literal| objectifier objectFrom: literal ].
sample isArray ifFalse: [ self error: 'Must be Array' ].
sample first first = sample ifFalse: [ self error: '1.1.- Must be sample' ].
(sample first at: 2) x = 700 ifFalse: [ self error: '1.2.- Must be Point x 700' ].
(sample first at: 2) y = sample ifFalse: [ self error: '1.2.- Must be Point y = sample' ].
(sample first at: 3) = 'A' ifFalse: [ self error: '1.3.- Must be $A' ].
((sample first at: 4) isKindOf: Set) ifFalse: [ self error: '1.4.- Must be a Set' ].
((sample first at: 4) includes: 'yourself') ifFalse: [ self error: '1.4.- #yourself must be present' ].
((sample at: 2) isKindOf: Point) ifFalse: [ self error: '2.- Must be aPoint' ].
(sample at: 2) x = 700 ifFalse: [ self error: '2.1.- Must be Point x 700' ].
(sample at: 2) y = sample ifFalse: [ self error: '2.2.- Must be Point y = sample' ].
((sample at: 3) isKindOf: Association) ifFalse: [ self error: '3.- Must be anAssociation' ].
((sample at: 3) key isKindOf: String) ifFalse: [ self error: '3.1.- key must be aString' ].
object := (sample at: 3).
(object key includes: 8 asCharacter) ifFalse: [ self error: '3.1.1.- Bs must be included' ].
object key last asciiValue = 200 ifFalse: [ self error: '3.1.2.- Character 200 must be included' ].
(object key indexOf: $/) = 13 ifFalse: [ self error: '3.1.3.- $/ must be at index 14' ].
object value = sample ifFalse: [ self error: '3.2.- Value must be sample' ].
(sample at: 4) = String ifFalse: [ self error: '4.- Must be String' ].
(sample at: 6) = 600 ifFalse: [ self error: '6.- Must be 600' ].
(sample at: 7) = 700.7 ifFalse: [ self error: '7.- Must be 700.7' ].
(sample at: 8) = 'x' ifFalse: [ self error: '8.- Must be #x' ].
(sample at: 9) isNil ifFalse: [ self error: '9.- Must be nil' ].
(sample at: 10) ,#hello = (sample at: 11) ifFalse: [ self error: '10.- Wrong contents at 10&11' ].
^#Ok
To generate the contents for this test, evaluate the following code in S8
| series objectifier sample object tag point tab stringifier |
tag := Stringifier new tagStart.
sample := #( 100 200 300 400 500 600 700.7 ) ,(Array with: #x with: nil with: tag with: tag ,#hello).
point := 700 @ sample.
sample at: 1 put: (Array with: sample with: point with: $A with: Object selectors asSet).
sample at: 2 put: point.
sample at: 3 put: (Association key: 'hello
world / crude',9 asCharacter,'world ',8 asCharacter ,200 asCharacter value: sample).
sample at: 4 put: String.
sample at: 5 put: tag,tag,tag.
self print: 'Stringifying Series...'.
stringifier := Stringifier to: #S8.
series := sample collect: [:each| stringifier literalFor: each ].
stringifier close.
self print: series asLiteral.
^series