-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: change inspect's default depth to 4 #28269
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,8 +113,10 @@ assert.strictEqual(util.inspect({ a: function*() {} }), | |
assert.strictEqual(util.inspect({ a: 1, b: 2 }), '{ a: 1, b: 2 }'); | ||
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] } } }'); | ||
assert.strictEqual( | ||
util.inspect({ 'a': { 'b': { 'c': { 'd': { 'e': { 'f': {} } } } } } }), | ||
'{\n a: {\n b: { c: { d: { e: [Object] } } }\n }\n}' | ||
); | ||
assert.strictEqual( | ||
util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }, false, null), | ||
'{\n a: { b: { c: { d: 2 } } }\n}'); | ||
|
@@ -154,10 +156,12 @@ assert.strictEqual(util.inspect((new JSStream())._externalStream), | |
} | ||
|
||
assert(/Object/.test( | ||
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, undefined, true) | ||
util.inspect({ a: { a: { a: { a: { a: { a: {} } } } } } }, | ||
undefined, undefined, true) | ||
)); | ||
assert(!/Object/.test( | ||
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true) | ||
util.inspect({ a: { a: { a: { a: { a: { a: {} } } } } } }, | ||
undefined, null, true) | ||
)); | ||
|
||
{ | ||
|
@@ -1253,18 +1257,36 @@ if (typeof Symbol !== 'undefined') { | |
|
||
// Empty and circular before depth. | ||
{ | ||
const arr = [[[[]]]]; | ||
assert.strictEqual(util.inspect(arr), '[ [ [ [] ] ] ]'); | ||
arr[0][0][0][0] = []; | ||
assert.strictEqual(util.inspect(arr), '[ [ [ [Array] ] ] ]'); | ||
arr[0][0][0] = {}; | ||
assert.strictEqual(util.inspect(arr), '[ [ [ {} ] ] ]'); | ||
arr[0][0][0] = { a: 2 }; | ||
assert.strictEqual(util.inspect(arr), '[ [ [ [Object] ] ] ]'); | ||
arr[0][0][0] = arr; | ||
assert.strictEqual(util.inspect(arr), '<ref *1> [ [ [ [Circular *1] ] ] ]'); | ||
const arr = [[[[[[]]]]]]; | ||
assert.strictEqual( | ||
util.inspect(arr), | ||
'[\n [\n [ [ [ [] ] ] ]\n ]\n]' | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not particularily happy with how these are printed, by the way. It almost seems like the linebreak logic in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default is currently set to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Do you recall why the particular value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking how many objects are all on the same line is difficult when it becomes to many. That's why I limited it to three by default. It is unrelated to the depth. |
||
arr[0][0][0][0][0][0] = []; | ||
assert.strictEqual( | ||
util.inspect(arr), | ||
'[\n [\n [ [ [ [Array] ] ] ]\n ]\n]' | ||
); | ||
arr[0][0][0][0][0] = {}; | ||
assert.strictEqual( | ||
util.inspect(arr), | ||
'[\n [\n [ [ [ {} ] ] ]\n ]\n]' | ||
); | ||
arr[0][0][0][0][0] = { a: 2 }; | ||
assert.strictEqual( | ||
util.inspect(arr), | ||
'[\n [\n [ [ [ [Object] ] ] ]\n ]\n]' | ||
); | ||
arr[0][0][0][0][0] = arr; | ||
assert.strictEqual( | ||
util.inspect(arr), | ||
'<ref *1> [\n [\n [ [ [ [Circular *1] ] ] ]\n ]\n]' | ||
); | ||
arr[0][0][0] = arr[0][0]; | ||
assert.strictEqual(util.inspect(arr), '[ [ <ref *1> [ [Circular *1] ] ] ]'); | ||
assert.strictEqual( | ||
util.inspect(arr), | ||
'[ [ <ref *1> [ [Circular *1] ] ] ]' | ||
); | ||
} | ||
|
||
// Corner cases. | ||
|
@@ -1354,7 +1376,7 @@ if (typeof Symbol !== 'undefined') { | |
// util.inspect.defaultOptions tests. | ||
{ | ||
const arr = new Array(101).fill(); | ||
const obj = { a: { a: { a: { a: 1 } } } }; | ||
const obj = { a: { a: { a: { a: { a: { a: 1 } } } } } }; | ||
|
||
const oldOptions = Object.assign({}, util.inspect.defaultOptions); | ||
|
||
|
@@ -1793,7 +1815,7 @@ util.inspect(process); | |
head = head.next = {}; | ||
assert.strictEqual( | ||
util.inspect(list), | ||
'{ next: { next: { next: [Object] } } }' | ||
'{\n next: {\n next: { next: { next: { next: [Object] } } }\n }\n}' | ||
); | ||
const longList = util.inspect(list, { depth: Infinity }); | ||
const match = longList.match(/next/g); | ||
|
@@ -2147,7 +2169,7 @@ assert.strictEqual( | |
getset.foo = new Set([[{ a: true }, 2, {}], 'foobar', { x: 1 }]); | ||
assert.strictEqual( | ||
inspect(getset, { getters: true }), | ||
'{\n foo: [Getter/Setter] Set { [ [Object], 2, {} ], ' + | ||
'{\n foo: [Getter/Setter] Set { [ { a: true }, 2, {} ], ' + | ||
"'foobar', { x: 1 } },\n inc: [Getter: NaN]\n}"); | ||
} | ||
|
||
|
@@ -2302,7 +2324,10 @@ assert.strictEqual( | |
}) | ||
}; | ||
|
||
out = util.inspect(obj, { compact: 1, breakLength: Infinity, colors: true }); | ||
out = util.inspect( | ||
obj, | ||
{ compact: 1, depth: 2, breakLength: Infinity, colors: true } | ||
); | ||
|
||
expected = [ | ||
'{', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is just documenting existing behaviour.
%o
is already defaulting to depth of4
before this change here.