◐ Shell
clean mode source ↗

test: improve internal/buffer.js test coverage · nodejs/node@17954c2

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(

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(

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);

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);