GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add some test cases for validateOffsetLengthWrite · nodejs/node@9f2bf3c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-fs-util-validateoffsetlengthwrite.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-fs-util-validateoffsetlengthwrite.js‎

Copy file name to clipboard
+55Lines 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 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.