import { describe, expect, test } from "vitest"; import { ConstString, parse, serialize, sizeofHead } from "../src"; import { expectDataViewEqual } from "."; import { filledDataView, sizedDataView } from '../src' describe(ConstString.name, () => { test('serialize', () => { const expected = filledDataView([0x68, 0x65, 0x6C, 0x00, 0x00]) let dv = sizedDataView(4) expect(() => serialize(dv, 'hello', ConstString(5))).toThrow() dv = sizedDataView(5) expect(() => serialize(dv, 'hello', ConstString(3))).toThrow() serialize(dv, 'hel', ConstString(3)) expectDataViewEqual(dv, expected) }) test('parse', () => { const expected = 'hel' const dv = filledDataView([0x68, 0x65, 0x6C, 0x6C, 0x6F]) const actual = parse(dv, ConstString(3)) expectDataViewEqual(actual, expected) }) test('sizeof', () => { expect(sizeofHead(ConstString(2))).toEqual(2) }) })