feat(DataView, ConstDataView)
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { describe, test, expect } from 'vitest'
|
||||
import { filledDataView, sizedDataView } from '.'
|
||||
import { expectDataViewEqual, filledDataView, sizedDataView } from '.'
|
||||
import { parse, serialize, sizeof, sizeofHead } from '../src'
|
||||
|
||||
describe('serialize', () => {
|
||||
@ -12,7 +12,7 @@ describe('serialize', () => {
|
||||
expect(8).toEqual(dv.byteLength)
|
||||
|
||||
serialize(dv, 1532.625, Number)
|
||||
expect(dv).toEqual(expected)
|
||||
expectDataViewEqual(dv, expected)
|
||||
})
|
||||
test('String', () => {
|
||||
const expected = filledDataView([
|
||||
@ -26,7 +26,7 @@ describe('serialize', () => {
|
||||
expect(9).toEqual(dv.byteLength)
|
||||
|
||||
serialize(dv, 'hello', String)
|
||||
expect(dv).toEqual(expected)
|
||||
expectDataViewEqual(dv, expected)
|
||||
})
|
||||
test('Array, Number', () => {
|
||||
const expected = filledDataView([
|
||||
@ -41,7 +41,22 @@ describe('serialize', () => {
|
||||
expect(20).toEqual(dv.byteLength)
|
||||
|
||||
serialize(dv, [1, 2], Array, Number)
|
||||
expect(dv).toEqual(expected)
|
||||
expectDataViewEqual(dv, expected)
|
||||
})
|
||||
test('DataView', () => {
|
||||
const expected = filledDataView([
|
||||
0x00, 0x00, 0x00, 0x04,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
])
|
||||
const dv = filledDataView([
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
])
|
||||
let actual = sizedDataView(7)
|
||||
expect(() => serialize(actual, dv, DataView)).toThrow()
|
||||
|
||||
actual = sizedDataView(8)
|
||||
serialize(actual, dv, DataView)
|
||||
expectDataViewEqual(actual, expected)
|
||||
})
|
||||
})
|
||||
|
||||
@ -50,7 +65,7 @@ describe('parse', () => {
|
||||
const expected = 1532.625
|
||||
const dv = filledDataView([0x40, 0x97, 0xF2, 0x80, 0x00, 0x00, 0x00, 0x00])
|
||||
const actual = parse(dv, Number)
|
||||
expect(actual).toEqual(expected)
|
||||
expectDataViewEqual(actual, expected)
|
||||
})
|
||||
test('String', () => {
|
||||
const expected = 'hello'
|
||||
@ -59,7 +74,7 @@ describe('parse', () => {
|
||||
0x68, 0x65, 0x6C, 0x6C, 0x6F
|
||||
])
|
||||
const actual = parse(dv, String)
|
||||
expect(actual).toEqual(expected)
|
||||
expectDataViewEqual(actual, expected)
|
||||
})
|
||||
test('Array, Number', () => {
|
||||
const expected = [1, 2]
|
||||
@ -69,7 +84,18 @@ describe('parse', () => {
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
])
|
||||
const actual = parse(dv, Array, Number)
|
||||
expect(actual).toEqual(expected)
|
||||
expectDataViewEqual(actual, expected)
|
||||
})
|
||||
test('DataView', () => {
|
||||
const expected = filledDataView([
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
])
|
||||
const dv = filledDataView([
|
||||
0x00, 0x00, 0x00, 0x04,
|
||||
0x00, 0x01, 0x02, 0x03,
|
||||
])
|
||||
const actual = parse(dv, DataView)
|
||||
expectDataViewEqual(actual, expected)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user