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 17954c2

Browse filesBrowse files
Masashi Hiranotargos
authored andcommitted
test: improve internal/buffer.js test coverage
Added tests buffer.js methods to write 48 bit value to improve test coverage. PR-URL: #21061 Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Lance Ball <lball@redhat.com>
1 parent 2ff4704 commit 17954c2
Copy full SHA for 17954c2

File tree

Expand file treeCollapse file tree

4 files changed

+28
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+28
-2
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-readint.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ const assert = require('assert');
169169
});
170170

171171
// Test 1 to 6 bytes.
172-
for (let i = 1; i < 6; i++) {
172+
for (let i = 1; i <= 6; i++) {
173173
['readIntBE', 'readIntLE'].forEach((fn) => {
174174
['', '0', null, {}, [], () => {}, true, false].forEach((o) => {
175175
assert.throws(
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-readuint.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const assert = require('assert');
130130
});
131131

132132
// Test 1 to 6 bytes.
133-
for (let i = 1; i < 6; i++) {
133+
for (let i = 1; i <= 6; i++) {
134134
['readUIntBE', 'readUIntLE'].forEach((fn) => {
135135
['', '0', null, {}, [], () => {}, true, false].forEach((o) => {
136136
assert.throws(
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-writeint.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ const errorOutOfBounds = common.expectsError({
162162
});
163163
}
164164

165+
// Test 48 bit
166+
{
167+
const value = 0x1234567890ab;
168+
const buffer = Buffer.allocUnsafe(6);
169+
buffer.writeIntBE(value, 0, 6);
170+
assert.ok(buffer.equals(new Uint8Array([
171+
0x12, 0x34, 0x56, 0x78, 0x90, 0xab
172+
])));
173+
174+
buffer.writeIntLE(value, 0, 6);
175+
assert.ok(buffer.equals(new Uint8Array([
176+
0xab, 0x90, 0x78, 0x56, 0x34, 0x12
177+
])));
178+
}
179+
165180
// Test Int
166181
{
167182
const data = Buffer.alloc(8);
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-writeuint.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ const assert = require('assert');
110110
assert.ok(data.equals(new Uint8Array([0x6d, 0x6d, 0x6d, 0x0a, 0xf9, 0xe7])));
111111
}
112112

113+
// Test 48 bit
114+
{
115+
const value = 0x1234567890ab;
116+
const data = Buffer.allocUnsafe(6);
117+
data.writeUIntBE(value, 0, 6);
118+
assert.ok(data.equals(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x90, 0xab])));
119+
120+
data.writeUIntLE(value, 0, 6);
121+
assert.ok(data.equals(new Uint8Array([0xab, 0x90, 0x78, 0x56, 0x34, 0x12])));
122+
}
123+
113124
// Test UInt
114125
{
115126
const data = Buffer.alloc(8);

0 commit comments

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