Skip to content

Commit a9d9d76

Browse files
kaktsaddaleax
authored andcommitted
test: add some test cases for validateOffsetLengthWrite
PR-URL: #21195 Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent 467a307 commit a9d9d76

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
4+
const common = require('../common');
5+
6+
const { validateOffsetLengthWrite } = require('internal/fs/utils');
7+
const { kMaxLength } = require('buffer');
8+
9+
// RangeError when offset > byteLength
10+
{
11+
const offset = 100;
12+
const length = 100;
13+
const byteLength = 50;
14+
common.expectsError(
15+
() => validateOffsetLengthWrite(offset, length, byteLength),
16+
{
17+
code: 'ERR_OUT_OF_RANGE',
18+
type: RangeError,
19+
message: 'The value of "offset" is out of range. ' +
20+
`It must be <= ${byteLength}. Received ${offset}`
21+
}
22+
);
23+
}
24+
25+
// RangeError when byteLength > kMaxLength, and length > kMaxLength - offset .
26+
{
27+
const offset = kMaxLength;
28+
const length = 100;
29+
const byteLength = kMaxLength + 1;
30+
common.expectsError(
31+
() => validateOffsetLengthWrite(offset, length, byteLength),
32+
{
33+
code: 'ERR_OUT_OF_RANGE',
34+
type: RangeError,
35+
message: 'The value of "length" is out of range. ' +
36+
`It must be <= ${kMaxLength - offset}. Received ${length}`
37+
}
38+
);
39+
}
40+
41+
// RangeError when byteLength < kMaxLength, and length > byteLength - offset .
42+
{
43+
const offset = kMaxLength - 150;
44+
const length = 200;
45+
const byteLength = kMaxLength - 100;
46+
common.expectsError(
47+
() => validateOffsetLengthWrite(offset, length, byteLength),
48+
{
49+
code: 'ERR_OUT_OF_RANGE',
50+
type: RangeError,
51+
message: 'The value of "length" is out of range. ' +
52+
`It must be <= ${byteLength - offset}. Received ${length}`
53+
}
54+
);
55+
}

0 commit comments

Comments
 (0)