add tests for binary

This commit is contained in:
cupcakearmy 2022-10-18 17:27:14 +02:00
parent 211d5f7629
commit 8397b7fc26
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F
3 changed files with 22 additions and 0 deletions

View File

@ -1,7 +1,18 @@
import { Base64, Bytes, Hex } from '../dist/index.js'
import { compareArrayLike } from './utils.js'
import { Precomputed } from './values.js'
describe('Encoding', () => {
describe('Bytes', () => {
for (const [input, output] of Object.entries(Precomputed.Encoding.Bytes)) {
it(`Should encode ${input} to ${output}`, async () => {
compareArrayLike(Bytes.encode(input), output)
})
it(`Should decode ${output} to ${input}`, async () => {
compareArrayLike(await Bytes.decode(output), input)
})
}
})
describe('Hex', () => {
for (const [input, output] of Object.entries(Precomputed.Encoding.Hex)) {
const buffer = Bytes.encode(input)

View File

@ -6,3 +6,10 @@ export class Promises {
} catch {}
}
}
export function compareArrayLike(a, b) {
chai.expect(a.length).to.equal(b.length)
for (let i = 0; i < a.length; i++) {
chai.expect(a[i]).to.equal(b[i])
}
}

View File

@ -10,6 +10,10 @@ export const Precomputed = {
occulto: '6f6363756c746f',
'hello world': '68656c6c6f20776f726c64',
},
Bytes: {
test: [0x74, 0x65, 0x73, 0x74],
occulto: [0x6f, 0x63, 0x63, 0x75, 0x6c, 0x74, 0x6f],
},
},
Hash: {
SHA_1: {