@@ -16,13 +16,34 @@ test('encoding-length', function (t) {
1616 } )
1717
1818 t . test ( 'returns correct length for empty dictionaries' , function ( t ) {
19- t . plan ( 1 )
20- t . equal ( bencode . encodingLength ( { } ) , 2 )
19+ t . plan ( 2 )
20+ t . equal ( bencode . encodingLength ( { } ) , 2 ) // de
21+ t . equal ( bencode . encodingLength ( new Map ( ) ) , 2 ) // de
22+ } )
23+
24+ t . test ( 'returns correct length for dictionaries' , function ( t ) {
25+ t . plan ( 2 )
26+ var obj = { a : 1 , b : 'str' , c : { de : 'f' } }
27+ var map = new Map ( [
28+ [ 'a' , 1 ] ,
29+ [ 'b' , 'str' ] ,
30+ [ 'c' , { de : 'f' } ]
31+ ] )
32+ t . equal ( bencode . encodingLength ( obj ) , 28 ) // d1:ai1e1:b3:str1:cd2:de1:fee
33+ t . equal ( bencode . encodingLength ( map ) , 28 ) // d1:ai1e1:b3:str1:cd2:de1:fee
2134 } )
2235
2336 t . test ( 'returns correct length for empty lists' , function ( t ) {
24- t . plan ( 1 )
25- t . equal ( bencode . encodingLength ( { } ) , 2 )
37+ t . plan ( 2 )
38+ t . equal ( bencode . encodingLength ( [ ] ) , 2 ) // le
39+ t . equal ( bencode . encodingLength ( new Set ( ) ) , 2 ) // le
40+ } )
41+
42+ t . test ( 'returns correct length for lists' , function ( t ) {
43+ t . plan ( 3 )
44+ t . equal ( bencode . encodingLength ( [ 1 , 2 , 3 ] ) , 11 ) // li1ei2ei3ee
45+ t . equal ( bencode . encodingLength ( [ 1 , 'string' , [ { a : 1 , b : 2 } ] ] ) , 29 ) // li1e6:stringld1:ai1e1:bi2eeee
46+ t . equal ( bencode . encodingLength ( new Set ( [ 1 , 'string' , [ { a : 1 , b : 2 } ] ] ) ) , 29 ) // li1e6:stringld1:ai1e1:bi2eeee
2647 } )
2748
2849 t . test ( 'returns correct length for integers' , function ( t ) {
0 commit comments