From 262f3777cefdba21987947b56827c3b8112fe5ba Mon Sep 17 00:00:00 2001 From: Masashi Hirano Date: Wed, 30 May 2018 00:57:18 +0900 Subject: [PATCH] test: improve internal/buffer.js test coverage Added tests buffer.js methods to write 48 bit value to improve test coverage. PR-URL: https://github.com/nodejs/node/pull/21061 Reviewed-By: Weijia Wang Reviewed-By: Rich Trott Reviewed-By: Trivikram Kamat Reviewed-By: Lance Ball --- test/parallel/test-buffer-readint.js | 2 +- test/parallel/test-buffer-readuint.js | 2 +- test/parallel/test-buffer-writeint.js | 15 +++++++++++++++ test/parallel/test-buffer-writeuint.js | 11 +++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-buffer-readint.js b/test/parallel/test-buffer-readint.js index d417f88b82fe73..971dd3bb959444 100644 --- a/test/parallel/test-buffer-readint.js +++ b/test/parallel/test-buffer-readint.js @@ -160,7 +160,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, undefined].forEach((o) => { assert.throws( diff --git a/test/parallel/test-buffer-readuint.js b/test/parallel/test-buffer-readuint.js index d2c07e4de87f89..de683f09503eff 100644 --- a/test/parallel/test-buffer-readuint.js +++ b/test/parallel/test-buffer-readuint.js @@ -128,7 +128,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, undefined].forEach((o) => { assert.throws( diff --git a/test/parallel/test-buffer-writeint.js b/test/parallel/test-buffer-writeint.js index fb91aa11b6f995..0e5b4960ab234d 100644 --- a/test/parallel/test-buffer-writeint.js +++ b/test/parallel/test-buffer-writeint.js @@ -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); diff --git a/test/parallel/test-buffer-writeuint.js b/test/parallel/test-buffer-writeuint.js index 8fe7783e71be04..999440114c74f4 100644 --- a/test/parallel/test-buffer-writeuint.js +++ b/test/parallel/test-buffer-writeuint.js @@ -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);