mirror of
https://github.com/cupcakearmy/occulto.git
synced 2024-12-22 05:36:28 +00:00
add tests for binary
This commit is contained in:
parent
211d5f7629
commit
8397b7fc26
@ -1,7 +1,18 @@
|
|||||||
import { Base64, Bytes, Hex } from '../dist/index.js'
|
import { Base64, Bytes, Hex } from '../dist/index.js'
|
||||||
|
import { compareArrayLike } from './utils.js'
|
||||||
import { Precomputed } from './values.js'
|
import { Precomputed } from './values.js'
|
||||||
|
|
||||||
describe('Encoding', () => {
|
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', () => {
|
describe('Hex', () => {
|
||||||
for (const [input, output] of Object.entries(Precomputed.Encoding.Hex)) {
|
for (const [input, output] of Object.entries(Precomputed.Encoding.Hex)) {
|
||||||
const buffer = Bytes.encode(input)
|
const buffer = Bytes.encode(input)
|
||||||
|
@ -6,3 +6,10 @@ export class Promises {
|
|||||||
} catch {}
|
} 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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,6 +10,10 @@ export const Precomputed = {
|
|||||||
occulto: '6f6363756c746f',
|
occulto: '6f6363756c746f',
|
||||||
'hello world': '68656c6c6f20776f726c64',
|
'hello world': '68656c6c6f20776f726c64',
|
||||||
},
|
},
|
||||||
|
Bytes: {
|
||||||
|
test: [0x74, 0x65, 0x73, 0x74],
|
||||||
|
occulto: [0x6f, 0x63, 0x63, 0x75, 0x6c, 0x74, 0x6f],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Hash: {
|
Hash: {
|
||||||
SHA_1: {
|
SHA_1: {
|
||||||
|
Loading…
Reference in New Issue
Block a user