2023-02-20 10:35:04 -05:00
|
|
|
// deno-fmt-ignore-file
|
|
|
|
// deno-lint-ignore-file
|
|
|
|
|
|
|
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
|
|
// Taken from Node 18.12.1
|
2024-04-02 18:24:55 -04:00
|
|
|
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
|
2023-02-20 10:35:04 -05:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('../common');
|
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const { Console } = require('console');
|
|
|
|
|
|
|
|
const queue = [];
|
|
|
|
|
|
|
|
const console = new Console({ write: (x) => {
|
|
|
|
queue.push(x);
|
|
|
|
}, removeListener: () => {} }, process.stderr, false);
|
|
|
|
|
|
|
|
function test(data, only, expected) {
|
|
|
|
if (arguments.length === 2) {
|
|
|
|
expected = only;
|
|
|
|
only = undefined;
|
|
|
|
}
|
|
|
|
console.table(data, only);
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
queue.shift().split('\n'),
|
|
|
|
expected.trimLeft().split('\n')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.throws(() => console.table([], false), {
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
});
|
|
|
|
|
|
|
|
test(null, 'null\n');
|
|
|
|
test(undefined, 'undefined\n');
|
|
|
|
test(false, 'false\n');
|
|
|
|
test('hi', 'hi\n');
|
|
|
|
test(Symbol(), 'Symbol()\n');
|
|
|
|
test(function() {}, '[Function (anonymous)]\n');
|
|
|
|
|
|
|
|
test([1, 2, 3], `
|
|
|
|
┌─────────┬────────┐
|
|
|
|
│ (index) │ Values │
|
|
|
|
├─────────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │
|
|
|
|
│ 1 │ 2 │
|
|
|
|
│ 2 │ 3 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test([Symbol(), 5, [10]], `
|
|
|
|
┌─────────┬────┬──────────┐
|
2024-06-11 07:41:44 -04:00
|
|
|
│ (index) │ 0 │ Values │
|
2023-02-20 10:35:04 -05:00
|
|
|
├─────────┼────┼──────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ │ Symbol() │
|
|
|
|
│ 1 │ │ 5 │
|
|
|
|
│ 2 │ 10 │ │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴────┴──────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test([null, 5], `
|
|
|
|
┌─────────┬────────┐
|
|
|
|
│ (index) │ Values │
|
|
|
|
├─────────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ null │
|
|
|
|
│ 1 │ 5 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test([undefined, 5], `
|
|
|
|
┌─────────┬───────────┐
|
2024-06-11 07:41:44 -04:00
|
|
|
│ (index) │ Values │
|
2023-02-20 10:35:04 -05:00
|
|
|
├─────────┼───────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ undefined │
|
|
|
|
│ 1 │ 5 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴───────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test({ a: 1, b: Symbol(), c: [10] }, `
|
|
|
|
┌─────────┬────┬──────────┐
|
2024-06-11 07:41:44 -04:00
|
|
|
│ (index) │ 0 │ Values │
|
2023-02-20 10:35:04 -05:00
|
|
|
├─────────┼────┼──────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ a │ │ 1 │
|
|
|
|
│ b │ │ Symbol() │
|
|
|
|
│ c │ 10 │ │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴────┴──────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test(new Map([ ['a', 1], [Symbol(), [2]] ]), `
|
|
|
|
┌───────────────────┬──────────┬────────┐
|
2024-06-11 07:41:44 -04:00
|
|
|
│ (iteration index) │ Key │ Values │
|
2023-02-20 10:35:04 -05:00
|
|
|
├───────────────────┼──────────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 'a' │ 1 │
|
|
|
|
│ 1 │ Symbol() │ [ 2 ] │
|
2023-02-20 10:35:04 -05:00
|
|
|
└───────────────────┴──────────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test(new Set([1, 2, Symbol()]), `
|
|
|
|
┌───────────────────┬──────────┐
|
2024-06-11 07:41:44 -04:00
|
|
|
│ (iteration index) │ Values │
|
2023-02-20 10:35:04 -05:00
|
|
|
├───────────────────┼──────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │
|
|
|
|
│ 1 │ 2 │
|
|
|
|
│ 2 │ Symbol() │
|
2023-02-20 10:35:04 -05:00
|
|
|
└───────────────────┴──────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test({ a: 1, b: 2 }, ['a'], `
|
|
|
|
┌─────────┬───┐
|
|
|
|
│ (index) │ a │
|
|
|
|
├─────────┼───┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ a │ │
|
|
|
|
│ b │ │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴───┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test([{ a: 1, b: 2 }, { a: 3, c: 4 }], ['a'], `
|
|
|
|
┌─────────┬───┐
|
|
|
|
│ (index) │ a │
|
|
|
|
├─────────┼───┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │
|
|
|
|
│ 1 │ 3 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴───┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test(new Map([[1, 1], [2, 2], [3, 3]]).entries(), `
|
|
|
|
┌───────────────────┬─────┬────────┐
|
|
|
|
│ (iteration index) │ Key │ Values │
|
|
|
|
├───────────────────┼─────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │ 1 │
|
|
|
|
│ 1 │ 2 │ 2 │
|
|
|
|
│ 2 │ 3 │ 3 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└───────────────────┴─────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test(new Map([[1, 1], [2, 2], [3, 3]]).values(), `
|
|
|
|
┌───────────────────┬────────┐
|
|
|
|
│ (iteration index) │ Values │
|
|
|
|
├───────────────────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │
|
|
|
|
│ 1 │ 2 │
|
|
|
|
│ 2 │ 3 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└───────────────────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test(new Map([[1, 1], [2, 2], [3, 3]]).keys(), `
|
|
|
|
┌───────────────────┬────────┐
|
|
|
|
│ (iteration index) │ Values │
|
|
|
|
├───────────────────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │
|
|
|
|
│ 1 │ 2 │
|
|
|
|
│ 2 │ 3 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└───────────────────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test(new Set([1, 2, 3]).values(), `
|
|
|
|
┌───────────────────┬────────┐
|
|
|
|
│ (iteration index) │ Values │
|
|
|
|
├───────────────────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │
|
|
|
|
│ 1 │ 2 │
|
|
|
|
│ 2 │ 3 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└───────────────────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
test({ a: { a: 1, b: 2, c: 3 } }, `
|
|
|
|
┌─────────┬───┬───┬───┐
|
|
|
|
│ (index) │ a │ b │ c │
|
|
|
|
├─────────┼───┼───┼───┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ a │ 1 │ 2 │ 3 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴───┴───┴───┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test({ a: { a: { a: 1, b: 2, c: 3 } } }, `
|
|
|
|
┌─────────┬──────────┐
|
2024-06-11 07:41:44 -04:00
|
|
|
│ (index) │ a │
|
2023-02-20 10:35:04 -05:00
|
|
|
├─────────┼──────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ a │ [Object] │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴──────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test({ a: [1, 2] }, `
|
|
|
|
┌─────────┬───┬───┐
|
|
|
|
│ (index) │ 0 │ 1 │
|
|
|
|
├─────────┼───┼───┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ a │ 1 │ 2 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴───┴───┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test({ a: [1, 2, 3, 4, 5], b: 5, c: { e: 5 } }, `
|
|
|
|
┌─────────┬───┬───┬───┬───┬───┬───┬────────┐
|
|
|
|
│ (index) │ 0 │ 1 │ 2 │ 3 │ 4 │ e │ Values │
|
|
|
|
├─────────┼───┼───┼───┼───┼───┼───┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ a │ 1 │ 2 │ 3 │ 4 │ 5 │ │ │
|
|
|
|
│ b │ │ │ │ │ │ │ 5 │
|
|
|
|
│ c │ │ │ │ │ │ 5 │ │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴───┴───┴───┴───┴───┴───┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test(new Uint8Array([1, 2, 3]), `
|
|
|
|
┌─────────┬────────┐
|
|
|
|
│ (index) │ Values │
|
|
|
|
├─────────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │
|
|
|
|
│ 1 │ 2 │
|
|
|
|
│ 2 │ 3 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test(Buffer.from([1, 2, 3]), `
|
|
|
|
┌─────────┬────────┐
|
|
|
|
│ (index) │ Values │
|
|
|
|
├─────────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │
|
|
|
|
│ 1 │ 2 │
|
|
|
|
│ 2 │ 3 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test({ a: undefined }, ['x'], `
|
|
|
|
┌─────────┬───┐
|
|
|
|
│ (index) │ x │
|
|
|
|
├─────────┼───┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ a │ │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴───┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test([], `
|
|
|
|
┌─────────┐
|
|
|
|
│ (index) │
|
|
|
|
├─────────┤
|
|
|
|
└─────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test(new Map(), `
|
|
|
|
┌───────────────────┬─────┬────────┐
|
|
|
|
│ (iteration index) │ Key │ Values │
|
|
|
|
├───────────────────┼─────┼────────┤
|
|
|
|
└───────────────────┴─────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], `
|
|
|
|
┌─────────┬─────┬─────┐
|
2024-06-11 07:41:44 -04:00
|
|
|
│ (index) │ a │ b │
|
2023-02-20 10:35:04 -05:00
|
|
|
├─────────┼─────┼─────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ 1 │ 'Y' │
|
|
|
|
│ 1 │ 'Z' │ 2 │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴─────┴─────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
{
|
|
|
|
const line = '─'.repeat(79);
|
2024-06-11 07:41:44 -04:00
|
|
|
const header = `name${' '.repeat(77)}`;
|
2023-02-20 10:35:04 -05:00
|
|
|
const name = 'very long long long long long long long long long long long ' +
|
|
|
|
'long long long long';
|
|
|
|
test([{ name }], `
|
|
|
|
┌─────────┬──${line}──┐
|
2024-06-11 07:41:44 -04:00
|
|
|
│ (index) │ ${header} │
|
2023-02-20 10:35:04 -05:00
|
|
|
├─────────┼──${line}──┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ '${name}' │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴──${line}──┘
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
|
|
|
|
test({ foo: '¥', bar: '¥' }, `
|
|
|
|
┌─────────┬────────┐
|
|
|
|
│ (index) │ Values │
|
|
|
|
├─────────┼────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ foo │ '¥' │
|
|
|
|
│ bar │ '¥' │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
test({ foo: '你好', bar: 'hello' }, `
|
|
|
|
┌─────────┬─────────┐
|
|
|
|
│ (index) │ Values │
|
|
|
|
├─────────┼─────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ foo │ '你好' │
|
|
|
|
│ bar │ 'hello' │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴─────────┘
|
|
|
|
`);
|
|
|
|
|
|
|
|
// Regression test for prototype pollution via console.table. Earlier versions
|
|
|
|
// of Node.js created an object with a non-null prototype within console.table
|
|
|
|
// and then wrote to object[column][index], which lead to an error as well as
|
|
|
|
// modifications to Object.prototype.
|
|
|
|
test([{ foo: 10 }, { foo: 20 }], ['__proto__'], `
|
|
|
|
┌─────────┬───────────┐
|
|
|
|
│ (index) │ __proto__ │
|
|
|
|
├─────────┼───────────┤
|
2024-06-11 07:41:44 -04:00
|
|
|
│ 0 │ │
|
|
|
|
│ 1 │ │
|
2023-02-20 10:35:04 -05:00
|
|
|
└─────────┴───────────┘
|
|
|
|
`);
|
|
|
|
assert.strictEqual('0' in Object.prototype, false);
|
|
|
|
assert.strictEqual('1' in Object.prototype, false);
|