-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathdecode.length.test.js
More file actions
24 lines (23 loc) · 787 Bytes
/
decode.length.test.js
File metadata and controls
24 lines (23 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import test from 'tape'
import bencode from '../index.js'
test('bencode#decode#bytes', function (t) {
t.test('bytes should be set to correct value for two separate bencoded elements', function (t) {
t.plan(2)
t.equal(bencode.decode('i123ei123e'), 123)
t.equal(bencode.decode.bytes, 5)
})
t.test('bytes should be set to correct value when followed by random junk data', function (t) {
t.plan(1)
const someData = {
string: 'Hello World',
integer: 12345,
dict: {
key: 'This is a string within a dictionary'
},
list: [1, 2, 3, 4, 'string', 5, {}]
}
const result = bencode.encode(someData)
bencode.decode(Buffer.from(result).toString() + 'RANDOM_JUNK_DATA')
t.equal(bencode.decode.bytes, result.length)
})
})