@@ -192,17 +192,17 @@ exports.msgpack = {
192192 test . expect ( 4 ) ;
193193 // Object to test with
194194 var o = [ 1 , 2 , 3 ] ;
195-
195+
196196 // Create two buffers full of packed data, 'b' and 'bb', with the latter
197197 // containing 3 extra bytes
198198 var b = msgpack . pack ( o ) ;
199199 var bb = new Buffer ( b . length + 3 ) ;
200200 b . copy ( bb , 0 , 0 , b . length ) ;
201-
201+
202202 // Expect no remaining bytes when unpacking 'b'
203203 test . deepEqual ( msgpack . unpack ( b ) , o ) ;
204204 test . deepEqual ( msgpack . unpack . bytes_remaining , 0 ) ;
205-
205+
206206 // Expect 3 remaining bytes when unpacking 'bb'
207207 test . deepEqual ( msgpack . unpack ( bb ) , o ) ;
208208 test . equal ( msgpack . unpack . bytes_remaining , 3 ) ;
@@ -221,5 +221,27 @@ exports.msgpack = {
221221 test . ok ( false , e . message ) ;
222222 }
223223 test . done ( ) ;
224+ } ,
225+ 'test toJSON compatibility' : function ( test ) {
226+ var expect = { msg : 'hello world' } ;
227+ var subject = { toJSON : function ( ) { return expect ; } } ;
228+ test . expect ( 1 ) ;
229+ test . deepEqual ( expect , msgpack . unpack ( msgpack . pack ( subject ) ) ) ;
230+ test . done ( ) ;
231+ } ,
232+ 'test toJSON compatibility for multiple args' : function ( test ) {
233+ var expect = { msg : 'hello world' } ;
234+ var subject = { toJSON : function ( ) { return expect ; } } ;
235+ var subject1 = { toJSON : function ( ) { msg: 'goodbye world' } } ;
236+ test . expect ( 1 ) ;
237+ test . deepEqual ( expect , msgpack . unpack ( msgpack . pack ( subject , subject1 ) ) ) ;
238+ test . done ( ) ;
239+ } ,
240+ 'test toJSON compatibility with prototype' : function ( test ) {
241+ var expect = { msg : 'hello world' } ;
242+ var subject = { __proto__ : { toJSON : function ( ) { return expect ; } } } ;
243+ test . expect ( 1 ) ;
244+ test . deepEqual ( expect , msgpack . unpack ( msgpack . pack ( subject ) ) ) ;
245+ test . done ( ) ;
224246 }
225247} ;
0 commit comments