2024-07-29 14:14:12 +00:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2022-10-18 14:59:33 +00:00
|
|
|
import { Base64, Bytes, Hex } from '../dist/index.js'
|
2022-10-18 13:53:43 +00:00
|
|
|
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 () => {
|
2024-07-29 14:14:12 +00:00
|
|
|
expect(Bytes.encode(input).buffer).toEqual(output.buffer)
|
2022-10-18 15:27:14 +00:00
|
|
|
})
|
|
|
|
it(`Should decode ${output} to ${input}`, async () => {
|
2024-07-29 14:14:12 +00:00
|
|
|
expect(Bytes.decode(output)).toEqual(input)
|
2022-10-18 15:27:14 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
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 () => {
|
2024-07-29 14:14:12 +00:00
|
|
|
expect(Hex.encode(buffer)).toEqual(output)
|
2022-10-18 14:59:33 +00:00
|
|
|
})
|
|
|
|
it(`Should decode ${output} to ${input}`, async () => {
|
2024-07-29 14:14:12 +00:00
|
|
|
expect(Hex.decode(output).buffer).toEqual(buffer.buffer)
|
2022-10-18 14:59:33 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2022-10-18 13:53:43 +00:00
|
|
|
describe('Base64', () => {
|
|
|
|
for (const [input, output] of Object.entries(Precomputed.Encoding.Base64)) {
|
|
|
|
const buffer = Bytes.encode(input)
|
|
|
|
it(`Should encode ${input} to ${output}`, async () => {
|
2024-07-29 14:14:12 +00:00
|
|
|
expect(await Base64.encode(buffer)).toEqual(output)
|
2022-10-18 13:53:43 +00:00
|
|
|
})
|
|
|
|
it(`Should decode ${output} to ${input}`, async () => {
|
2024-07-29 14:14:12 +00:00
|
|
|
expect((await Base64.decode(output)).buffer).toEqual(buffer.buffer)
|
2022-10-18 13:53:43 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|