feat(Struct)
This commit is contained in:
27
test/ConstString.test.js
Normal file
27
test/ConstString.test.js
Normal 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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user