Skip to content
Permalink
Browse files

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...
kakts authored and targos committed Jun 7, 2018
1 parent 511d610 commit 9f2bf3c1b38afe6d78d870793e83cabc8bbc5277
Showing with 55 additions and 0 deletions.
  1. +55 −0 test/parallel/test-fs-util-validateoffsetlengthwrite.js
@@ -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}`
}
);
}

0 comments on commit 9f2bf3c

Please sign in to comment.
You can’t perform that action at this time.