Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a15de48

Browse filesBrowse files
mritunjayzMylesBorins
authored andcommitted
test: add property for RangeError in test-buffer-copy
PR-URL: #23968 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent d1ac802 commit a15de48
Copy full SHA for a15de48

File tree

Expand file treeCollapse file tree

1 file changed

+13
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-5
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-buffer-copy.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-copy.js
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55

66
const b = Buffer.allocUnsafe(1024);
77
const c = Buffer.allocUnsafe(512);
8+
9+
const errorProperty = {
10+
code: 'ERR_INDEX_OUT_OF_RANGE',
11+
type: RangeError,
12+
message: 'Index out of range'
13+
};
14+
815
let cntr = 0;
916

1017
{
@@ -107,9 +114,9 @@ bb.fill('hello crazy world');
107114
b.copy(c, 0, 100, 10);
108115

109116
// copy throws at negative sourceStart
110-
assert.throws(function() {
111-
Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1);
112-
}, RangeError);
117+
common.expectsError(
118+
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1),
119+
errorProperty);
113120

114121
{
115122
// check sourceEnd resets to targetEnd if former is greater than the latter
@@ -122,7 +129,8 @@ assert.throws(function() {
122129
}
123130

124131
// throw with negative sourceEnd
125-
assert.throws(() => b.copy(c, 0, 0, -1), RangeError);
132+
common.expectsError(
133+
() => b.copy(c, 0, -1), errorProperty);
126134

127135
// when sourceStart is greater than sourceEnd, zero copied
128136
assert.strictEqual(b.copy(c, 0, 100, 10), 0);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.