Files
serialize-js/test/ConstString.test.js
2025-08-04 15:33:12 +03:00

28 lines
822 B
JavaScript

import { describe, expect, test } from "vitest";
import { ConstString, parse, serialize, sizeofHead } from "../src";
import { expectDataViewEqual, 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))
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)
})
})