occulto/test/encoding.spec.js

39 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-10-18 14:59:33 +00:00
import { Base64, Bytes, Hex } from '../dist/index.js'
2022-10-18 15:27:14 +00:00
import { compareArrayLike } from './utils.js'
import { Precomputed } from './values.js'
describe('Encoding', () => {
2022-10-18 15:27:14 +00:00
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)
})
}
})
2022-10-18 14:59:33 +00:00
describe('Hex', () => {
for (const [input, output] of Object.entries(Precomputed.Encoding.Hex)) {
const buffer = Bytes.encode(input)
it(`Should encode ${input} to ${output}`, async () => {
chai.expect(await Hex.encode(buffer)).to.equal(output)
})
it(`Should decode ${output} to ${input}`, async () => {
chai.expect(await Hex.decode(output)).to.deep.equal(buffer)
})
}
})
describe('Base64', () => {
for (const [input, output] of Object.entries(Precomputed.Encoding.Base64)) {
const buffer = Bytes.encode(input)
it(`Should encode ${input} to ${output}`, async () => {
chai.expect(await Base64.encode(buffer)).to.equal(output)
})
it(`Should decode ${output} to ${input}`, async () => {
chai.expect(await Base64.decode(output)).to.deep.equal(buffer)
})
}
})
})