Skip to content

Commit

Permalink
chore: fix type errors in bitfield-rle tests (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn authored May 21, 2024
1 parent dfd7632 commit df66656
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/core-manager/bitfield-rle.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function encode(bitfield, buffer, offset) {
/**
* @param {Buffer} bitfield
*/
export function encodingLength(bitfield) {
function encodingLength(bitfield) {
var state = new State(bitfield, undefined, 0)
rle(state)
return state.outputOffset
Expand Down
44 changes: 12 additions & 32 deletions tests/bitfield-rle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ test('encodes and decodes', function () {
)
})

test('encodingLength', function () {
var bits = new Bitfield(1024)
var len = rle.encodingLength(bits.buffer)
assert(len < bits.buffer.length, 'is smaller')
var deflated = rle.encode(bits.buffer)
assert.deepEqual(
len,
deflated.length,
'encoding length is similar to encoded buffers length'
)
})

test('encodes and decodes with all bits set', function () {
var bits = new Bitfield(1024)

Expand Down Expand Up @@ -104,26 +92,18 @@ test('encodes empty bitfield', function () {
})

test('throws on bad input', function () {
assert.throws(
function () {
rle.decode(toUint32Array([100, 0, 0, 0]))
},
undefined,
'invalid delta count'
)
assert.throws(function () {
rle.decode(Buffer.from([100, 0, 0, 0]))
}, 'invalid delta count')
// t.exception.all also catches RangeErrors, which is what we expect from this
assert.throws(
function () {
rle.decode(
toUint32Array([
10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0,
10, 0,
])
)
},
undefined,
'missing delta'
)
assert.throws(function () {
rle.decode(
Buffer.from([
10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0,
10, 0,
])
)
}, 'missing delta')
})

test('not power of two', function () {
Expand All @@ -136,7 +116,7 @@ test('not power of two', function () {
)
})

/** @param {Bitfield | Buffer | Array<number>} b */
/** @param {Bitfield | Uint8Array | Array<number>} b */
function toUint32Array(b) {
if (Array.isArray(b)) {
b = Buffer.from(b)
Expand Down

0 comments on commit df66656

Please sign in to comment.