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: increase coverage for buffer.js · nodejs/node@a755ef0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-buffer-arraybuffer.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-arraybuffer.js
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,41 @@ b.writeDoubleBE(11.11, 0, true);
107107
return true;
108108
});
109109
}
110+
111+
{
112+
// If byteOffset is not numeric, it defaults to 0.
113+
const ab = new ArrayBuffer(10);
114+
const expected = Buffer.from(ab, 0);
115+
assert.deepStrictEqual(Buffer.from(ab, 'fhqwhgads'), expected);
116+
assert.deepStrictEqual(Buffer.from(ab, NaN), expected);
117+
assert.deepStrictEqual(Buffer.from(ab, {}), expected);
118+
assert.deepStrictEqual(Buffer.from(ab, []), expected);
119+
120+
// If byteOffset can be converted to a number, it will be.
121+
assert.deepStrictEqual(Buffer.from(ab, [1]), Buffer.from(ab, 1));
122+
123+
// If byteOffset is Infinity, throw.
124+
assert.throws(
125+
() => { Buffer.from(ab, Infinity); },
126+
/^RangeError: 'offset' is out of bounds$/
127+
);
128+
}
129+
130+
{
131+
// If length is not numeric, it defaults to 0.
132+
const ab = new ArrayBuffer(10);
133+
const expected = Buffer.from(ab, 0, 0);
134+
assert.deepStrictEqual(Buffer.from(ab, 0, 'fhqwhgads'), expected);
135+
assert.deepStrictEqual(Buffer.from(ab, 0, NaN), expected);
136+
assert.deepStrictEqual(Buffer.from(ab, 0, {}), expected);
137+
assert.deepStrictEqual(Buffer.from(ab, 0, []), expected);
138+
139+
// If length can be converted to a number, it will be.
140+
assert.deepStrictEqual(Buffer.from(ab, 0, [1]), Buffer.from(ab, 0, 1));
141+
142+
//If length is Infinity, throw.
143+
assert.throws(
144+
() => { Buffer.from(ab, 0, Infinity); },
145+
/^RangeError: 'length' is out of bounds$/
146+
);
147+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — 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.