diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-26 11:06:40 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-03 02:22:30 +0200 |
commit | 666c67e078bddc32f25409f4a929c1e9b5f47373 (patch) | |
tree | 6a108e92e66f6d7199745e4d4a83df17644e8fbe /test/parallel/test-util-inspect.js | |
parent | e1e9f1e9eeeb899fb1dad10072fdf22ce5c9827e (diff) | |
download | android-node-v8-666c67e078bddc32f25409f4a929c1e9b5f47373.tar.gz android-node-v8-666c67e078bddc32f25409f4a929c1e9b5f47373.tar.bz2 android-node-v8-666c67e078bddc32f25409f4a929c1e9b5f47373.zip |
test: simplify date inspection tests
The code duplicated a lot of logic that was already abstracted. Use
the abstraction instead to remove code overhead.
PR-URL: https://github.com/nodejs/node/pull/26922
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Diffstat (limited to 'test/parallel/test-util-inspect.js')
-rw-r--r-- | test/parallel/test-util-inspect.js | 48 |
1 files changed, 3 insertions, 45 deletions
diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index dd44c9c439..547399f763 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1815,7 +1815,9 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); [RegExp, ['foobar', 'g'], '/foobar/g'], [WeakSet, [[{}]], '{ <items unknown> }'], [WeakMap, [[[{}, {}]]], '{ <items unknown> }'], - [BigInt64Array, [10], '[ 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n ]'] + [BigInt64Array, [10], '[ 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n ]'], + [Date, ['Sun, 14 Feb 2010 11:48:40 GMT'], '2010-02-14T11:48:40.000Z'], + [Date, ['invalid_date'], 'Invalid Date'] ].forEach(([base, input, rawExpected]) => { class Foo extends base {} const value = new Foo(...input); @@ -1841,50 +1843,6 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); assert(/\[Symbol\(foo\)]: 'yeah'/.test(res), res); }); -// Date null prototype checks -{ - class CustomDate extends Date { - } - - const date = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT'); - assert.strictEqual(util.inspect(date), 'CustomDate 2010-02-14T11:48:40.000Z'); - - // add properties - date.foo = 'bar'; - assert.strictEqual(util.inspect(date), - '{ CustomDate 2010-02-14T11:48:40.000Z foo: \'bar\' }'); - - // Check for null prototype - Object.setPrototypeOf(date, null); - assert.strictEqual(util.inspect(date), - '{ [Date: null prototype] 2010-02-14T11:48:40.000Z' + - ' foo: \'bar\' }'); - - const anotherDate = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT'); - Object.setPrototypeOf(anotherDate, null); - assert.strictEqual(util.inspect(anotherDate), - '[Date: null prototype] 2010-02-14T11:48:40.000Z'); -} - -// Check for invalid dates and null prototype -{ - class CustomDate extends Date { - } - - const date = new CustomDate('invalid_date'); - assert.strictEqual(util.inspect(date), 'CustomDate Invalid Date'); - - // add properties - date.foo = 'bar'; - assert.strictEqual(util.inspect(date), - '{ CustomDate Invalid Date foo: \'bar\' }'); - - // Check for null prototype - Object.setPrototypeOf(date, null); - assert.strictEqual(util.inspect(date), - '{ [Date: null prototype] Invalid Date foo: \'bar\' }'); -} - assert.strictEqual(inspect(1n), '1n'); assert.strictEqual(inspect(Object(-1n)), '[BigInt: -1n]'); assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]'); |