fix(Array, {HeadlessType})
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { ConstArray, parse, serialize, sizeof, sizeofHead } from "../src";
|
||||
import { ConstArray, isHeadless, parse, serialize, sizeof, sizeofHead } from "../src";
|
||||
import { expectDataViewEqual, filledDataView, sizedDataView } from ".";
|
||||
|
||||
describe(ConstArray.name, () => {
|
||||
@ -33,4 +33,41 @@ describe(ConstArray.name, () => {
|
||||
test('sizeof', () => {
|
||||
expect(sizeofHead(ConstArray(2), Number)).toEqual(16)
|
||||
})
|
||||
|
||||
const array_dv = filledDataView([
|
||||
0x00, 0x00, 0x00, 0x08,
|
||||
0x00, 0x00, 0x00, 0x11,
|
||||
// hello
|
||||
0x00, 0x00, 0x00, 0x05,
|
||||
0x68, 0x65, 0x6C, 0x6C, 0x6F,
|
||||
// sek1ro
|
||||
0x00, 0x00, 0x00, 0x06,
|
||||
0x73, 0x65, 0x6b, 0x31, 0x72, 0x6f,
|
||||
])
|
||||
const array = ['hello', 'sek1ro']
|
||||
|
||||
test('serialize, String', () => {
|
||||
|
||||
const actual = sizedDataView(sizeof(array, ConstArray(2), String))
|
||||
|
||||
expect(() => sizeof(ConstArray(2), String)).toThrow()
|
||||
|
||||
serialize(actual, array, ConstArray(2), String)
|
||||
expectDataViewEqual(actual, array_dv)
|
||||
})
|
||||
|
||||
test('parse, String', () => {
|
||||
expect(parse(array_dv, ConstArray(2), String)).toEqual(array)
|
||||
})
|
||||
|
||||
test('isHeadless', () => {
|
||||
expect(isHeadless(ConstArray(2), Number)).toBeFalsy()
|
||||
expect(isHeadless(ConstArray(2), String)).toBeTruthy()
|
||||
})
|
||||
|
||||
test('sizeof', () => {
|
||||
expect(sizeof(ConstArray(2), Number)).toBe(16)
|
||||
expect(() => sizeof(ConstArray(2), String)).toThrow()
|
||||
expect(sizeof(['hello', 'sek1ro'], ConstArray(2), String)).toBe(27)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user