[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
test[S8ObjC] extend
SwikiCodeRobot @> #testS8ObjCExtend |
"Subclass NSObject creating a new class named NRTest"
| pool cls counter instance |
counter := 0.
pool := (ObjCClass classNamed: #NSAutoreleasePool in: #Foundation) newInstanceHandle.
cls := (ObjCClass classNamed: #NSObject) extend: #NRTest.
cls addMethod: #description type: '@@:'
function: [:me :cmd|
counter := counter + 1.
cmd = #description ifFalse: [ self error: 'Wrong command ',cmd ].
S8ObjC value: #test
].
cls addMethod: #instanceOnly type: '@@:'
function: [:me :cmd|
cmd = #instanceOnly ifFalse: [ self error: 'Wrong command ',cmd ].
S8ObjC value: #test2
].
cls addIvar: #name type: '@'.
(ObjCClass classNamed: #NRTest) notNil ifTrue: [
self error: 'NRTest class exists'
].
cls register.
instance := cls instance "alloc+init".
"ToDo-
// call [instance description] in a variety of ways (via toString())
var str = 'test', str2 = 'test2', success = false;
assert.equal($.NRTest('respondsToSelector','instanceOnly'), false);
assert.equal(str2, instance('instanceOnly'))
assert.equal(str, instance('description')+'')
assert.equal(str, instance.toString())
assert.equal(str, ''+instance)
assert.equal(str, instance+'')
assert.equal(counter, 4)
assert.equal($.NRTest, instance('class'))
"