Skip to content

Commit 67c9dae

Browse files
committed
test: Add test for Map dictionary encoding
1 parent 97df33b commit 67c9dae

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

test/encode.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ test('bencode#encode()', function (t) {
3131
t.equal(bencode.encode(data).toString(), 'd2:1211:Hello World2:34i12345ee')
3232
})
3333

34+
t.test('should encode a Map as dictionary', function (t) {
35+
t.plan(1)
36+
var data = new Map([
37+
[ 12, 'Hello World' ],
38+
[ '34', 12345 ],
39+
[ Buffer.from('buffer key'), Buffer.from('buffer value') ]
40+
])
41+
t.equal(bencode.encode(data).toString(), 'd2:1211:Hello World2:34i12345e10:buffer key12:buffer valuee')
42+
})
43+
3444
t.test('should be able to encode a positive integer', function (t) {
3545
t.plan(1)
3646
t.equal(bencode.encode(123).toString(), 'i123e')

0 commit comments

Comments
 (0)