Note Characters from S8 comes to VSE as Strings |
"Testing object with circular references. Note that this code MUST be run in VSE." self cancelFileIn! | sample object | sample := '{"origin":"S8","id":11,"contents":{"id":2,"class":{"id":3,"global":"Array"},"contents":[{"id":4,"class":" 3","contents":[" 2",{"1":700,"2":" 2","id":5,"class":{"id":6,"global":"Point","allInstVarNames":["x","y"]}},"A",{"id":7,"class":{"id":8,"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"]}]}," 5",{"1":"hello\nworld / crude\tworld \bČ","2":" 2","id":9,"class":{"id":10,"global":"Association","allInstVarNames":["key","value"]}},{"id":11,"global":"String"}," ",600,700.7,"x",null," "," hello"]}}' asObject. 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
"Collect the result, running in S8 and paste (by hand) in this page" | tag sample point tab string | tab := String with: 9 asCharacter. 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',tab,'world ',(String with: 8 asCharacter with: 200 asCharacter) value: sample). sample at: 4 put: String. sample at: 5 put: tag,tag,tag. string := (Stringifier to: #S8) @ sample. "string outputToFile: 'sample.object.json'." self print: string printString. string