[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
test[sharing] VSE-S8 02 circular
Test for objects with circular references.
"Testing object with circular references"
| sample object |
sample := '{"id":14,"origin":"VSE","contents":{"id":2,"contents":[{"id":4,"contents":[" 2",{"class":{"id":7,"global":"Point","allInstVarNames":["x","y"]},"1":700,"2":" 2","id":6},{"1":65,"id":8,"class":{"id":9,"global":"Character","allInstVarNames":["asciiInteger"]}},{"id":10,"contents":["isIndexedColor","basicSize","triggerEvent:with:","errorBadEvent:","isCursor","isDialogTopPane","addBehavior:","knownDefinition","perform:with:with:with:","isCharacter","when:do:","isPoint","isMDIClient","addEventHandlers:","objectShallowCopy","isButton","isBehavior","aboutToExitSession","isContext","osError:","osNotification","startingSession","evaluateWithArguments:","propertyAt:","class","doesNotUnderstand:","isMetaClass","instVarAt:","isComboBox","implementedBySubclass","notImplementedYet","at:","changed:","isByteArray","modifiedByOStyle","frameCanBeRescaled","isTimeStamp","osError","hasActionForEvent:","triggerEvent:withArguments:","perform:with:","asString","isDynamicLinkLibrary","~~","displayWith:","isString","ISSUE","isMessage","when:evaluate:","mustBeBoolean","isAssociation","primitiveFailed","isResidueOrNil","error:","perform:with:with:","isBitmap","changed","isExternalHandle","initialize","isDate","triggerEvent:with:with:","basicInspect","when:send:to:withArguments:","aboutToSaveImage","isCollection","hash:","isFraction","changed:with:","isCompiledMethod","isDialogWindow","isDictionary","when:send:to:with:with:","isDirectory","lastOsError","vmInterrupt:","isRadioButton","displayAt:","dependsOn:","osErrorMessage:","cantReturn","notifyWhenFinalizable:","isStream","isArray","printRecursionOn:","osWarning:","isMethodDictionary","osNotification:","halt","changed:with:with:","isFileStream","doesNotNeedFinalization","triggerEvent:","triggerEvent:withArguments:ifNotHandled:","isSubPane","actionListForEvent:","osWarning","hash","isBoolean","isMenu","osWorkaround","changedEventName","eventsHandled","methodFor:","allDependents","become:","shallowCopy","updateEvent:selector:arguments:","perform:withArguments:","isFloat","libraryName","copy","isTopPane","removeAllActionsWithReceiver:","basicAt:put:","isControlPane","isClass","when:send:to:","finalize:","basicAt:","isMDIChild","isMDIFrame","methodDictionaryArray:","isResidue","isPushButton","methodDictionaries","sender","update:with:","propertyTableForEdit","isIcon","methodNotAvailable","isNotebookPagePane","isInteger","methodDictionaryArray","eventTableCreate","removeDependent:","isExternalAddress","isTextPane","isKindOf:","isFile","smalltalkLibrary","actionForEvent:","evaluate","update:with:with:","revertToClassBehavior","addedByOStyle","update:","broadcast:with:","finalize","methodFor:in:","removeBehavior:","eventTable","allReferences","isBlockClosure","doNotNotifyWhenFinalizable:","objectEventTable:","removeActionsWithReceiver:forEvent:","isTextSelection","isTime","isGraphPane","perform:","platformDependent","printOn:","setActionList:forEvent:","dependents","errorBadSelector:","isColor","deepCopy","isGraphicsTool","isInLibrary","isStoredPicture","when:send:to:with:","isRectangle","canTriggerEvent:","isSymbol","==","isIndexedCollection","isFixedObject","isDoubleByteString","isFont","notFullyImplemented","basicHash:","propertyTable","isDIB","propertyAt:ifAbsentPut:","objectDeepCopy","release","isCompilationResult","smalltalkLibraryName","storeString","notNil","species","isInBase","objectProperties","displayAt:with:","finalizationRegistry","propertyAt:ifAbsent:","allReferencesPrim","inspect","isDropDownList","isSelfInitializingObject","smalltalkLibraryOrdinal","basicHash","removeBehavior:from:containedIn:","~=","at:put:","removeActionsForEvent:","removeAction:forEvent:","isMemberOf:","eventTableForEdit","isWindow","instVarAt:put:","yourself","isApplicationWindow","objectEventTable","obsoleteMethod","addDependent:","isNil","objectProperties:","respondsTo:","ASSERT:","broadcast:","isStatusPane","releaseEventTable","propertyAt:put:","invalidMessage","isLargeInteger","library","size","isGroupBox","statusPaneHelp:","isNumber","triggerEvent:ifNotHandled:","isSmallInteger","=","needsFinalization","hasFinalization","isDoubleByteSymbol","isRGBColor","isToolPane","libraryOrdinal","removeActionsSatisfying:forEvent:","storeOn:","printString"],"class":{"id":11,"global":"Set","allInstVarNames":["elementCount","contents"]}}],"class":{"id":5,"global":"OrderedCollection","allInstVarNames":["startPosition","endPosition","contents"]}}," 6",{"class":{"id":13,"global":"Association","allInstVarNames":["value","key"]},"1":" 2","2":"hello\r\nworld \/ crude\tworld \b\u00C8","id":12},{"id":14,"global":"String"}," ",600,700.7,"x",null," "," hello"],"class":{"id":3,"global":"Array"}}}' asObject.
sample isArray ifFalse: [ self error: 'Must be Array' ].
sample first first = sample ifFalse: [ self error: '1.1.- Must be sample' ].
sample first second x = 700 ifFalse: [ self error: '1.2.- Must be Point x 700' ].
sample first second y = sample ifFalse: [ self error: '1.2.- Must be Point y = sample' ].
sample first third = $A ifFalse: [ self error: '1.3.- Must be $A' ].
(sample first fourth isKindOf: Set) ifFalse: [ self error: '1.4.- Must be a Set' ].
(sample first fourth includes: #yourself) ifFalse: [ self error: '1.4.- #yourself must be present' ].
(sample second isKindOf: Point) ifFalse: [ self error: '2.- Must be aPoint' ].
sample second x = 700 ifFalse: [ self error: '2.1.- Must be Point x 700' ].
sample second y = sample ifFalse: [ self error: '2.2.- Must be Point y = sample' ].
(sample third isKindOf: Association) ifFalse: [ self error: '3.- Must be anAssociation' ].
(sample third key isKindOf: String) ifFalse: [ self error: '3.1.- key must be aString' ].
object := sample third.
(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: $/) = 14 ifFalse: [ self error: '3.1.3.- $/ must be at index 14' ].
object value = sample ifFalse: [ self error: '3.2.- Value must be sample' ].
sample fourth = 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' ].
self print: #Ok
Expression to dump source object
To be executed in VSE
"Do not need to run this code in S8"
self cancelFileIn!
| tag sample point tab string |
tab := String with: (Character value: 9).
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: (OrderedCollection 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.
"(File newFile: 'sample.object.json') nextPutAll: string; close."
string