From 8397b7fc26a591047e3b2e8f02fee3aa9eeceeb3 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Tue, 18 Oct 2022 17:27:14 +0200 Subject: [PATCH] add tests for binary --- test/encoding.spec.js | 11 +++++++++++ test/utils.js | 7 +++++++ test/values.js | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/test/encoding.spec.js b/test/encoding.spec.js index 07a5649..1df382c 100644 --- a/test/encoding.spec.js +++ b/test/encoding.spec.js @@ -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) diff --git a/test/utils.js b/test/utils.js index 4729863..bdbbdcf 100644 --- a/test/utils.js +++ b/test/utils.js @@ -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]) + } +} diff --git a/test/values.js b/test/values.js index 12e81bb..6908834 100644 --- a/test/values.js +++ b/test/values.js @@ -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: {