Skip to content

Commit

Permalink
test: improve internal/buffer.js test coverage
Browse files Browse the repository at this point in the history
Added tests buffer.js methods to write 48 bit value to
improve test coverage.

PR-URL: #21061
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Lance Ball <[email protected]>
  • Loading branch information
Masashi Hirano authored and targos committed Jun 13, 2018
1 parent 2ff4704 commit 17954c2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-readint.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const assert = require('assert');
});

// Test 1 to 6 bytes.
for (let i = 1; i < 6; i++) {
for (let i = 1; i <= 6; i++) {
['readIntBE', 'readIntLE'].forEach((fn) => {
['', '0', null, {}, [], () => {}, true, false].forEach((o) => {
assert.throws(
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-readuint.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const assert = require('assert');
});

// Test 1 to 6 bytes.
for (let i = 1; i < 6; i++) {
for (let i = 1; i <= 6; i++) {
['readUIntBE', 'readUIntLE'].forEach((fn) => {
['', '0', null, {}, [], () => {}, true, false].forEach((o) => {
assert.throws(
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-buffer-writeint.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ const errorOutOfBounds = common.expectsError({
});
}

// Test 48 bit
{
const value = 0x1234567890ab;
const buffer = Buffer.allocUnsafe(6);
buffer.writeIntBE(value, 0, 6);
assert.ok(buffer.equals(new Uint8Array([
0x12, 0x34, 0x56, 0x78, 0x90, 0xab
])));

buffer.writeIntLE(value, 0, 6);
assert.ok(buffer.equals(new Uint8Array([
0xab, 0x90, 0x78, 0x56, 0x34, 0x12
])));
}

// Test Int
{
const data = Buffer.alloc(8);
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-buffer-writeuint.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ const assert = require('assert');
assert.ok(data.equals(new Uint8Array([0x6d, 0x6d, 0x6d, 0x0a, 0xf9, 0xe7])));
}

// Test 48 bit
{
const value = 0x1234567890ab;
const data = Buffer.allocUnsafe(6);
data.writeUIntBE(value, 0, 6);
assert.ok(data.equals(new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x90, 0xab])));

data.writeUIntLE(value, 0, 6);
assert.ok(data.equals(new Uint8Array([0xab, 0x90, 0x78, 0x56, 0x34, 0x12])));
}

// Test UInt
{
const data = Buffer.alloc(8);
Expand Down

0 comments on commit 17954c2

Please sign in to comment.