feat(Int)
This commit is contained in:
29
test/Int.test.js
Normal file
29
test/Int.test.js
Normal file
@ -0,0 +1,29 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { expectDataViewEqual, filledDataView, sizedDataView } from '.';
|
||||
import { Int, parse, serialize, sizeof } from "../src";
|
||||
|
||||
describe(Int.name, () => {
|
||||
|
||||
const Type = Int(32, 'unsigned')
|
||||
const type = 512
|
||||
const type_dv = filledDataView([0x00, 0x00, 0x02, 0x00])
|
||||
|
||||
test('serialize', () => {
|
||||
let actual = sizedDataView(3);
|
||||
expect(() => serialize(actual, type, Type)).toThrow()
|
||||
|
||||
actual = sizedDataView(sizeof(Type))
|
||||
serialize(actual, type, Type)
|
||||
|
||||
expectDataViewEqual(actual, type_dv)
|
||||
})
|
||||
|
||||
test('parse', () => {
|
||||
expect(parse(type_dv, Type)).toEqual(type)
|
||||
})
|
||||
|
||||
test('serialize, overflow', () => {
|
||||
expect(() => serialize(sizedDataView(1), 128, Int(8, 'signed'))).toThrow()
|
||||
expect(() => serialize(sizedDataView(1), -129, Int(8, 'signed'))).toThrow()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user