diff options
Diffstat (limited to 'cli/tests')
7 files changed, 52 insertions, 36 deletions
diff --git a/cli/tests/node_compat/config.jsonc b/cli/tests/node_compat/config.jsonc index d1ad44f41..8a31f4dc2 100644 --- a/cli/tests/node_compat/config.jsonc +++ b/cli/tests/node_compat/config.jsonc @@ -161,6 +161,7 @@ "test-assert.js", "test-bad-unicode.js", "test-btoa-atob.js", + "test-buffer-alloc.js", "test-buffer-arraybuffer.js", "test-buffer-ascii.js", "test-buffer-badhex.js", @@ -175,6 +176,7 @@ "test-buffer-fakes.js", "test-buffer-from.js", "test-buffer-includes.js", + "test-buffer-indexof.js", "test-buffer-inheritance.js", "test-buffer-isencoding.js", "test-buffer-iterator.js", 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]); } } diff --git a/cli/tests/node_compat/test/parallel/test-buffer-arraybuffer.js b/cli/tests/node_compat/test/parallel/test-buffer-arraybuffer.js index 9f515736e..286481758 100644 --- a/cli/tests/node_compat/test/parallel/test-buffer-arraybuffer.js +++ b/cli/tests/node_compat/test/parallel/test-buffer-arraybuffer.js @@ -2,8 +2,8 @@ // 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'; @@ -42,21 +42,18 @@ assert.strictEqual(dv.getFloat64(8, true), 3.1415); // Now test protecting users from doing stupid things -// TODO(Soremwar) -// There is an inconsistency on feross implementation on how buffers are checked -// Enable once it's sorted out -// assert.throws(function() { -// function AB() { } -// Object.setPrototypeOf(AB, ArrayBuffer); -// Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype); -// Buffer.from(new AB()); -// }, { -// code: 'ERR_INVALID_ARG_TYPE', -// name: 'TypeError', -// message: 'The first argument must be of type string or an instance of ' + -// 'Buffer, ArrayBuffer, or Array or an Array-like Object. Received ' + -// 'an instance of AB' -// }); +assert.throws(function() { + function AB() { } + Object.setPrototypeOf(AB, ArrayBuffer); + Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype); + Buffer.from(new AB()); +}, { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message: 'The first argument must be of type string or an instance of ' + + 'Buffer, ArrayBuffer, or Array or an Array-like Object. Received ' + + 'an instance of AB' +}); // Test the byteOffset and length arguments { diff --git a/cli/tests/node_compat/test/parallel/test-buffer-bytelength.js b/cli/tests/node_compat/test/parallel/test-buffer-bytelength.js index e23b3c3c2..7fb62c78f 100644 --- a/cli/tests/node_compat/test/parallel/test-buffer-bytelength.js +++ b/cli/tests/node_compat/test/parallel/test-buffer-bytelength.js @@ -2,15 +2,15 @@ // 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 SlowBuffer = require('buffer').SlowBuffer; -const vm = require('vm'); +// const vm = require('vm'); [ [32, 'latin1'], @@ -30,8 +30,6 @@ const vm = require('vm'); ); }); -assert.strictEqual(Buffer.byteLength('', undefined, true), -1); - assert(ArrayBuffer.isView(new Buffer(10))); assert(ArrayBuffer.isView(new SlowBuffer(10))); assert(ArrayBuffer.isView(Buffer.alloc(10))); @@ -98,6 +96,7 @@ assert.strictEqual(Buffer.byteLength('aGkk', 'base64'), 3); assert.strictEqual( Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==', 'base64'), 25 ); +// base64url assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ', 'base64url'), 11); assert.strictEqual(Buffer.byteLength('aGVsbG8gd29ybGQ', 'BASE64URL'), 11); assert.strictEqual(Buffer.byteLength('bm9kZS5qcyByb2NrcyE', 'base64url'), 14); @@ -128,7 +127,7 @@ assert.strictEqual(Buffer.byteLength('Il était tué', 'utf8'), 14); // TODO(Soremwar) // Enable once vm module is available -// // Test that ArrayBuffer from a different context is detected correctly +// Test that ArrayBuffer from a different context is detected correctly // const arrayBuf = vm.runInNewContext('new ArrayBuffer()'); // assert.strictEqual(Buffer.byteLength(arrayBuf), 0); diff --git a/cli/tests/node_compat/test/parallel/test-buffer-from.js b/cli/tests/node_compat/test/parallel/test-buffer-from.js index ef023cf0b..6483e2a63 100644 --- a/cli/tests/node_compat/test/parallel/test-buffer-from.js +++ b/cli/tests/node_compat/test/parallel/test-buffer-from.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 { deepStrictEqual, throws } = require('assert'); -const { runInNewContext } = require('vm'); +// const { runInNewContext } = require('vm'); const checkString = 'test'; @@ -36,7 +36,6 @@ class MyBadPrimitive { deepStrictEqual(Buffer.from(new String(checkString)), check); deepStrictEqual(Buffer.from(new MyString()), check); deepStrictEqual(Buffer.from(new MyPrimitive()), check); - // TODO(Soremwar) // Enable once again when vm works correctly // deepStrictEqual( @@ -66,7 +65,7 @@ deepStrictEqual(Buffer.from(new MyPrimitive()), check); 'Buffer, ArrayBuffer, or Array or an Array-like Object.' + common.invalidArgTypeHelper(input) }; - throws(() => Buffer.from(input), errObj); + throws(() => Buffer.from(input), errObj); throws(() => Buffer.from(input, 'hex'), errObj); }); diff --git a/cli/tests/node_compat/test/parallel/test-buffer-includes.js b/cli/tests/node_compat/test/parallel/test-buffer-includes.js index 66da7bfd3..797ec8246 100644 --- a/cli/tests/node_compat/test/parallel/test-buffer-includes.js +++ b/cli/tests/node_compat/test/parallel/test-buffer-includes.js @@ -2,8 +2,8 @@ // 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'); diff --git a/cli/tests/node_compat/test/parallel/test-buffer-indexof.js b/cli/tests/node_compat/test/parallel/test-buffer-indexof.js index e98e34349..802e0208b 100644 --- a/cli/tests/node_compat/test/parallel/test-buffer-indexof.js +++ b/cli/tests/node_compat/test/parallel/test-buffer-indexof.js @@ -2,8 +2,8 @@ // 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'); |