feat(Struct)

This commit is contained in:
2025-08-03 23:18:27 +03:00
parent 72f287a4e4
commit 38f0d922aa
15 changed files with 410 additions and 150 deletions

27
test/ConstString.test.js Normal file
View File

@ -0,0 +1,27 @@
import { describe, expect, test } from "vitest";
import { ConstString, parse, serialize, sizeofHead } from "../src";
import { filledDataView, sizedDataView } from ".";
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)
serialize(dv, 'hello', ConstString(3))
expect(dv).toEqual(expected)
})
test('parse', () => {
const expected = 'hel'
const dv = filledDataView([0x68, 0x65, 0x6C, 0x6C, 0x6F])
const actual = parse(dv, ConstString(3))
expect(actual).toEqual(expected)
})
test('sizeof', () => {
expect(sizeofHead(ConstString(2))).toEqual(2)
})
})