Additional tiny base64 decoder tests (#1252)

* Additional tiny base64 decoder tests

* Update packages/util-crypto/src/base64/encode.spec.ts

* Update packages/x-randomvalues/src/base64.spec.ts
This commit is contained in:
Jaco
2021-11-27 09:23:18 +02:00
committed by GitHub
parent 64fd66bd2a
commit 8a5b514944
+33 -39
View File
@@ -3,46 +3,40 @@
import { base64Decode } from './base64';
const TESTS = [
{
// hello world Приветствую ми 你好
base64: 'aGVsbG8gd29ybGQg0J/RgNC40LLQtdGC0YHRgtCy0YPRjiDQvNC4IOS9oOWlvQ==',
expect: new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130, 209, 129, 209, 130, 208, 178, 209, 131, 209, 142, 32, 208, 188, 208, 184, 32, 228, 189, 160, 229, 165, 189])
},
{
// ✓ à la mode
base64: '4pyTIMOgIGxhIG1vZGU=',
expect: new Uint8Array([226, 156, 147, 32, 195, 160, 32, 108, 97, 32, 109, 111, 100, 101])
},
{
// Hello World!
base64: 'SGVsbG8gV29ybGQh',
expect: new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33])
},
{
base64: 'AA==',
expect: new Uint8Array([0])
},
{
base64: 'AAA=',
expect: new Uint8Array([0, 0])
},
{
base64: 'AAAA',
expect: new Uint8Array([0, 0, 0])
}
];
describe('base64Decode', (): void => {
it('decodes a mixed base64 utf8 string (1)', (): void => {
it.each(TESTS)('%p', (test): void => {
expect(
base64Decode('aGVsbG8gd29ybGQg0J/RgNC40LLQtdGC0YHRgtCy0YPRjiDQvNC4IOS9oOWlvQ==')
).toEqual(
// hello world Приветствую ми 你好
new Uint8Array([
104, 101, 108, 108, 111, 32, 119, 111,
114, 108, 100, 32, 208, 159, 209, 128,
208, 184, 208, 178, 208, 181, 209, 130,
209, 129, 209, 130, 208, 178, 209, 131,
209, 142, 32, 208, 188, 208, 184, 32,
228, 189, 160, 229, 165, 189
])
);
});
it('decodes a mixed base64 utf8 string (2)', (): void => {
expect(
base64Decode('4pyTIMOgIGxhIG1vZGU=')
).toEqual(
// ✓ à la mode
new Uint8Array([
226, 156, 147, 32, 195,
160, 32, 108, 97, 32,
109, 111, 100, 101
])
);
});
it('decodes a mixed base64 utf8 string (3)', (): void => {
expect(
base64Decode('SGVsbG8gV29ybGQh')
).toEqual(
// Hello World!
new Uint8Array([
72, 101, 108, 108, 111,
32, 87, 111, 114, 108,
100, 33
])
);
base64Decode(test.base64)
).toEqual(test.expect);
});
});