0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-fs-util-validateoffsetlengthwrite.js
Zach Bjornson 5e3b4d6ed9 fs: allow int64 offset in fs.write/writeSync/fd.write
Ref https://github.com/nodejs/node/issues/26563

PR-URL: https://github.com/nodejs/node/pull/26572
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-08-16 22:09:34 -07:00

40 lines
1.0 KiB
JavaScript

// 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 > 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}`
}
);
}