diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 1368136abe8f22..d2085d11802aee 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -41,7 +41,25 @@ assert.strictEqual(d.length, 0); assert.strictEqual(b.offset, 0); } +// Test creating a Buffer from a Uint8Array +{ + const ui8 = new Uint8Array(4).fill(42); + const e = Buffer.from(ui8); + for (const [index, value] of e.entries()) { + assert.strictEqual(value, ui8[index]); + } +} +// Test creating a Buffer from a Uint8Array (old constructor) +{ + const ui8 = new Uint8Array(4).fill(42); + const e = Buffer(ui8); + for (const [key, value] of e.entries()) { + assert.strictEqual(value, ui8[key]); + } +} + // Test creating a Buffer from a Uint32Array +// Note: it is implicitly interpreted as Array of integers modulo 256 { const ui32 = new Uint32Array(4).fill(42); const e = Buffer.from(ui32); @@ -50,11 +68,12 @@ assert.strictEqual(d.length, 0); } } // Test creating a Buffer from a Uint32Array (old constructor) +// Note: it is implicitly interpreted as Array of integers modulo 256 { const ui32 = new Uint32Array(4).fill(42); const e = Buffer(ui32); for (const [key, value] of e.entries()) { - assert.deepStrictEqual(value, ui32[key]); + assert.strictEqual(value, ui32[key]); } } diff --git a/test/parallel/test-webcrypto-random.js b/test/parallel/test-webcrypto-random.js index c3fc6aaab2eb1e..73089fe7b49094 100644 --- a/test/parallel/test-webcrypto-random.js +++ b/test/parallel/test-webcrypto-random.js @@ -47,10 +47,10 @@ for (const ctor of intTypedConstructors) { } { - const buf = new Uint16Array(10); - const before = Buffer.from(buf).toString('hex'); + const buf = Buffer.alloc(10); + const before = buf.toString('hex'); webcrypto.getRandomValues(buf); - const after = Buffer.from(buf).toString('hex'); + const after = buf.toString('hex'); assert.notStrictEqual(before, after); }