1010
1111"use strict" ;
1212
13- /**
14- * Module dependencies.
15- */
16-
17- var should = require ( 'should' ) ;
13+ var assert = require ( 'assert' ) ;
1814var hessian = require ( '../' ) ;
1915var utils = require ( './utils' ) ;
2016
@@ -24,89 +20,94 @@ describe('binary.test.js', function () {
2420 } ) ;
2521
2622 it ( 'should write "foo"' , function ( ) {
27- hessian . encode ( new Buffer ( 'foo' ) ) . should . eql (
28- Buffer . concat ( [ new Buffer ( [ 'B' . charCodeAt ( 0 ) , 0x00 , 0x03 ] ) , new Buffer ( 'foo' ) ] ) ) ;
23+ assert . deepEqual (
24+ hessian . encode ( new Buffer ( 'foo' ) ) ,
25+ Buffer . concat ( [ new Buffer ( [ 'B' . charCodeAt ( 0 ) , 0x00 , 0x03 ] ) , new Buffer ( 'foo' ) ] )
26+ ) ;
2927 } ) ;
3028
3129 it ( 'should read and write empty binary' , function ( ) {
3230 var empty = hessian . decode ( new Buffer ( [ 'B' . charCodeAt ( 0 ) , 0x00 , 0x00 ] ) ) ;
33- empty . should . be . a . Buffer ;
34- empty . should . length ( 0 ) ;
31+ assert ( Buffer . isBuffer ( empty ) ) ;
32+ assert ( empty . length === 0 ) ;
3533
36- hessian . encode ( new Buffer ( '' ) ) . should . eql ( new Buffer ( [ 'B' . charCodeAt ( 0 ) , 0x00 , 0x00 ] ) ) ;
34+ assert . deepEqual (
35+ hessian . encode ( new Buffer ( '' ) ) ,
36+ new Buffer ( [ 'B' . charCodeAt ( 0 ) , 0x00 , 0x00 ] )
37+ ) ;
3738 } ) ;
3839
3940 it ( 'should write and read as java impl' , function ( ) {
4041 var bytes = new Buffer ( 65535 ) ;
4142 bytes . fill ( 0x41 ) ;
4243 var buf = hessian . encode ( bytes , '1.0' ) ;
43- buf . should . length ( utils . bytes ( 'v1/bytes/65535' ) . length ) ;
44- buf . should . eql ( utils . bytes ( 'v1/bytes/65535' ) ) ;
45- hessian . decode ( utils . bytes ( 'v1/bytes/65535' ) , '1.0' ) . should . eql ( bytes ) ;
44+ assert ( buf . length === utils . bytes ( 'v1/bytes/65535' ) . length ) ;
45+ assert . deepEqual ( buf , utils . bytes ( 'v1/bytes/65535' ) ) ;
46+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v1/bytes/65535' ) , '1.0' ) , bytes ) ;
4647
4748 var bytes = new Buffer ( 32768 ) ;
4849 bytes . fill ( 0x41 ) ;
4950 var buf = hessian . encode ( bytes , '1.0' ) ;
50- buf . should . length ( utils . bytes ( 'v1/bytes/32768' ) . length ) ;
51- buf . should . eql ( utils . bytes ( 'v1/bytes/32768' ) ) ;
52- hessian . decode ( utils . bytes ( 'v1/bytes/32768' ) , '1.0' ) . should . eql ( bytes ) ;
51+ assert ( buf . length === utils . bytes ( 'v1/bytes/32768' ) . length ) ;
52+ assert . deepEqual ( buf , utils . bytes ( 'v1/bytes/32768' ) ) ;
53+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v1/bytes/32768' ) , '1.0' ) , bytes ) ;
5354
5455 var bytes = new Buffer ( 32769 ) ;
5556 bytes . fill ( 0x41 ) ;
5657 var buf = hessian . encode ( bytes , '1.0' ) ;
57- buf . should . length ( utils . bytes ( 'v1/bytes/32769' ) . length ) ;
58- buf . should . eql ( utils . bytes ( 'v1/bytes/32769' ) ) ;
59- hessian . decode ( utils . bytes ( 'v1/bytes/32769' ) , '1.0' ) . should . eql ( bytes ) ;
58+ assert ( buf . length === utils . bytes ( 'v1/bytes/32769' ) . length ) ;
59+ assert . deepEqual ( buf , utils . bytes ( 'v1/bytes/32769' ) ) ;
60+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v1/bytes/32769' ) , '1.0' ) , bytes ) ;
6061
6162 var bytes = new Buffer ( 32767 ) ;
6263 bytes . fill ( 0x41 ) ;
6364 var buf = hessian . encode ( bytes , '1.0' ) ;
64- buf . should . length ( utils . bytes ( 'v1/bytes/32767' ) . length ) ;
65- buf . should . eql ( utils . bytes ( 'v1/bytes/32767' ) ) ;
66- hessian . decode ( utils . bytes ( 'v1/bytes/32767' ) , '1.0' ) . should . eql ( bytes ) ;
65+ assert ( buf . length === utils . bytes ( 'v1/bytes/32767' ) . length ) ;
66+ assert . deepEqual ( buf , utils . bytes ( 'v1/bytes/32767' ) ) ;
67+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v1/bytes/32767' ) , '1.0' ) , bytes ) ;
6768
6869 var bytes = new Buffer ( 32769 ) ;
6970 bytes . fill ( 0x41 ) ;
7071 var buf = hessian . encode ( bytes , '1.0' ) ;
71- buf . should . length ( utils . bytes ( 'v1/bytes/32769' ) . length ) ;
72- buf . should . eql ( utils . bytes ( 'v1/bytes/32769' ) ) ;
73- hessian . decode ( utils . bytes ( 'v1/bytes/32769' ) , '1.0' ) . should . eql ( bytes ) ;
72+ assert ( buf . length === utils . bytes ( 'v1/bytes/32769' ) . length ) ;
73+ assert . deepEqual ( buf , utils . bytes ( 'v1/bytes/32769' ) ) ;
74+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v1/bytes/32769' ) , '1.0' ) , bytes ) ;
7475
7576 var bytes = new Buffer ( 42769 ) ;
7677 bytes . fill ( 0x41 ) ;
7778 var buf = hessian . encode ( bytes , '1.0' ) ;
78- buf . should . length ( utils . bytes ( 'v1/bytes/42769' ) . length ) ;
79- buf . should . eql ( utils . bytes ( 'v1/bytes/42769' ) ) ;
80- hessian . decode ( utils . bytes ( 'v1/bytes/42769' ) , '1.0' ) . should . eql ( bytes ) ;
79+ assert ( buf . length === utils . bytes ( 'v1/bytes/42769' ) . length ) ;
80+ assert . deepEqual ( buf , utils . bytes ( 'v1/bytes/42769' ) ) ;
81+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v1/bytes/42769' ) , '1.0' ) , bytes ) ;
8182
8283 var bytes = new Buffer ( 82769 ) ;
8384 bytes . fill ( 0x41 ) ;
8485 var buf = hessian . encode ( bytes , '1.0' ) ;
85- buf . should . length ( utils . bytes ( 'v1/bytes/82769' ) . length ) ;
86- buf . should . eql ( utils . bytes ( 'v1/bytes/82769' ) ) ;
87- hessian . decode ( utils . bytes ( 'v1/bytes/82769' ) , '1.0' ) . should . eql ( bytes ) ;
86+ assert ( buf . length === utils . bytes ( 'v1/bytes/82769' ) . length ) ;
87+ assert . deepEqual ( buf , utils . bytes ( 'v1/bytes/82769' ) ) ;
88+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v1/bytes/82769' ) , '1.0' ) , bytes ) ;
8889 } ) ;
8990
9091 describe ( 'v2.0' , function ( ) {
9192 it ( 'should read zero length binary data' , function ( ) {
9293 var buf = hessian . decode ( new Buffer ( [ 0x20 ] ) , '2.0' ) ;
93- buf . should . length ( 0 ) ;
94- buf . should . eql ( new Buffer ( 0 ) ) ;
94+ assert ( buf . length === 0 ) ;
95+ assert . deepEqual ( buf , new Buffer ( 0 ) ) ;
9596 } ) ;
9697
9798 it ( 'should read short datas' , function ( ) {
9899 var decoder = new hessian . DecoderV2 ( new Buffer ( [ 0x20 , 0x23 , 0x23 , 0x02 , 0x03 , 0x20 ] ) ) ;
99100 var buf = decoder . read ( ) ;
100- buf . should . length ( 0 ) ;
101- buf . should . eql ( new Buffer ( 0 ) ) ;
101+ assert ( buf . length === 0 ) ;
102+ assert . deepEqual ( buf , new Buffer ( 0 ) ) ;
102103
103104 buf = decoder . read ( ) ;
104- buf . should . length ( 3 ) ;
105- buf . should . eql ( new Buffer ( [ 0x23 , 2 , 3 ] ) ) ;
105+ assert ( buf . length === 3 ) ;
106+ assert . deepEqual ( buf , new Buffer ( [ 0x23 , 2 , 3 ] ) ) ;
106107
107108 buf = decoder . read ( ) ;
108- buf . should . length ( 0 ) ;
109- buf . should . eql ( new Buffer ( 0 ) ) ;
109+ assert ( buf . length === 0 ) ;
110+ assert . deepEqual ( buf , new Buffer ( 0 ) ) ;
110111 decoder . clean ( ) ;
111112 } ) ;
112113
@@ -115,25 +116,25 @@ describe('binary.test.js', function () {
115116 input . fill ( 0x2f ) ;
116117 input [ 0 ] = 0x2f ;
117118 var buf = hessian . decode ( input , '2.0' ) ;
118- buf . should . length ( 15 ) ;
119+ assert ( buf . length === 15 ) ;
119120 var output = new Buffer ( 15 ) ;
120121 output . fill ( 0x2f ) ;
121- buf . should . eql ( output ) ;
122+ assert . deepEqual ( buf , output ) ;
122123
123124 var buf15 = new Buffer ( 15 ) ;
124125 buf15 . fill ( 0x41 ) ;
125- hessian . encode ( buf15 , '2.0' ) . should . eql ( utils . bytes ( 'v2/bytes/15' ) ) ;
126- hessian . decode ( utils . bytes ( 'v2/bytes/15' ) , '2.0' ) . should . eql ( buf15 ) ;
126+ assert . deepEqual ( hessian . encode ( buf15 , '2.0' ) , utils . bytes ( 'v2/bytes/15' ) ) ;
127+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v2/bytes/15' ) , '2.0' ) , buf15 ) ;
127128
128129 var buf16 = new Buffer ( 16 ) ;
129130 buf16 . fill ( 0x41 ) ;
130- hessian . encode ( buf16 , '2.0' ) . should . eql ( utils . bytes ( 'v2/bytes/16' ) ) ;
131- hessian . decode ( utils . bytes ( 'v2/bytes/16' ) , '2.0' ) . should . eql ( buf16 ) ;
131+ assert . deepEqual ( hessian . encode ( buf16 , '2.0' ) , utils . bytes ( 'v2/bytes/16' ) ) ;
132+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v2/bytes/16' ) , '2.0' ) , buf16 ) ;
132133 } ) ;
133134
134135 it ( 'should read long binary' , function ( ) {
135136 var buf = hessian . encode ( new Buffer ( 65535 ) , '2.0' ) ;
136- buf [ 0 ] . should . equal ( 0x41 ) ;
137+ assert ( buf [ 0 ] === 0x41 ) ;
137138 hessian . decode ( buf , '2.0' ) ;
138139
139140 buf = hessian . encode ( new Buffer ( 65536 ) , '2.0' ) ;
@@ -144,92 +145,58 @@ describe('binary.test.js', function () {
144145 } ) ;
145146
146147 it ( 'should write short binary' , function ( ) {
147- hessian . encode ( new Buffer ( '' ) , '2.0' ) . should . eql ( new Buffer ( [ 0x20 ] ) ) ;
148+ assert . deepEqual ( hessian . encode ( new Buffer ( '' ) , '2.0' ) , new Buffer ( [ 0x20 ] ) ) ;
148149 } ) ;
149150
150151 it ( 'should write and read as java impl' , function ( ) {
151152 var bytes = new Buffer ( 65535 ) ;
152153 bytes . fill ( 0x41 ) ;
153154 var buf = hessian . encode ( bytes , '2.0' ) ;
154- buf . should . length ( utils . bytes ( 'v2/bytes/65535' ) . length ) ;
155- buf . should . eql ( utils . bytes ( 'v2/bytes/65535' ) ) ;
156- hessian . decode ( utils . bytes ( 'v2/bytes/65535' ) , '2.0' ) . should . eql ( bytes ) ;
155+ assert ( buf . length === utils . bytes ( 'v2/bytes/65535' ) . length ) ;
156+ assert . deepEqual ( buf , utils . bytes ( 'v2/bytes/65535' ) ) ;
157+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v2/bytes/65535' ) , '2.0' ) , bytes ) ;
157158
158159 var bytes = new Buffer ( 32768 ) ;
159160 bytes . fill ( 0x41 ) ;
160161 var buf = hessian . encode ( bytes , '2.0' ) ;
161- buf . should . length ( utils . bytes ( 'v2/bytes/32768' ) . length ) ;
162- buf . should . eql ( utils . bytes ( 'v2/bytes/32768' ) ) ;
163- hessian . decode ( utils . bytes ( 'v2/bytes/32768' ) , '2.0' ) . should . eql ( bytes ) ;
162+ assert ( buf . length === utils . bytes ( 'v2/bytes/32768' ) . length ) ;
163+ assert . deepEqual ( buf , utils . bytes ( 'v2/bytes/32768' ) ) ;
164+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v2/bytes/32768' ) , '2.0' ) , bytes ) ;
164165
165166 var bytes = new Buffer ( 32769 ) ;
166167 bytes . fill ( 0x41 ) ;
167168 var buf = hessian . encode ( bytes , '2.0' ) ;
168- buf . should . length ( utils . bytes ( 'v2/bytes/32769' ) . length ) ;
169- buf . should . eql ( utils . bytes ( 'v2/bytes/32769' ) ) ;
170- hessian . decode ( utils . bytes ( 'v2/bytes/32769' ) , '2.0' ) . should . eql ( bytes ) ;
169+ assert ( buf . length === utils . bytes ( 'v2/bytes/32769' ) . length ) ;
170+ assert . deepEqual ( buf , utils . bytes ( 'v2/bytes/32769' ) ) ;
171+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v2/bytes/32769' ) , '2.0' ) , bytes ) ;
171172
172173 var bytes = new Buffer ( 32767 ) ;
173174 bytes . fill ( 0x41 ) ;
174175 var buf = hessian . encode ( bytes , '2.0' ) ;
175- buf . should . length ( utils . bytes ( 'v2/bytes/32767' ) . length ) ;
176- buf . should . eql ( utils . bytes ( 'v2/bytes/32767' ) ) ;
177- hessian . decode ( utils . bytes ( 'v2/bytes/32767' ) , '2.0' ) . should . eql ( bytes ) ;
176+ assert ( buf . length === utils . bytes ( 'v2/bytes/32767' ) . length ) ;
177+ assert . deepEqual ( buf , utils . bytes ( 'v2/bytes/32767' ) ) ;
178+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v2/bytes/32767' ) , '2.0' ) , bytes ) ;
178179
179180 var bytes = new Buffer ( 32769 ) ;
180181 bytes . fill ( 0x41 ) ;
181182 var buf = hessian . encode ( bytes , '2.0' ) ;
182- buf . should . length ( utils . bytes ( 'v2/bytes/32769' ) . length ) ;
183- buf . should . eql ( utils . bytes ( 'v2/bytes/32769' ) ) ;
184- hessian . decode ( utils . bytes ( 'v2/bytes/32769' ) , '2.0' ) . should . eql ( bytes ) ;
183+ assert ( buf . length === utils . bytes ( 'v2/bytes/32769' ) . length ) ;
184+ assert . deepEqual ( buf , utils . bytes ( 'v2/bytes/32769' ) ) ;
185+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v2/bytes/32769' ) , '2.0' ) , bytes ) ;
185186
186187 var bytes = new Buffer ( 42769 ) ;
187188 bytes . fill ( 0x41 ) ;
188189 var buf = hessian . encode ( bytes , '2.0' ) ;
189- buf . should . length ( utils . bytes ( 'v2/bytes/42769' ) . length ) ;
190- buf . should . eql ( utils . bytes ( 'v2/bytes/42769' ) ) ;
191- hessian . decode ( utils . bytes ( 'v2/bytes/42769' ) , '2.0' ) . should . eql ( bytes ) ;
190+ assert ( buf . length === utils . bytes ( 'v2/bytes/42769' ) . length ) ;
191+ assert . deepEqual ( buf , utils . bytes ( 'v2/bytes/42769' ) ) ;
192+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v2/bytes/42769' ) , '2.0' ) , bytes ) ;
192193
193194 var bytes = new Buffer ( 82769 ) ;
194195 bytes . fill ( 0x41 ) ;
195196 var buf = hessian . encode ( bytes , '2.0' ) ;
196- buf . should . length ( utils . bytes ( 'v2/bytes/82769' ) . length ) ;
197- buf . should . eql ( utils . bytes ( 'v2/bytes/82769' ) ) ;
198- hessian . decode ( utils . bytes ( 'v2/bytes/82769' ) , '2.0' ) . should . eql ( bytes ) ;
197+ assert ( buf . length === utils . bytes ( 'v2/bytes/82769' ) . length ) ;
198+ assert . deepEqual ( buf , utils . bytes ( 'v2/bytes/82769' ) ) ;
199+ assert . deepEqual ( hessian . decode ( utils . bytes ( 'v2/bytes/82769' ) , '2.0' ) , bytes ) ;
199200 } ) ;
200-
201- // it('should read java hessian 1.0 bin format', function () {
202- // var bytes = new Buffer(65535);
203- // bytes.fill(0x41);
204- // hessian.decode(utils.bytes('v1/bytes/65535'), '2.0').should.eql(bytes);
205-
206- // var bytes = new Buffer(32767);
207- // bytes.fill(0x41);
208- // hessian.decode(utils.bytes('v1/bytes/32767'), '2.0').should.eql(bytes);
209-
210- // var bytes = new Buffer(32768);
211- // bytes.fill(0x41);
212- // hessian.decode(utils.bytes('v1/bytes/32768'), '2.0').should.eql(bytes);
213-
214- // var bytes = new Buffer(32769);
215- // bytes.fill(0x41);
216- // hessian.decode(utils.bytes('v1/bytes/32769'), '2.0').should.eql(bytes);
217-
218- // var bytes = new Buffer(32767);
219- // bytes.fill(0x41);
220- // hessian.decode(utils.bytes('v1/bytes/32767'), '2.0').should.eql(bytes);
221-
222- // var bytes = new Buffer(32769);
223- // bytes.fill(0x41);
224- // hessian.decode(utils.bytes('v1/bytes/32769'), '2.0').should.eql(bytes);
225-
226- // var bytes = new Buffer(42769);
227- // bytes.fill(0x41);
228- // hessian.decode(utils.bytes('v1/bytes/42769'), '2.0').should.eql(bytes);
229-
230- // var bytes = new Buffer(82769);
231- // bytes.fill(0x41);
232- // hessian.decode(utils.bytes('v1/bytes/82769'), '2.0').should.eql(bytes);
233- // });
234201 } ) ;
235202} ) ;
0 commit comments