Skip to content

Commit

Permalink
Add test for ByteData accepting Uint8ClampedArray
Browse files Browse the repository at this point in the history
  • Loading branch information
RenovatingDev committed Jan 31, 2022
1 parent 975eecd commit 702296a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/unit/core/byte-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const BitBuffer = require('core/bit-buffer')
const ByteData = require('core/byte-data')
const Mode = require('core/mode')

test('Byte Data', function (t) {
test('Byte Data: String Input', function (t) {
const text = '1234'
const textBitLength = 32
const textByte = [49, 50, 51, 52] // 1, 2, 3, 4
Expand All @@ -24,3 +24,17 @@ test('Byte Data', function (t) {

t.end()
})

test('Byte Data: Byte Input', function (t) {
const bytes = new Uint8ClampedArray([1, 231, 32, 22])

const byteData = new ByteData(bytes)
t.equal(byteData.getLength(), bytes.length, 'Should return correct length')
t.equal(byteData.getBitsLength(), bytes.length * 8, 'Should return correct bit length')

const bitBuffer = new BitBuffer()
byteData.write(bitBuffer)
t.deepEqual(bitBuffer.buffer, bytes, 'Should write correct data to buffer')

t.end()
})

0 comments on commit 702296a

Please sign in to comment.