Skip to content

Commit

Permalink
v0.10.0: npmignore & typedoc
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin committed May 6, 2024
1 parent c311715 commit 1708d00
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,7 @@ out
/*.config.js
/dist/assets
/tsconfig.json
/tsdoc.json
/tsup.config.ts
/typedoc
/typedoc.json
20 changes: 16 additions & 4 deletions lib/buffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ describe('read/write Float16', () => {
{ hex: 'fc00', float: -Infinity },
{ hex: '7e00', float: NaN },
{ hex: 'fe00', float: -NaN },
])('Buffer.from("$hex", "hex").readFloat16BE() = $expected', ({ hex, float }) => {
])('Buffer.from("$hex", "hex").readFloat16BE() = $float', ({ hex, float }) => {
expect(Buffer.from(hex, 'hex').readFloat16BE()).toBe(float)
expect(new Buffer(2).writeFloat16BE(float).toString('hex')).toBe(hex)
})
Expand Down Expand Up @@ -1638,8 +1638,10 @@ describe('Buffer.unpack()', () => {
describe('Buffer.iterUnpack()', () => {
test('should unpack all tuples', () => {
const buf1 = Buffer.from('01fe01fe', 'hex')
const actual = [...buf1.iterUnpack('!BB')]
expect(actual).toEqual([[1, 254], [1, 254]])
const actual1 = [...buf1.iterUnpack('!BB')]
expect(actual1).toEqual([[1, 254], [1, 254]])
const actual2 = [...Buffer.iterUnpack(buf1, '!BB')]
expect(actual2).toEqual([[1, 254], [1, 254]])
})

test('should throw error with invalid type of buf', () => {
Expand All @@ -1661,6 +1663,16 @@ describe('Buffer.iterUnpack()', () => {
expect(err.message).toMatch(/lenRequired/)
}
})

test('should throw error with unknown format', () => {
expect.hasAssertions()
try {
jest.spyOn(Buffer, 'packParseFormat').mockReturnValueOnce({ littleEndian: false, items: [[1, 'z']] })
console.log([...Buffer.iterUnpack(Buffer.from('00', 'hex'), 'z')])
} catch (err) {
expect(err.message).toMatch(/Unknown format/)
}
})
})

describe('Buffer.packParseFormat()', () => {
Expand All @@ -1673,7 +1685,7 @@ describe('Buffer.packParseFormat()', () => {
}
})

test('should throw error with invalid type of format', () => {
test('should throw error with invalid format', () => {
expect.hasAssertions()
try {
Buffer.packParseFormat('!')
Expand Down
Loading

0 comments on commit 1708d00

Please sign in to comment.