var $ = require('../')
  , assert = require('assert')

$.import('Foundation')
$.NSAutoreleasePool('alloc')('init')

// Subclass 'NSObject', creating a new class named 'NRTest'
var NRTest = $.NSObject.extend('NRTest')
  , counter = 0

// Add a new method to the NRTest class responding to the "description" selector
NRTest.addMethod('description', '@@:', function (id, sel) {
  counter++
  return $.NSString('stringWithUTF8String', 'test')
})

// Finalize the class so the we can make instances of it
NRTest.register()

// Create an instance
var instance = NRTest('alloc')('init')

// call [instance description]
console.log(instance('description')+'')
console.log(instance.toString())
console.log(String(instance))
//console.log(''+instance) // Either of these
//console.log(instance+'') // segfault, WTF?

assert.equal(counter, 3)

@@ -361,15 +361,18 @@
 on (
-id, sel
+self, _cmd
 ) %7B%0A
@@ -383,16 +383,36 @@
 unter++%0A
+  console.log(_cmd)%0A
   return
@@ -627,16 +627,54 @@
 ription%5D
+ in a variety of ways (via toString())
 %0Aconsole
@@ -769,18 +769,16 @@
 tance))%0A
-//
 console.
@@ -797,30 +797,9 @@
 nce)
- // Either of these%0A//
+%0A
 cons
@@ -822,26 +822,8 @@
 +'')
- // segfault, WTF?
 %0A%0Aas
@@ -846,7 +846,7 @@
 er, 
-3
+5
 )%0A

Change up tests/extend.js. No segfault on node 0.5.4.