summaryrefslogtreecommitdiff
path: root/cli/tests/node_compat/test/parallel/test-buffer-alloc.js
diff options
context:
space:
mode:
authorAapo Alasuutari <aapo.alasuutari@gmail.com>2023-10-08 11:09:50 +0900
committerGitHub <noreply@github.com>2023-10-08 11:09:50 +0900
commiteffb5e1ce417e9b7f22adcdc598e9a5ec593f4a2 (patch)
tree620544d0d4051ad16d78c5df3fbed0441b800ea0 /cli/tests/node_compat/test/parallel/test-buffer-alloc.js
parentedeccef4990598620bf5595df6fc8c1b1b1a7f73 (diff)
fix(node/buffer): utf8ToBytes should return a Uint8Array (#20769)
Diffstat (limited to 'cli/tests/node_compat/test/parallel/test-buffer-alloc.js')
-rw-r--r--cli/tests/node_compat/test/parallel/test-buffer-alloc.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/cli/tests/node_compat/test/parallel/test-buffer-alloc.js b/cli/tests/node_compat/test/parallel/test-buffer-alloc.js
index c93e80f63..35b29ae95 100644
--- a/cli/tests/node_compat/test/parallel/test-buffer-alloc.js
+++ b/cli/tests/node_compat/test/parallel/test-buffer-alloc.js
@@ -2,14 +2,14 @@
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
-// Taken from Node 16.13.0
-// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
+// Taken from Node 18.12.1
+// This file is automatically generated by `tools/node_compat/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
-const vm = require('vm');
+// const vm = require('vm');
const SlowBuffer = require('buffer').SlowBuffer;
@@ -48,7 +48,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);
@@ -57,11 +75,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]);
}
}