feat(Int)

This commit is contained in:
2025-08-05 10:09:53 +03:00
parent 8c2d7118c2
commit f5b485d546
5 changed files with 123 additions and 2 deletions

29
test/Int.test.js Normal file
View 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()
})
})