Remove buffer dependency

This commit is contained in:
Jack Hadrill
2022-02-22 22:35:55 +00:00
parent 4d7cf1347f
commit 5c17b880cf
19 changed files with 106 additions and 96 deletions

View File

@@ -31,7 +31,7 @@ test('Read a buffer.', () => {
// Then
const result = smartBuffer.readBytes(4)
expect(result).toMatchObject(Buffer.from([0, 1, 2, 3]))
expect(result).toMatchObject(new Uint8Array([0, 1, 2, 3]))
})
test('Read a UInt16 from an offset.', () => {
@@ -67,7 +67,7 @@ test('Read a buffer from an offset.', () => {
smartBuffer.cursor = 2
// Then
expect(smartBuffer.readBytes(4)).toMatchObject(Buffer.from([2, 3, 4, 5]))
expect(smartBuffer.readBytes(4)).toMatchObject(new Uint8Array([2, 3, 4, 5]))
})
test('Write a UInt16.', () => {
@@ -78,7 +78,7 @@ test('Write a UInt16.', () => {
smartBuffer.writeUInt16(12345)
// Then
expect(smartBuffer.data).toMatchObject(Buffer.from([0x30, 0x39]))
expect(smartBuffer.data).toMatchObject(new Uint8Array([0x30, 0x39]))
})
test('Write a UInt32.', () => {
@@ -89,7 +89,7 @@ test('Write a UInt32.', () => {
smartBuffer.writeUInt32(1234567890)
// Then
expect(smartBuffer.data).toMatchObject(Buffer.from([0x49, 0x96, 0x02, 0xD2]))
expect(smartBuffer.data).toMatchObject(new Uint8Array([0x49, 0x96, 0x02, 0xD2]))
})
test('Write a buffer.', () => {
@@ -100,7 +100,7 @@ test('Write a buffer.', () => {
smartBuffer.writeBytes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
// Then
expect(smartBuffer.data).toMatchObject(Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
expect(smartBuffer.data).toMatchObject(new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
})
test('Write a UInt16 at an offset.', () => {
@@ -112,7 +112,7 @@ test('Write a UInt16 at an offset.', () => {
smartBuffer.writeUInt16(12345)
// Then
expect(smartBuffer.data).toMatchObject(Buffer.from([0x00, 0x00, 0x30, 0x39]))
expect(smartBuffer.data).toMatchObject(new Uint8Array([0x00, 0x00, 0x30, 0x39]))
})
test('Write a UInt32 at an offset.', () => {
@@ -124,7 +124,7 @@ test('Write a UInt32 at an offset.', () => {
smartBuffer.writeUInt32(1234567890)
// Then
expect(smartBuffer.data).toMatchObject(Buffer.from([0x00, 0x00, 0x49, 0x96, 0x02, 0xD2]))
expect(smartBuffer.data).toMatchObject(new Uint8Array([0x00, 0x00, 0x49, 0x96, 0x02, 0xD2]))
})
test('Write a buffer at an offset.', () => {
@@ -136,7 +136,7 @@ test('Write a buffer at an offset.', () => {
smartBuffer.writeBytes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
// Then
expect(smartBuffer.data).toMatchObject(Buffer.from([0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
expect(smartBuffer.data).toMatchObject(new Uint8Array([0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
})
test('Cursor is correctly incremented after reading a UInt16.', () => {