summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/node_compat/config.json5
-rw-r--r--cli/tests/node_compat/test/parallel/test-console-group.js2
-rw-r--r--cli/tests/node_compat/test/parallel/test-console-table.js2
-rw-r--r--cli/tests/node_compat/test/parallel/test-console-tty-colors.js102
-rw-r--r--cli/tests/node_compat/test/parallel/test-readline-position.js43
-rw-r--r--cli/tests/node_compat/test/parallel/test-stream2-readable-from-list.js108
-rw-r--r--cli/tests/node_compat/test/parallel/test-util-format.js35
-rw-r--r--cli/tests/node_compat/test/parallel/test-util-inspect.js83
-rw-r--r--cli/tests/unit_node/util_test.ts2
9 files changed, 268 insertions, 114 deletions
diff --git a/cli/tests/node_compat/config.json b/cli/tests/node_compat/config.json
index 43d9862b3..cdfbf4677 100644
--- a/cli/tests/node_compat/config.json
+++ b/cli/tests/node_compat/config.json
@@ -42,9 +42,7 @@
"test-child-process-stdio-inherit.js",
"test-child-process-stdout-flush-exit.js",
"test-child-process-stdout-flush.js",
- "test-console-group.js",
"test-console-instance.js",
- "test-console-table.js",
"test-crypto-hmac.js",
"test-dgram-custom-lookup.js",
"test-dgram-ipv6only.js",
@@ -229,6 +227,7 @@
"test-console-no-swallow-stack-overflow.js",
"test-console-sync-write-error.js",
"test-console-table.js",
+ "test-console-tty-colors.js",
"test-crypto-hmac.js",
"test-crypto-prime.js",
"test-dgram-close-during-bind.js",
@@ -423,6 +422,7 @@
"test-readline-emit-keypress-events.js",
"test-readline-interface-escapecodetimeout.js",
"test-readline-keys.js",
+ "test-readline-position.js",
"test-readline-reopen.js",
"test-readline-set-raw-mode.js",
"test-readline-undefined-columns.js",
@@ -556,6 +556,7 @@
"test-stream2-push.js",
"test-stream2-read-sync-stack.js",
"test-stream2-readable-empty-buffer-no-eof.js",
+ "test-stream2-readable-from-list.js",
"test-stream2-readable-legacy-drain.js",
"test-stream2-readable-non-empty-end.js",
"test-stream2-readable-wrap-destroy.js",
diff --git a/cli/tests/node_compat/test/parallel/test-console-group.js b/cli/tests/node_compat/test/parallel/test-console-group.js
index 6e49734eb..257317214 100644
--- a/cli/tests/node_compat/test/parallel/test-console-group.js
+++ b/cli/tests/node_compat/test/parallel/test-console-group.js
@@ -127,7 +127,6 @@ function teardown() {
}
// Check that multiline strings and object output are indented properly.
-/* TODO(kt3k): Enable this
{
setup();
const expectedOut = 'not indented\n' +
@@ -155,7 +154,6 @@ function teardown() {
assert.strictEqual(stderr, expectedErr);
teardown();
}
-*/
// Check that the kGroupIndent symbol property is not enumerable
{
diff --git a/cli/tests/node_compat/test/parallel/test-console-table.js b/cli/tests/node_compat/test/parallel/test-console-table.js
index 4e176e8cd..3aa34d7c1 100644
--- a/cli/tests/node_compat/test/parallel/test-console-table.js
+++ b/cli/tests/node_compat/test/parallel/test-console-table.js
@@ -175,7 +175,6 @@ test({ a: { a: 1, b: 2, c: 3 } }, `
└─────────┴───┴───┴───┘
`);
-/* TODO(kt3k): Enable this
test({ a: { a: { a: 1, b: 2, c: 3 } } }, `
┌─────────┬──────────┐
│ (index) │ a │
@@ -183,7 +182,6 @@ test({ a: { a: { a: 1, b: 2, c: 3 } } }, `
│ a │ [Object] │
└─────────┴──────────┘
`);
-*/
test({ a: [1, 2] }, `
┌─────────┬───┬───┐
diff --git a/cli/tests/node_compat/test/parallel/test-console-tty-colors.js b/cli/tests/node_compat/test/parallel/test-console-tty-colors.js
new file mode 100644
index 000000000..9676529ba
--- /dev/null
+++ b/cli/tests/node_compat/test/parallel/test-console-tty-colors.js
@@ -0,0 +1,102 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
+
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const util = require('util');
+const { Writable } = require('stream');
+const { Console } = require('console');
+
+function check(isTTY, colorMode, expectedColorMode, inspectOptions) {
+ const items = [
+ 1,
+ { a: 2 },
+ [ 'foo' ],
+ { '\\a': '\\bar' },
+ ];
+
+ let i = 0;
+ const stream = new Writable({
+ write: common.mustCall((chunk, enc, cb) => {
+ assert.strictEqual(chunk.trim(),
+ util.inspect(items[i++], {
+ colors: expectedColorMode,
+ ...inspectOptions
+ }));
+ cb();
+ }, items.length),
+ decodeStrings: false
+ });
+ stream.isTTY = isTTY;
+
+ // Set ignoreErrors to `false` here so that we see assertion failures
+ // from the `write()` call happen.
+ const testConsole = new Console({
+ stdout: stream,
+ ignoreErrors: false,
+ colorMode,
+ inspectOptions
+ });
+ for (const item of items) {
+ testConsole.log(item);
+ }
+}
+
+check(true, 'auto', true);
+check(false, 'auto', false);
+check(false, undefined, true, { colors: true, compact: false });
+check(true, 'auto', true, { compact: false });
+check(true, undefined, false, { colors: false });
+check(true, true, true);
+check(false, true, true);
+check(true, false, false);
+check(false, false, false);
+
+// Check invalid options.
+{
+ const stream = new Writable({
+ write: common.mustNotCall()
+ });
+
+ [0, 'true', null, {}, [], () => {}].forEach((colorMode) => {
+ const received = util.inspect(colorMode);
+ assert.throws(
+ () => {
+ new Console({
+ stdout: stream,
+ ignoreErrors: false,
+ colorMode: colorMode
+ });
+ },
+ {
+ message: `The argument 'colorMode' is invalid. Received ${received}`,
+ code: 'ERR_INVALID_ARG_VALUE'
+ }
+ );
+ });
+
+ [true, false, 'auto'].forEach((colorMode) => {
+ assert.throws(
+ () => {
+ new Console({
+ stdout: stream,
+ ignoreErrors: false,
+ colorMode: colorMode,
+ inspectOptions: {
+ colors: false
+ }
+ });
+ },
+ {
+ message: 'Option "options.inspectOptions.color" cannot be used in ' +
+ 'combination with option "colorMode"',
+ code: 'ERR_INCOMPATIBLE_OPTION_PAIR'
+ }
+ );
+ });
+}
diff --git a/cli/tests/node_compat/test/parallel/test-readline-position.js b/cli/tests/node_compat/test/parallel/test-readline-position.js
new file mode 100644
index 000000000..0ffdf4b18
--- /dev/null
+++ b/cli/tests/node_compat/test/parallel/test-readline-position.js
@@ -0,0 +1,43 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
+
+// Flags: --expose-internals
+'use strict';
+const common = require('../common');
+const { PassThrough } = require('stream');
+const readline = require('readline');
+const assert = require('assert');
+
+const ctrlU = { ctrl: true, name: 'u' };
+
+common.skipIfDumbTerminal();
+
+{
+ const input = new PassThrough();
+ const rl = readline.createInterface({
+ terminal: true,
+ input: input,
+ prompt: ''
+ });
+
+ const tests = [
+ [1, 'a'],
+ [2, 'ab'],
+ [2, '丁'],
+ [0, '\u0301'], // COMBINING ACUTE ACCENT
+ [1, 'a\u0301'], // á
+ [0, '\u20DD'], // COMBINING ENCLOSING CIRCLE
+ [2, 'a\u20DDb'], // a⃝b
+ [0, '\u200E'], // LEFT-TO-RIGHT MARK
+ ];
+
+ for (const [cursor, string] of tests) {
+ rl.write(string);
+ assert.strictEqual(rl.getCursorPos().cols, cursor);
+ rl.write(null, ctrlU);
+ }
+}
diff --git a/cli/tests/node_compat/test/parallel/test-stream2-readable-from-list.js b/cli/tests/node_compat/test/parallel/test-stream2-readable-from-list.js
new file mode 100644
index 000000000..72c3b15aa
--- /dev/null
+++ b/cli/tests/node_compat/test/parallel/test-stream2-readable-from-list.js
@@ -0,0 +1,108 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
+
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// Flags: --expose-internals
+'use strict';
+require('../common');
+const assert = require('assert');
+const fromList = require('stream').Readable._fromList;
+const BufferList = require('internal/streams/buffer_list');
+const util = require('util');
+
+function bufferListFromArray(arr) {
+ const bl = new BufferList();
+ for (let i = 0; i < arr.length; ++i)
+ bl.push(arr[i]);
+ return bl;
+}
+
+{
+ // Verify behavior with buffers
+ let list = [ Buffer.from('foog'),
+ Buffer.from('bark'),
+ Buffer.from('bazy'),
+ Buffer.from('kuel') ];
+ list = bufferListFromArray(list);
+
+ assert.strictEqual(
+ util.inspect([ list ], { compact: false }),
+ `[
+ BufferList {
+ head: [Object],
+ tail: [Object],
+ length: 4
+ }
+]`);
+
+ // Read more than the first element.
+ let ret = fromList(6, { buffer: list, length: 16 });
+ assert.strictEqual(ret.toString(), 'foogba');
+
+ // Read exactly the first element.
+ ret = fromList(2, { buffer: list, length: 10 });
+ assert.strictEqual(ret.toString(), 'rk');
+
+ // Read less than the first element.
+ ret = fromList(2, { buffer: list, length: 8 });
+ assert.strictEqual(ret.toString(), 'ba');
+
+ // Read more than we have.
+ ret = fromList(100, { buffer: list, length: 6 });
+ assert.strictEqual(ret.toString(), 'zykuel');
+
+ // all consumed.
+ assert.deepStrictEqual(list, new BufferList());
+}
+
+{
+ // Verify behavior with strings
+ let list = [ 'foog',
+ 'bark',
+ 'bazy',
+ 'kuel' ];
+ list = bufferListFromArray(list);
+
+ // Read more than the first element.
+ let ret = fromList(6, { buffer: list, length: 16, decoder: true });
+ assert.strictEqual(ret, 'foogba');
+
+ // Read exactly the first element.
+ ret = fromList(2, { buffer: list, length: 10, decoder: true });
+ assert.strictEqual(ret, 'rk');
+
+ // Read less than the first element.
+ ret = fromList(2, { buffer: list, length: 8, decoder: true });
+ assert.strictEqual(ret, 'ba');
+
+ // Read more than we have.
+ ret = fromList(100, { buffer: list, length: 6, decoder: true });
+ assert.strictEqual(ret, 'zykuel');
+
+ // all consumed.
+ assert.deepStrictEqual(list, new BufferList());
+}
diff --git a/cli/tests/node_compat/test/parallel/test-util-format.js b/cli/tests/node_compat/test/parallel/test-util-format.js
index 3fd24863f..9d474c481 100644
--- a/cli/tests/node_compat/test/parallel/test-util-format.js
+++ b/cli/tests/node_compat/test/parallel/test-util-format.js
@@ -50,13 +50,11 @@ assert.strictEqual(util.format('foo', 'bar', 'baz'), 'foo bar baz');
assert.strictEqual(util.format(symbol), 'Symbol(foo)');
assert.strictEqual(util.format('foo', symbol), 'foo Symbol(foo)');
assert.strictEqual(util.format('%s', symbol), 'Symbol(foo)');
-// TODO(kt3k): Enable this
-// assert.strictEqual(util.format('%j', symbol), 'undefined');
+assert.strictEqual(util.format('%j', symbol), 'undefined');
// Number format specifier
assert.strictEqual(util.format('%d'), '%d');
assert.strictEqual(util.format('%d', 42.0), '42');
-/* TODO(kt3k): Enable this
assert.strictEqual(util.format('%d', 42), '42');
assert.strictEqual(util.format('%d', '42'), '42');
assert.strictEqual(util.format('%d', '42.0'), '42');
@@ -137,7 +135,6 @@ assert.strictEqual(util.format('%f', Infinity), 'Infinity');
assert.strictEqual(util.format('%f', -Infinity), '-Infinity');
assert.strictEqual(util.format('%f %f', 42, 43), '42 43');
assert.strictEqual(util.format('%f %f', 42), '42 %f');
-*/
// String format specifier
assert.strictEqual(util.format('%s'), '%s');
@@ -146,16 +143,16 @@ assert.strictEqual(util.format('%s', null), 'null');
assert.strictEqual(util.format('%s', 'foo'), 'foo');
assert.strictEqual(util.format('%s', 42), '42');
assert.strictEqual(util.format('%s', '42'), '42');
-// assert.strictEqual(util.format('%s', -0), '-0');
+assert.strictEqual(util.format('%s', -0), '-0');
assert.strictEqual(util.format('%s', '-0.0'), '-0.0');
assert.strictEqual(util.format('%s %s', 42, 43), '42 43');
assert.strictEqual(util.format('%s %s', 42), '42 %s');
-// assert.strictEqual(util.format('%s', 42n), '42n');
+assert.strictEqual(util.format('%s', 42n), '42n');
assert.strictEqual(util.format('%s', Symbol('foo')), 'Symbol(foo)');
assert.strictEqual(util.format('%s', true), 'true');
-// assert.strictEqual(util.format('%s', { a: [1, 2, 3] }), '{ a: [Array] }');
+assert.strictEqual(util.format('%s', { a: [1, 2, 3] }), '{ a: [Array] }');
assert.strictEqual(util.format('%s', { toString() { return 'Foo'; } }), 'Foo');
-// assert.strictEqual(util.format('%s', { toString: 5 }), '{ toString: 5 }');
+assert.strictEqual(util.format('%s', { toString: 5 }), '{ toString: 5 }');
assert.strictEqual(util.format('%s', () => 5), '() => 5');
assert.strictEqual(util.format('%s', Infinity), 'Infinity');
assert.strictEqual(util.format('%s', -Infinity), '-Infinity');
@@ -243,10 +240,10 @@ assert.strictEqual(util.format('%s', -Infinity), '-Infinity');
// JSON format specifier
assert.strictEqual(util.format('%j'), '%j');
-// assert.strictEqual(util.format('%j', 42), '42');
-// assert.strictEqual(util.format('%j', '42'), '"42"');
-// assert.strictEqual(util.format('%j %j', 42, 43), '42 43');
-// assert.strictEqual(util.format('%j %j', 42), '42 %j');
+assert.strictEqual(util.format('%j', 42), '42');
+assert.strictEqual(util.format('%j', '42'), '"42"');
+assert.strictEqual(util.format('%j %j', 42, 43), '42 43');
+assert.strictEqual(util.format('%j %j', 42), '42 %j');
// Object format specifier
const obj = {
@@ -268,8 +265,7 @@ const nestedObj2 = {
};
assert.strictEqual(util.format('%o'), '%o');
assert.strictEqual(util.format('%o', 42), '42');
-// assert.strictEqual(util.format('%o', 'foo'), '\'foo\'');
-/*
+assert.strictEqual(util.format('%o', 'foo'), '\'foo\'');
assert.strictEqual(
util.format('%o', obj),
'{\n' +
@@ -340,11 +336,9 @@ assert.strictEqual(
' [prototype]: { [constructor]: [Circular *1] }\n' +
' }\n' +
'} %o');
-*/
assert.strictEqual(util.format('%O'), '%O');
assert.strictEqual(util.format('%O', 42), '42');
-/* TODO(kt3k): Enable this
assert.strictEqual(util.format('%O', 'foo'), '\'foo\'');
assert.strictEqual(
util.format('%O', obj),
@@ -359,7 +353,6 @@ assert.strictEqual(
assert.strictEqual(
util.format('%O %O', obj),
'{ foo: \'bar\', foobar: 1, func: [Function: func] } %O');
-*/
// Various format specifiers
assert.strictEqual(util.format('%%s%s', 'foo'), '%sfoo');
@@ -382,7 +375,6 @@ assert.strictEqual(util.format('%i:%i'), '%i:%i');
assert.strictEqual(util.format('%f:%f', 12, 30), '12:30');
assert.strictEqual(util.format('%f:%f', 12), '12:%f');
assert.strictEqual(util.format('%f:%f'), '%f:%f');
-/* TODO(kt3k): Enable this
assert.strictEqual(util.format('o: %j, a: %j', {}, []), 'o: {}, a: []');
assert.strictEqual(util.format('o: %j, a: %j', {}), 'o: {}, a: %j');
assert.strictEqual(util.format('o: %j, a: %j'), 'o: %j, a: %j');
@@ -396,7 +388,6 @@ assert.strictEqual(util.format('a% b', 'x'), 'a% b x');
assert.strictEqual(util.format('percent: %d%, fraction: %d', 10, 0.1),
'percent: 10%, fraction: 0.1');
assert.strictEqual(util.format('abc%', 1), 'abc% 1');
-*/
// Additional arguments after format specifiers
assert.strictEqual(util.format('%i', 1, 'number'), '1 number');
@@ -408,7 +399,6 @@ assert.strictEqual(util.format('%cab'), '%cab');
assert.strictEqual(util.format('%cab', 'color: blue'), 'ab');
assert.strictEqual(util.format('%cab', 'color: blue', 'c'), 'ab c');
-/* TODO(kt3k): Enable this
{
const o = {};
o.o = o;
@@ -424,7 +414,6 @@ assert.strictEqual(util.format('%cab', 'color: blue', 'c'), 'ab c');
assert.throws(() => util.format('%j', o),
/^Error: Not a circular object but still not serializable$/);
}
-*/
// Errors
const err = new Error('foo');
@@ -442,7 +431,6 @@ class CustomError extends Error {
const customError = new CustomError('bar');
assert.strictEqual(util.format(customError), customError.stack);
// Doesn't capture stack trace
-/* TODO(kt3k): Enable this
function BadCustomError(msg) {
Error.call(this);
Object.defineProperty(this, 'message',
@@ -454,7 +442,6 @@ Object.setPrototypeOf(BadCustomError.prototype, Error.prototype);
Object.setPrototypeOf(BadCustomError, Error);
assert.strictEqual(util.format(new BadCustomError('foo')),
'[BadCustomError: foo]');
-*/
// The format of arguments should not depend on type of the first argument
assert.strictEqual(util.format('1', '1'), '1 1');
@@ -491,7 +478,6 @@ assert.strictEqual(
// 'SharedArrayBuffer { [Uint8Contents]: <00 00 00 00>, byteLength: 4 }'
// );
-/* TODO(kt3k): Enable this
assert.strictEqual(
util.formatWithOptions(
{ colors: true, compact: 3 },
@@ -499,7 +485,6 @@ assert.strictEqual(
),
'[ 1, [Object] ]'
);
-*/
[
undefined,
diff --git a/cli/tests/node_compat/test/parallel/test-util-inspect.js b/cli/tests/node_compat/test/parallel/test-util-inspect.js
index f5382844a..fd3243ec5 100644
--- a/cli/tests/node_compat/test/parallel/test-util-inspect.js
+++ b/cli/tests/node_compat/test/parallel/test-util-inspect.js
@@ -110,13 +110,11 @@ assert.strictEqual(
);
assert.strictEqual(util.inspect(new Date('')), (new Date('')).toString());
assert.strictEqual(util.inspect('\n\x01'), "'\\n\\x01'");
-/* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(`${Array(75).fill(1)}'\n\x1d\n\x03\x85\x7f\x7e\x9f\xa0`),
// eslint-disable-next-line no-irregular-whitespace
`"${Array(75).fill(1)}'\\n" +\n '\\x1D\\n' +\n '\\x03\\x85\\x7F~\\x9F '`
);
-*/
assert.strictEqual(util.inspect([]), '[]');
assert.strictEqual(util.inspect(Object.create([])), 'Array {}');
assert.strictEqual(util.inspect([1, 2]), '[ 1, 2 ]');
@@ -137,21 +135,17 @@ assert.strictEqual(util.inspect({ 'a': {} }), '{ a: {} }');
assert.strictEqual(util.inspect({ 'a': { 'b': 2 } }), '{ a: { b: 2 } }');
assert.strictEqual(util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }),
'{ a: { b: { c: [Object] } } }');
-/* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }, false, null),
'{\n a: { b: { c: { d: 2 } } }\n}');
-*/
// TODO(wafuwafu13): Fix
// assert.strictEqual(util.inspect([1, 2, 3], true), '[ 1, 2, 3, [length]: 3 ]');
-/* TODO(kt3k): Enable this
assert.strictEqual(util.inspect({ 'a': { 'b': { 'c': 2 } } }, false, 0),
'{ a: [Object] }');
assert.strictEqual(util.inspect({ 'a': { 'b': { 'c': 2 } } }, false, 1),
'{ a: { b: [Object] } }');
assert.strictEqual(util.inspect({ 'a': { 'b': ['c'] } }, false, 1),
'{ a: { b: [Array] } }');
-*/
// TODO(wafuwafu13): Fix
// assert.strictEqual(util.inspect(new Uint8Array(0)), 'Uint8Array(0) []');
// assert(inspect(new Uint8Array(0), { showHidden: true }).includes('[buffer]'));
@@ -187,12 +181,10 @@ assert.match(
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, undefined, true),
/Object/
);
-/* TODO(kt3k): Enable this
assert.doesNotMatch(
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true),
/Object/
);
-*/
// TODO(wafuwafu13): Fix
// {
@@ -368,7 +360,6 @@ assert.doesNotMatch(
// assert.strictEqual(inspect(brokenLength), 'Float32Array(2) [ 0n, 0n ]');
// }
-/* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(Object.create({}, {
visible: { value: 1, enumerable: true },
@@ -392,7 +383,6 @@ assert.strictEqual(
})),
"[Object: null prototype] { name: 'Tim' }"
);
-*/
// Dynamic properties.
{
@@ -404,12 +394,10 @@ assert.strictEqual(
util.inspect({ get readwrite() { return 1; }, set readwrite(val) {} }),
'{ readwrite: [Getter/Setter] }');
- /* TODO(kt3k): Enable this
assert.strictEqual(
// eslint-disable-next-line accessor-pairs
util.inspect({ set writeonly(val) {} }),
'{ writeonly: [Setter] }');
- */
const value = {};
value.a = value;
@@ -419,12 +407,10 @@ assert.strictEqual(
return null;
}
};
- /* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(getterFn, { getters: true }),
'{ one: [Getter: null] }'
);
- */
}
// TODO(wafuwafu13): Fix
@@ -459,12 +445,10 @@ assert.strictEqual(
CustomArray.prototype.foo = true;
const arr = new CustomArray(50);
arr[49] = 'I win';
- /* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(arr),
"CustomArray(50) [ <49 empty items>, 'I win' ]"
);
- */
// TODO(wafuwafu13): Fix
// assert.strictEqual(
// util.inspect(arr, { showHidden: true }),
@@ -570,19 +554,15 @@ assert.strictEqual(
{
const value = /123/ig;
value.aprop = 42;
- /* TODO(kt3k): Enable this
assert.strictEqual(util.inspect(value), '/123/gi { aprop: 42 }');
- */
}
// Dates with properties.
{
const value = new Date('Sun, 14 Feb 2010 11:48:40 GMT');
value.aprop = 42;
- /* TODO(kt3k): Enable this
assert.strictEqual(util.inspect(value),
'2010-02-14T11:48:40.000Z { aprop: 42 }');
- */
}
// TODO(wafuwafu13): Implement 'vm'
@@ -621,7 +601,6 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
"[ 'foo', <1 empty item>, 'baz', 'bar', <96 empty items>, 'qux' ]"
);
delete a[3];
- /* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(a, { maxArrayLength: 4 }),
"[ 'foo', <1 empty item>, 'baz', <97 empty items>, ... 1 more item ]"
@@ -630,7 +609,6 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
assert.strictEqual(util.inspect(a, {
maxArrayLength: 2
}), "[ 'foo', <1 empty item>, ... 99 more items ]");
- */
}
// TODO(wafuwafu13): Implement `previewEntries`
@@ -680,7 +658,6 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
set: function() {}
}
});
- /* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(getter, true),
'[Object: null prototype] { [a]: [Getter] }'
@@ -693,7 +670,6 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
util.inspect(getterAndSetter, true),
'[Object: null prototype] { [c]: [Getter/Setter] }'
);
- */
}
// Exceptions should print the error message, not '{}'.
@@ -716,10 +692,8 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
const ex = util.inspect(new Error('FAIL'), true);
assert(ex.includes('Error: FAIL'));
- /* TODO(kt3k): Enable this
assert(ex.includes('[stack]'));
assert(ex.includes('[message]'));
- */
}
{
@@ -727,9 +701,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
Error.stackTraceLimit = 0;
const err = new Error('foo');
const err2 = new Error('foo\nbar');
- /* TODO(kt3k): Enable this
assert.strictEqual(util.inspect(err, { compact: true }), '[Error: foo]');
- */
assert(err.stack);
delete err.stack;
assert(!err.stack);
@@ -809,12 +781,10 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
}
Object.setPrototypeOf(BadCustomError.prototype, Error.prototype);
Object.setPrototypeOf(BadCustomError, Error);
- /* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(new BadCustomError('foo')),
'[BadCustomError: foo]'
);
- */
}
// TODO(wafuwafu13): Fix
@@ -848,9 +818,7 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
// });
// https://github.com/nodejs/node-v0.x-archive/issues/1941
-/* TODO(kt3k): Enable this
assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}');
-*/
// https://github.com/nodejs/node-v0.x-archive/issues/1944
{
@@ -913,7 +881,6 @@ assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}');
// }
// Test util.inspect.styles and util.inspect.colors.
-/* TODO(kt3k): Enable this
{
function testColorStyle(style, input, implicit) {
const colorName = util.inspect.styles[style];
@@ -939,7 +906,6 @@ assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}');
testColorStyle('date', new Date());
testColorStyle('regexp', /regexp/);
}
-*/
// An object with "hasOwnProperty" overwritten should not throw.
util.inspect({ hasOwnProperty: null });
@@ -953,12 +919,10 @@ util.inspect({ hasOwnProperty: null });
util.inspect(subject, { showHidden: false }).includes('hidden'),
false
);
- /* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(subject, { showHidden: true }).includes('hidden'),
true
);
- */
assert.strictEqual(
util.inspect(subject, { colors: false }).includes('\u001b[32m'),
false
@@ -971,7 +935,6 @@ util.inspect({ hasOwnProperty: null });
util.inspect(subject, { depth: 2 }).includes('c: [Object]'),
true
);
- /* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(subject, { depth: 0 }).includes('a: [Object]'),
true
@@ -984,14 +947,12 @@ util.inspect({ hasOwnProperty: null });
util.inspect(subject, { depth: undefined }).includes('{ d: 0 }'),
true
);
- */
}
{
// "customInspect" option can enable/disable calling [util.inspect.custom]().
const subject = { [util.inspect.custom]: () => 123 };
- /* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect(subject, { customInspect: true }).includes('123'),
true
@@ -1004,7 +965,6 @@ util.inspect({ hasOwnProperty: null });
util.inspect(subject, { customInspect: false }).includes('123'),
false
);
- */
// TODO(wafuwafu13): Fix
// assert.strictEqual(
// util.inspect(subject, { customInspect: false }).includes('inspect'),
@@ -1014,7 +974,6 @@ util.inspect({ hasOwnProperty: null });
// A custom [util.inspect.custom]() should be able to return other Objects.
subject[util.inspect.custom] = () => ({ foo: 'bar' });
- /* TODO(kt3k): Enable this
assert.strictEqual(util.inspect(subject), "{ foo: 'bar' }");
subject[util.inspect.custom] = common.mustCall((depth, opts) => {
@@ -1038,7 +997,6 @@ util.inspect({ hasOwnProperty: null });
});
util.inspect(subject);
- */
// util.inspect.custom is a shared symbol which can be accessed as
// Symbol.for("nodejs.util.inspect.custom").
@@ -1046,9 +1004,7 @@ util.inspect({ hasOwnProperty: null });
subject[inspect] = () => ({ baz: 'quux' });
- /* TODO(kt3k): Enable this
assert.strictEqual(util.inspect(subject), '{ baz: \'quux\' }');
- */
subject[inspect] = (depth, opts) => {
assert.strictEqual(opts.customInspectOptions, true);
@@ -1059,7 +1015,6 @@ util.inspect({ hasOwnProperty: null });
util.inspect(subject, { customInspectOptions: true, seen: null });
}
-/* TODO(kt3k): Enable this
{
const subject = { [util.inspect.custom]: common.mustCall((depth, opts) => {
assert.strictEqual(depth, null);
@@ -1067,7 +1022,6 @@ util.inspect({ hasOwnProperty: null });
}) };
util.inspect(subject, { depth: null, compact: true });
}
-*/
// TODO(wafuwafu13): Fix
// {
@@ -1081,12 +1035,10 @@ util.inspect({ hasOwnProperty: null });
// }
// Verify that it's possible to use the stylize function to manipulate input.
-/* TODO(kt3k): Enable this
assert.strictEqual(
util.inspect([1, 2, 3], { stylize() { return 'x'; } }),
'[ x, x, x ]'
);
-*/
// Using `util.inspect` with "colors" option should produce as many lines as
// without it.
@@ -1114,13 +1066,11 @@ assert.strictEqual(
}
// Test boxed primitives output the correct values.
-/* TODO(kt3k): Enable this
assert.strictEqual(util.inspect(new String('test')), "[String: 'test']");
assert.strictEqual(
util.inspect(new String('test'), { colors: true }),
"\u001b[32m[String: 'test']\u001b[39m"
);
-*/
assert.strictEqual(
util.inspect(Object(Symbol('test'))),
'[Symbol: Symbol(test)]'
@@ -1146,7 +1096,6 @@ assert.strictEqual(util.inspect(new Number(-1.1)), '[Number: -1.1]');
assert.strictEqual(util.inspect(new Number(13.37)), '[Number: 13.37]');
// Test boxed primitives with own properties.
-/* TODO(kt3k): Enable this
{
const str = new String('baz');
str.foo = 'bar';
@@ -1275,7 +1224,6 @@ if (typeof Symbol !== 'undefined') {
'}'
);
}
-*/
// TODO(wafuwafu13): Fix
// // Test Promise.
@@ -1357,7 +1305,6 @@ if (typeof Symbol !== 'undefined') {
// Minimal inspection should still return as much information as possible about
// the constructor and Symbol.toStringTag.
-/* TODO(kt3k): Enable this
{
class Foo {
get [Symbol.toStringTag]() {
@@ -1502,19 +1449,16 @@ if (typeof Symbol !== 'undefined') {
});
assert.strictEqual(util.inspect(x), '{ constructor: [Getter] }');
}
-*/
{
const x = new function() {}; // eslint-disable-line new-parens
assert.strictEqual(util.inspect(x), '{}');
}
-/* TODO(kt3k): Enable this
{
const x = Object.create(null);
assert.strictEqual(util.inspect(x), '[Object: null prototype] {}');
}
-*/
// TODO(wafuwafu13): Fix
// {
@@ -1539,7 +1483,6 @@ if (typeof Symbol !== 'undefined') {
// '[ ... 101 more items ]');
// }
-/* TODO(kt3k): Enable this
{
const x = Array(101);
assert.strictEqual(util.inspect(x, { maxArrayLength: 0 }),
@@ -1633,7 +1576,6 @@ if (typeof Symbol !== 'undefined') {
}
);
}
-*/
util.inspect(process);
@@ -1647,7 +1589,6 @@ util.inspect(process);
// );
// }
-/* TODO(kt3k): Enable this
{
// @@toStringTag
const obj = { [Symbol.toStringTag]: 'a' };
@@ -1822,7 +1763,6 @@ util.inspect(process);
expect = "{\n a: '12 45 78 01 34 67 90 23'\n}";
assert.strictEqual(out, expect);
}
-*/
// TODO(wafuwafu13): Fix
// // Check compact indentation.
@@ -2022,7 +1962,6 @@ util.inspect(process);
// assert(obj && arr);
// }
-/* TODO(kt3k): Enable this
{ // Test argument objects.
const args = (function() { return arguments; })('a');
assert.strictEqual(util.inspect(args), "[Arguments] { '0': 'a' }");
@@ -2047,15 +1986,12 @@ util.inspect(process);
// assert(longList.includes('[Object: Inspection interrupted ' +
// 'prematurely. Maximum call stack size exceeded.]'));
}
-*/
// Do not escape single quotes if no double quote or backtick is present.
assert.strictEqual(util.inspect("'"), '"\'"');
assert.strictEqual(util.inspect('"\''), '`"\'`');
// eslint-disable-next-line no-template-curly-in-string
-/* TODO(kt3k): Enable this
assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
-*/
// TODO(wafuwafu13): Fix
// // Errors should visualize as much information as possible.
@@ -2179,7 +2115,6 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
// });
// "class" properties should not be detected as "class".
-/* TODO(kt3k): Enable this
{
// eslint-disable-next-line space-before-function-paren
let obj = { class () {} };
@@ -2210,7 +2145,6 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
'[Function: class Foo {}]'
);
}
-*/
// TODO(wafuwafu13): Fix
// // Verify that throwing in valueOf and toString still produces nice results.
@@ -2344,7 +2278,6 @@ assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]');
// inspect(new BigUint64Array([0n])), 'BigUint64Array(1) [ 0n ]');
// Verify non-enumerable keys get escaped.
-/* TODO(kt3k): Enable this
{
const obj = {};
Object.defineProperty(obj, 'Non\nenumerable\tkey', { value: true });
@@ -2415,7 +2348,6 @@ assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]');
assert.strictEqual(inspect('foobar', { colors: true }), "'foobar'");
inspect.styles.string = stringStyle;
}
-*/
assert.strictEqual(
inspect([1, 3, 2], { sorted: true }),
@@ -2425,7 +2357,6 @@ assert.strictEqual(
inspect({ c: 3, a: 1, b: 2 }, { sorted: true }),
'{ a: 1, b: 2, c: 3 }'
);
-/* TODO(kt3k): Enable this
assert.strictEqual(
inspect(
{ a200: 4, a100: 1, a102: 3, a101: 2 },
@@ -2433,7 +2364,6 @@ assert.strictEqual(
),
'{ a200: 4, a102: 3, a101: 2, a100: 1 }'
);
-*/
// TODO(wafuwafu13): Fix
// // Non-indices array properties are sorted as well.
@@ -2535,8 +2465,8 @@ assert.strictEqual(
// );
// }
+// TODO(wafuwafu13): Fix
// Check the getter option.
-/* TODO(kt3k): Enable this
{
let foo = 1;
const get = { get foo() { return foo; } };
@@ -2568,7 +2498,6 @@ assert.strictEqual(
// '{\n foo: [Getter/Setter] Set(3) { [ [Object], 2, {} ], ' +
// "'foobar', { x: 1 } },\n inc: [Getter: NaN]\n}");
}
-*/
// Check compact number mode.
{
@@ -2981,12 +2910,10 @@ assert.strictEqual(
const bar = new Bar();
- /* TODO(kt3k): Enable this
assert.strictEqual(
inspect(bar),
'Bar(0) [Map] { prop: true, prop2: true, abc: true }'
);
- */
// TODO(wafuwafu13): Fix
// assert.strictEqual(
// inspect(bar, { showHidden: true, getters: true, colors: false }),
@@ -3050,7 +2977,6 @@ assert.strictEqual(
// Check that prototypes with a null prototype are inspectable.
// Regression test for https://github.com/nodejs/node/issues/35730
-/* TODO(kt3k): Enable this
{
function Func() {}
Func.prototype = null;
@@ -3059,7 +2985,6 @@ assert.strictEqual(
assert.strictEqual(util.inspect(object), '{ constructor: [Function: Func] }');
}
-*/
// Test changing util.inspect.colors colors and aliases.
{
@@ -3096,7 +3021,6 @@ assert.strictEqual(
// }
// Truncate output for Primitives with 1 character left
-/* TODO(kt3k): Enable this
{
assert.strictEqual(util.inspect('bl', { maxStringLength: 1 }),
"'b'... 1 more character");
@@ -3111,7 +3035,6 @@ assert.strictEqual(
);
assert.match(util.inspect(x, { maxStringLength: null }), /a'$/);
}
-*/
// TODO(wafuwafu13): Implement 'vm'
// {
@@ -3197,7 +3120,6 @@ assert.strictEqual(
// assert(fullObjectGraph(global).has(Function.prototype));
// }
-/* TODO(kt3k): Enable this
{
// Confirm that own constructor value displays correctly.
@@ -3217,7 +3139,6 @@ assert.strictEqual(
'}'
);
}
-*/
// TODO(wafuwafu13): Fix TypeError: main.hasOwnProperty is not a function
// {
@@ -3271,11 +3192,9 @@ assert.strictEqual(
);
}
-/* TODO(kt3k): Enable this
{
assert.strictEqual(
util.inspect({ ['__proto__']: { a: 1 } }),
"{ ['__proto__']: { a: 1 } }"
);
}
-*/
diff --git a/cli/tests/unit_node/util_test.ts b/cli/tests/unit_node/util_test.ts
index 44b20299e..81794c856 100644
--- a/cli/tests/unit_node/util_test.ts
+++ b/cli/tests/unit_node/util_test.ts
@@ -12,7 +12,7 @@ import * as util from "node:util";
Deno.test({
name: "[util] format",
fn() {
- assertEquals(util.format("%o", [10, 11]), "[ 10, 11 ]");
+ assertEquals(util.format("%o", [10, 11]), "[ 10, 11, [length]: 2 ]");
},
});