feat(DataView, ConstDataView)
This commit is contained in:
31
test/ConstDataView.test.js
Normal file
31
test/ConstDataView.test.js
Normal file
@ -0,0 +1,31 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { ConstDataView, parse, serialize, sizeofHead } from "../src";
|
||||
import { expectDataViewEqual, filledDataView } from ".";
|
||||
|
||||
describe(ConstDataView.name, () => {
|
||||
test('serialize', () => {
|
||||
const expected = filledDataView([0x00, 0x00, 0x01, 0x02, 0x00, 0x00])
|
||||
const dv = filledDataView([0x01, 0x02])
|
||||
|
||||
const buffer = new ArrayBuffer(6)
|
||||
let actual = new DataView(buffer, 2, 1)
|
||||
expect(() => serialize(actual, dv, ConstDataView(2))).toThrow()
|
||||
|
||||
actual = new DataView(buffer, 2, 2)
|
||||
|
||||
serialize(actual, dv, ConstDataView(2))
|
||||
expectDataViewEqual(new DataView(actual.buffer), expected)
|
||||
})
|
||||
|
||||
test('parse', () => {
|
||||
const expected = filledDataView([0x01, 0x02])
|
||||
const dv = filledDataView([0x00, 0x00, 0x01, 0x02, 0x00, 0x00])
|
||||
const frame = new DataView(dv.buffer, dv.byteOffset + 2, 2)
|
||||
const actual = parse(frame, ConstDataView(2))
|
||||
expectDataViewEqual(actual, expected)
|
||||
})
|
||||
|
||||
test('sizeof', () => {
|
||||
expect(sizeofHead(ConstDataView(2))).toEqual(2)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user