feat(Boolean)
This commit is contained in:
@ -3,6 +3,16 @@ import { expectDataViewEqual, filledDataView, sizedDataView } from '.'
|
||||
import { parse, serialize, sizeof, sizeofHead } from '../src'
|
||||
|
||||
describe('serialize', () => {
|
||||
test('Boolean', () => {
|
||||
const expected = filledDataView([0x01])
|
||||
let actual = sizedDataView(0)
|
||||
expect(() => serialize(actual, true, Boolean)).toThrow()
|
||||
|
||||
actual = sizedDataView(1)
|
||||
|
||||
serialize(actual, true, Boolean)
|
||||
expectDataViewEqual(actual, expected)
|
||||
})
|
||||
test('Number', () => {
|
||||
const expected = filledDataView([0x40, 0x97, 0xF2, 0x80, 0x00, 0x00, 0x00, 0x00])
|
||||
let dv = sizedDataView(7)
|
||||
@ -61,11 +71,15 @@ describe('serialize', () => {
|
||||
})
|
||||
|
||||
describe('parse', () => {
|
||||
test('Boolean', () => {
|
||||
expect(parse(filledDataView([0x00]), Boolean)).toBeFalsy()
|
||||
expect(parse(filledDataView([0x01]), Boolean)).toBeTruthy()
|
||||
})
|
||||
test('Number', () => {
|
||||
const expected = 1532.625
|
||||
const dv = filledDataView([0x40, 0x97, 0xF2, 0x80, 0x00, 0x00, 0x00, 0x00])
|
||||
const actual = parse(dv, Number)
|
||||
expectDataViewEqual(actual, expected)
|
||||
expect(actual).toEqual(expected)
|
||||
})
|
||||
test('String', () => {
|
||||
const expected = 'hello'
|
||||
@ -74,7 +88,7 @@ describe('parse', () => {
|
||||
0x68, 0x65, 0x6C, 0x6C, 0x6F
|
||||
])
|
||||
const actual = parse(dv, String)
|
||||
expectDataViewEqual(actual, expected)
|
||||
expect(actual).toEqual(expected)
|
||||
})
|
||||
test('Array, Number', () => {
|
||||
const expected = [1, 2]
|
||||
@ -84,7 +98,7 @@ describe('parse', () => {
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
])
|
||||
const actual = parse(dv, Array, Number)
|
||||
expectDataViewEqual(actual, expected)
|
||||
expect(actual).toEqual(expected)
|
||||
})
|
||||
test('DataView', () => {
|
||||
const expected = filledDataView([
|
||||
@ -112,11 +126,16 @@ describe('sizeofHead', () => {
|
||||
expect(sizeofHead(Array, Number)).toEqual(4)
|
||||
expect(sizeofHead([1], Array, Number)).toEqual(4)
|
||||
})
|
||||
test('DataView', () => {
|
||||
expect(sizeofHead(DataView)).toEqual(4)
|
||||
expect(sizeofHead(filledDataView([0x01]), DataView)).toEqual(4)
|
||||
})
|
||||
})
|
||||
|
||||
describe('sizeof', () => {
|
||||
test('unknown', () => {
|
||||
expect(() => sizeof(String)).toThrow()
|
||||
expect(() => sizeof(Array, Number)).toThrow()
|
||||
expect(() => sizeof(DataView)).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user