1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 02:09:22 +02:00
Oinktube/node_modules/level-codec/test/kv.js
2022-07-15 11:08:01 -03:00

109 lines
2.3 KiB
JavaScript

var test = require('tape')
var Codec = require('..')
test('encode key', function (t) {
var codec = new Codec({ keyEncoding: 'hex' })
var buf = codec.encodeKey('686579', {})
t.equal(buf.toString(), 'hey')
buf = codec.encodeKey('686579')
t.equal(buf.toString(), 'hey')
buf = codec.encodeKey('686579', {
keyEncoding: 'binary'
})
t.equal(buf.toString(), '686579')
buf = codec.encodeKey({ foo: 'bar' }, {
keyEncoding: 'none'
})
t.deepEqual(buf, { foo: 'bar' })
t.end()
})
test('encode value', function (t) {
var codec = new Codec({ valueEncoding: 'hex' })
var buf = codec.encodeValue('686579', {})
t.equal(buf.toString(), 'hey')
buf = codec.encodeValue('686579')
t.equal(buf.toString(), 'hey')
buf = codec.encodeValue('686579', {
valueEncoding: 'binary'
})
t.equal(buf.toString(), '686579')
t.end()
})
test('decode key', function (t) {
var codec = new Codec({ keyEncoding: 'hex' })
var buf = codec.decodeKey(Buffer.from('hey'), {})
t.equal(buf, '686579')
buf = codec.decodeKey(Buffer.from('hey'))
t.equal(buf, '686579')
buf = codec.decodeKey(Buffer.from('hey'), {
keyEncoding: 'binary'
})
t.equal(buf.toString(), 'hey')
t.end()
})
test('decode value', function (t) {
var codec = new Codec({ valueEncoding: 'hex' })
var buf = codec.decodeValue(Buffer.from('hey'), {})
t.equal(buf, '686579')
buf = codec.decodeValue(Buffer.from('hey'))
t.equal(buf, '686579')
buf = codec.decodeValue(Buffer.from('hey'), {
valueEncoding: 'binary'
})
t.equal(buf.toString(), 'hey')
t.end()
})
test('encode value - legacy', function (t) {
var codec = new Codec({ encoding: 'hex' })
var buf = codec.encodeValue('686579', {})
t.equal(buf.toString(), 'hey')
buf = codec.encodeValue('686579')
t.equal(buf.toString(), 'hey')
buf = codec.encodeValue('686579', {
encoding: 'binary'
})
t.equal(buf.toString(), '686579')
t.end()
})
test('decode value - legacy', function (t) {
var codec = new Codec({ encoding: 'hex' })
var buf = codec.decodeValue(Buffer.from('hey'), {})
t.equal(buf, '686579')
buf = codec.decodeValue(Buffer.from('hey'))
t.equal(buf, '686579')
buf = codec.decodeValue(Buffer.from('hey'), {
encoding: 'binary'
})
t.equal(buf.toString(), 'hey')
t.end()
})