@cloudpss/ubjson
Version:
45 lines (40 loc) • 1.04 kB
text/typescript
import { encodeMany, decodeMany } from '../dist/index.js';
test('encode/decode many', () => {
const data = [
{
a: 1,
b: 2,
c: 3,
d: 4,
e: 5,
},
1,
null,
'x',
true,
[1, 2, 3],
Uint8Array.of(3, 3, 1),
];
const encoded = encodeMany(data);
const decoded = [...decodeMany(encoded)];
expect(decoded).toEqual(data);
});
test('encode/decode many with error', () => {
expect(() =>
encodeMany(
(function* () {
yield 1;
throw new Error('xx');
})(),
),
).toThrow('xx');
});
test('encode/decode many with invalid value', () => {
expect(() => encodeMany([1, () => 1])).toThrow();
});
test('encode/decode many with undefined', () => {
const data = [1, null, undefined, [undefined]];
const encoded = encodeMany(data);
const decoded = [...decodeMany(encoded)];
expect(decoded).toEqual([1, null, [null]]);
});