48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { BinaryReader } from '../binary/BinaryReader.js';
|
|
import {
|
|
readCompactU64,
|
|
readFssHttpExGuid,
|
|
readFssHttpStreamHeader,
|
|
} from './primitives.js';
|
|
|
|
describe('FSSHTTPB primitives', () => {
|
|
it.each([
|
|
[[0x00], 0n],
|
|
[[(0x5a << 1) | 1], 0x5an],
|
|
[[0xd2, 0x48], 0x1234n],
|
|
[
|
|
[0x80, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01],
|
|
0x0123_4567_89ab_cdefn,
|
|
],
|
|
] as const)('decodes compact unsigned integer %j', (input, expected) => {
|
|
const reader = new BinaryReader(Uint8Array.from(input));
|
|
expect(readCompactU64(reader)).toBe(expected);
|
|
expect(reader.remaining).toBe(0);
|
|
});
|
|
|
|
it('rejects a truncated extended GUID at the original absolute offset', () => {
|
|
const reader = new BinaryReader(
|
|
Uint8Array.from([0, 0, 0x80, 1, 2]),
|
|
2,
|
|
3,
|
|
'test ExGuid'
|
|
);
|
|
expect(() => readFssHttpExGuid(reader)).toThrowError(
|
|
expect.objectContaining({ code: 'BOUNDS_EXCEEDED', offset: 3 })
|
|
);
|
|
});
|
|
|
|
it('rejects stream-object end markers where a start is required', () => {
|
|
const reader = new BinaryReader(Uint8Array.from([0x05]));
|
|
expect(() => readFssHttpStreamHeader(reader)).toThrowError(
|
|
expect.objectContaining({
|
|
code: 'INVALID_STRUCTURE',
|
|
offset: 0,
|
|
structure: 'FSSHTTPB stream object header',
|
|
})
|
|
);
|
|
});
|
|
});
|