-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for noAssert option in buf.read*()
PR-URL: #10713 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
c012dd7
commit 06a1e9e
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
// testing basic buffer read functions | ||
const buf = Buffer.from([0xa4, 0xfd, 0x48, 0xea, 0xcf, 0xff, 0xd9, 0x01, 0xde]); | ||
|
||
function read(buff, funx, args, expected) { | ||
|
||
assert.strictEqual(buff[funx](...args), expected); | ||
assert.throws( | ||
() => buff[funx](-1), | ||
/^RangeError: Index out of range$/ | ||
); | ||
|
||
assert.doesNotThrow( | ||
() => assert.strictEqual(buff[funx](...args, true), expected), | ||
'noAssert does not change return value for valid ranges' | ||
); | ||
|
||
} | ||
|
||
// testing basic functionality of readDoubleBE() and readDOubleLE() | ||
read(buf, 'readDoubleBE', [1], -3.1827727774563287e+295); | ||
read(buf, 'readDoubleLE', [1], -6.966010051009108e+144); | ||
|
||
// testing basic functionality of readFLoatBE() and readFloatLE() | ||
read(buf, 'readFloatBE', [1], -1.6691549692541768e+37); | ||
read(buf, 'readFloatLE', [1], -7861303808); | ||
|
||
// testing basic functionality of readInt8() | ||
read(buf, 'readInt8', [1], -3); | ||
|
||
// testing basic functionality of readInt16BE() and readInt16LE() | ||
read(buf, 'readInt16BE', [1], -696); | ||
read(buf, 'readInt16LE', [1], 0x48fd); | ||
|
||
// testing basic functionality of readInt32BE() and readInt32LE() | ||
read(buf, 'readInt32BE', [1], -45552945); | ||
read(buf, 'readInt32LE', [1], -806729475); | ||
|
||
// testing basic functionality of readIntBE() and readIntLE() | ||
read(buf, 'readIntBE', [1, 1], -3); | ||
read(buf, 'readIntLE', [2, 1], 0x48); | ||
|
||
// testing basic functionality of readUInt8() | ||
read(buf, 'readUInt8', [1], 0xfd); | ||
|
||
// testing basic functionality of readUInt16BE() and readUInt16LE() | ||
read(buf, 'readUInt16BE', [2], 0x48ea); | ||
read(buf, 'readUInt16LE', [2], 0xea48); | ||
|
||
// testing basic functionality of readUInt32BE() and readUInt32LE() | ||
read(buf, 'readUInt32BE', [1], 0xfd48eacf); | ||
read(buf, 'readUInt32LE', [1], 0xcfea48fd); | ||
|
||
// testing basic functionality of readUIntBE() and readUIntLE() | ||
read(buf, 'readUIntBE', [2, 0], 0xfd); | ||
read(buf, 'readUIntLE', [2, 0], 0x48); |