summaryrefslogtreecommitdiff
path: root/test/parallel/test-util-inspect.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-05-14 18:44:30 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-05-19 19:30:58 +0200
commit27df81cd1874e5392bbfa479543e47dd226f322a (patch)
treed4eb0c03f475164ce9dc82c8c513eba197511319 /test/parallel/test-util-inspect.js
parent456a8193cb6d7ba3514c14c64130c3f5c5fcd198 (diff)
downloadandroid-node-v8-27df81cd1874e5392bbfa479543e47dd226f322a.tar.gz
android-node-v8-27df81cd1874e5392bbfa479543e47dd226f322a.tar.bz2
android-node-v8-27df81cd1874e5392bbfa479543e47dd226f322a.zip
util: remove custom inspection function
This removes the deprecated custom inspection function and fixes all tests accordingly. Refs: https://github.com/nodejs/node/issues/15549 PR-URL: https://github.com/nodejs/node/pull/20722 Refs: https://github.com/nodejs/node/issues/15549 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-util-inspect.js')
-rw-r--r--test/parallel/test-util-inspect.js91
1 files changed, 21 insertions, 70 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js
index b80e932dd1..e3122d1b81 100644
--- a/test/parallel/test-util-inspect.js
+++ b/test/parallel/test-util-inspect.js
@@ -531,10 +531,10 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
);
}
-// GH-1941
+// https://github.com/nodejs/node-v0.x-archive/issues/1941
assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}');
-// GH-1944
+// https://github.com/nodejs/node-v0.x-archive/issues/1944
{
const d = new Date();
d.toUTCString = null;
@@ -549,20 +549,20 @@ assert.strictEqual(util.inspect(Object.create(Date.prototype)), 'Date {}');
}
// Should not throw.
-const r = /regexp/;
-r.toString = null;
-util.inspect(r);
-
-// Bug with user-supplied inspect function returns non-string.
-util.inspect([{ inspect: () => 123 }]);
+{
+ const r = /regexp/;
+ r.toString = null;
+ util.inspect(r);
+}
-// GH-2225
+// See https://github.com/nodejs/node-v0.x-archive/issues/2225
{
- const x = { inspect: util.inspect };
- assert.strictEqual(util.inspect(x).includes('inspect'), true);
+ const x = { [util.inspect.custom]: util.inspect };
+ assert(util.inspect(x).includes(
+ '[Symbol(util.inspect.custom)]: \n { [Function: inspect]'));
}
-// util.inspect should display the escaped value of a key.
+// `util.inspect` should display the escaped value of a key.
{
const w = {
'\\': 1,
@@ -660,8 +660,8 @@ util.inspect({ hasOwnProperty: null });
}
{
- // "customInspect" option can enable/disable calling inspect() on objects.
- const subject = { inspect: () => 123 };
+ // "customInspect" option can enable/disable calling [util.inspect.custom]().
+ const subject = { [util.inspect.custom]: () => 123 };
assert.strictEqual(
util.inspect(subject, { customInspect: true }).includes('123'),
@@ -680,31 +680,6 @@ util.inspect({ hasOwnProperty: null });
true
);
- // Custom inspect() functions should be able to return other Objects.
- subject.inspect = () => ({ foo: 'bar' });
-
- assert.strictEqual(util.inspect(subject), '{ foo: \'bar\' }');
-
- subject.inspect = (depth, opts) => {
- assert.strictEqual(opts.customInspectOptions, true);
- };
-
- util.inspect(subject, { customInspectOptions: true });
-}
-
-{
- // "customInspect" option can enable/disable calling [util.inspect.custom]().
- const subject = { [util.inspect.custom]: () => 123 };
-
- assert.strictEqual(
- util.inspect(subject, { customInspect: true }).includes('123'),
- true
- );
- assert.strictEqual(
- util.inspect(subject, { customInspect: false }).includes('123'),
- false
- );
-
// A custom [util.inspect.custom]() should be able to return other Objects.
subject[util.inspect.custom] = () => ({ foo: 'bar' });
@@ -718,42 +693,15 @@ util.inspect({ hasOwnProperty: null });
}
{
- // [util.inspect.custom] takes precedence over inspect.
- const subject = {
- [util.inspect.custom]() { return 123; },
- inspect() { return 456; }
- };
-
- assert.strictEqual(
- util.inspect(subject, { customInspect: true }).includes('123'),
- true
- );
- assert.strictEqual(
- util.inspect(subject, { customInspect: false }).includes('123'),
- false
- );
- assert.strictEqual(
- util.inspect(subject, { customInspect: true }).includes('456'),
- false
- );
- assert.strictEqual(
- util.inspect(subject, { customInspect: false }).includes('456'),
- false
- );
-}
-
-{
// Returning `this` from a custom inspection function works.
- assert.strictEqual(util.inspect({ a: 123, inspect() { return this; } }),
- '{ a: 123, inspect: [Function: inspect] }');
-
const subject = { a: 123, [util.inspect.custom]() { return this; } };
const UIC = 'util.inspect.custom';
assert.strictEqual(util.inspect(subject),
`{ a: 123,\n [Symbol(${UIC})]: [Function: [${UIC}]] }`);
}
-// util.inspect with "colors" option should produce as many lines as without it.
+// Using `util.inspect` with "colors" option should produce as many lines as
+// without it.
{
function testLines(input) {
const countLines = (str) => (str.match(/\n/g) || []).length;
@@ -1160,8 +1108,11 @@ util.inspect(process);
// Setting custom inspect property to a non-function should do nothing.
{
- const obj = { inspect: 'fhqwhgads' };
- assert.strictEqual(util.inspect(obj), "{ inspect: 'fhqwhgads' }");
+ const obj = { [util.inspect.custom]: 'fhqwhgads' };
+ assert.strictEqual(
+ util.inspect(obj),
+ "{ [Symbol(util.inspect.custom)]: 'fhqwhgads' }"
+ );
}
{