Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/internal/cli_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ const renderRow = (row, columnWidths) => {
for (let i = 0; i < row.length; i++) {
const cell = row[i];
const len = getStringWidth(cell);
const needed = (columnWidths[i] - len) / 2;
const needed = (columnWidths[i] - len);
// round(needed) + ceil(needed) will always add up to the amount
// of spaces we need while also left justifying the output.
out += StringPrototypeRepeat(' ', needed) + cell +
StringPrototypeRepeat(' ', MathCeil(needed));
out += cell + StringPrototypeRepeat(' ', MathCeil(needed));
if (i !== row.length - 1)
out += tableChars.middle;
}
Expand Down
130 changes: 65 additions & 65 deletions test/parallel/test-console-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,124 +38,124 @@ test([1, 2, 3], `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
0 1
1 2
2 3
01
12
23
└─────────┴────────┘
`);

test([Symbol(), 5, [10]], `
┌─────────┬────┬──────────┐
│ (index) │ 0 │ Values │
│ (index) │ 0 │ Values
├─────────┼────┼──────────┤
0 │ │ Symbol() │
1 │ │ 5
2 │ 10 │ │
0 │ │ Symbol() │
1 │ │ 5
2 │ 10 │ │
└─────────┴────┴──────────┘
`);

test([null, 5], `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
0 null │
1 5
0 │ null
15
└─────────┴────────┘
`);

test([undefined, 5], `
┌─────────┬───────────┐
│ (index) │ Values │
│ (index) │ Values
├─────────┼───────────┤
0 │ undefined │
15
0 │ undefined │
15
└─────────┴───────────┘
`);

test({ a: 1, b: Symbol(), c: [10] }, `
┌─────────┬────┬──────────┐
│ (index) │ 0 │ Values │
│ (index) │ 0 │ Values
├─────────┼────┼──────────┤
a │ │ 1
b │ │ Symbol() │
c │ 10 │ │
a │ │ 1
b │ │ Symbol() │
c │ 10 │ │
└─────────┴────┴──────────┘
`);

test(new Map([ ['a', 1], [Symbol(), [2]] ]), `
┌───────────────────┬──────────┬────────┐
│ (iteration index) │ Key │ Values │
│ (iteration index) │ Key │ Values │
├───────────────────┼──────────┼────────┤
0 'a' │ 1
1 │ Symbol() │ [ 2 ] │
0 │ 'a' │ 1
1 │ Symbol() │ [ 2 ] │
└───────────────────┴──────────┴────────┘
`);

test(new Set([1, 2, Symbol()]), `
┌───────────────────┬──────────┐
│ (iteration index) │ Values │
│ (iteration index) │ Values
├───────────────────┼──────────┤
01
12
2 │ Symbol() │
01
12
2 │ Symbol() │
└───────────────────┴──────────┘
`);

test({ a: 1, b: 2 }, ['a'], `
┌─────────┬───┐
│ (index) │ a │
├─────────┼───┤
a │ │
b │ │
a │ │
b │ │
└─────────┴───┘
`);

test([{ a: 1, b: 2 }, { a: 3, c: 4 }], ['a'], `
┌─────────┬───┐
│ (index) │ a │
├─────────┼───┤
0 │ 1 │
1 │ 3 │
0 │ 1 │
1 │ 3 │
└─────────┴───┘
`);

test(new Map([[1, 1], [2, 2], [3, 3]]).entries(), `
┌───────────────────┬─────┬────────┐
│ (iteration index) │ Key │ Values │
├───────────────────┼─────┼────────┤
0 1 │ 1
1 2 │ 2
2 3 │ 3
0 │ 1 │ 1
1 │ 2 │ 2
2 │ 3 │ 3
└───────────────────┴─────┴────────┘
`);

test(new Map([[1, 1], [2, 2], [3, 3]]).values(), `
┌───────────────────┬────────┐
│ (iteration index) │ Values │
├───────────────────┼────────┤
0 1
1 2
2 3
01
12
23
└───────────────────┴────────┘
`);

test(new Map([[1, 1], [2, 2], [3, 3]]).keys(), `
┌───────────────────┬────────┐
│ (iteration index) │ Values │
├───────────────────┼────────┤
0 1
1 2
2 3
01
12
23
└───────────────────┴────────┘
`);

test(new Set([1, 2, 3]).values(), `
┌───────────────────┬────────┐
│ (iteration index) │ Values │
├───────────────────┼────────┤
0 1
1 2
2 3
01
12
23
└───────────────────┴────────┘
`);

Expand All @@ -164,61 +164,61 @@ test({ a: { a: 1, b: 2, c: 3 } }, `
┌─────────┬───┬───┬───┐
│ (index) │ a │ b │ c │
├─────────┼───┼───┼───┤
a │ 1 │ 2 │ 3 │
a │ 1 │ 2 │ 3 │
└─────────┴───┴───┴───┘
`);

test({ a: { a: { a: 1, b: 2, c: 3 } } }, `
┌─────────┬──────────┐
│ (index) │ a
│ (index) │ a
├─────────┼──────────┤
a │ [Object] │
a │ [Object] │
└─────────┴──────────┘
`);

test({ a: [1, 2] }, `
┌─────────┬───┬───┐
│ (index) │ 0 │ 1 │
├─────────┼───┼───┤
a │ 1 │ 2 │
a │ 1 │ 2 │
└─────────┴───┴───┘
`);

test({ a: [1, 2, 3, 4, 5], b: 5, c: { e: 5 } }, `
┌─────────┬───┬───┬───┬───┬───┬───┬────────┐
│ (index) │ 0 │ 1 │ 2 │ 3 │ 4 │ e │ Values │
├─────────┼───┼───┼───┼───┼───┼───┼────────┤
a │ 1 │ 2 │ 3 │ 4 │ 5 │ │ │
b │ │ │ │ │ │ │ 5
c │ │ │ │ │ │ 5 │ │
a │ 1 │ 2 │ 3 │ 4 │ 5 │ │ │
b │ │ │ │ │ │ │ 5
c │ │ │ │ │ │ 5 │ │
└─────────┴───┴───┴───┴───┴───┴───┴────────┘
`);

test(new Uint8Array([1, 2, 3]), `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
0 1
1 2
2 3
01
12
23
└─────────┴────────┘
`);

test(Buffer.from([1, 2, 3]), `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
0 1
1 2
2 3
01
12
23
└─────────┴────────┘
`);

test({ a: undefined }, ['x'], `
┌─────────┬───┐
│ (index) │ x │
├─────────┼───┤
a │ │
a │ │
└─────────┴───┘
`);

Expand All @@ -238,23 +238,23 @@ test(new Map(), `

test([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], `
┌─────────┬─────┬─────┐
│ (index) │ a │ b
│ (index) │ a │ b
├─────────┼─────┼─────┤
0 1 │ 'Y' │
1 │ 'Z' │ 2
01 │ 'Y' │
1 │ 'Z' │ 2
└─────────┴─────┴─────┘
`);

{
const line = '─'.repeat(79);
const header = `${' '.repeat(37)}name${' '.repeat(40)}`;
const header = `name${' '.repeat(77)}`;
const name = 'very long long long long long long long long long long long ' +
'long long long long';
test([{ name }], `
┌─────────┬──${line}──┐
│ (index) │ ${header}│
│ (index) │ ${header}
├─────────┼──${line}──┤
0 │ '${name}' │
0 │ '${name}' │
└─────────┴──${line}──┘
`);
}
Expand All @@ -263,17 +263,17 @@ test({ foo: '¥', bar: '¥' }, `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
foo '¥' │
bar '¥' │
foo │ '¥'
bar │ '¥'
└─────────┴────────┘
`);

test({ foo: '你好', bar: 'hello' }, `
┌─────────┬─────────┐
│ (index) │ Values │
├─────────┼─────────┤
foo │ '你好' │
bar │ 'hello' │
foo │ '你好' │
bar │ 'hello' │
└─────────┴─────────┘
`);

Expand All @@ -285,8 +285,8 @@ test([{ foo: 10 }, { foo: 20 }], ['__proto__'], `
┌─────────┬───────────┐
│ (index) │ __proto__ │
├─────────┼───────────┤
0 │ │
1 │ │
0 │ │
1 │ │
└─────────┴───────────┘
`);
assert.strictEqual('0' in Object.prototype, false);
Expand Down