-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add some test cases for validateOffsetLengthWrite
PR-URL: #21195 Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
- Loading branch information
Showing
1 changed file
with
55 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,55 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const { validateOffsetLengthWrite } = require('internal/fs/utils'); | ||
const { kMaxLength } = require('buffer'); | ||
|
||
// RangeError when offset > byteLength | ||
{ | ||
const offset = 100; | ||
const length = 100; | ||
const byteLength = 50; | ||
common.expectsError( | ||
() => validateOffsetLengthWrite(offset, length, byteLength), | ||
{ | ||
code: 'ERR_OUT_OF_RANGE', | ||
type: RangeError, | ||
message: 'The value of "offset" is out of range. ' + | ||
`It must be <= ${byteLength}. Received ${offset}` | ||
} | ||
); | ||
} | ||
|
||
// RangeError when byteLength > kMaxLength, and length > kMaxLength - offset . | ||
{ | ||
const offset = kMaxLength; | ||
const length = 100; | ||
const byteLength = kMaxLength + 1; | ||
common.expectsError( | ||
() => validateOffsetLengthWrite(offset, length, byteLength), | ||
{ | ||
code: 'ERR_OUT_OF_RANGE', | ||
type: RangeError, | ||
message: 'The value of "length" is out of range. ' + | ||
`It must be <= ${kMaxLength - offset}. Received ${length}` | ||
} | ||
); | ||
} | ||
|
||
// RangeError when byteLength < kMaxLength, and length > byteLength - offset . | ||
{ | ||
const offset = kMaxLength - 150; | ||
const length = 200; | ||
const byteLength = kMaxLength - 100; | ||
common.expectsError( | ||
() => validateOffsetLengthWrite(offset, length, byteLength), | ||
{ | ||
code: 'ERR_OUT_OF_RANGE', | ||
type: RangeError, | ||
message: 'The value of "length" is out of range. ' + | ||
`It must be <= ${byteLength - offset}. Received ${length}` | ||
} | ||
); | ||
} |