From 3d59e35db2fbe9314e61f4a80fa4bcd9e79cee06 Mon Sep 17 00:00:00 2001 From: pfg Date: Fri, 9 May 2025 17:43:00 -0700 Subject: [PATCH] TODO --- test/js/bun/test/expect-boxed.test.js | 3 + .../parallel/test-util-isDeepStrictEqual.js | 94 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 test/js/bun/test/expect-boxed.test.js create mode 100644 test/js/node/test/parallel/test-util-isDeepStrictEqual.js diff --git a/test/js/bun/test/expect-boxed.test.js b/test/js/bun/test/expect-boxed.test.js new file mode 100644 index 0000000000..9ef09f826a --- /dev/null +++ b/test/js/bun/test/expect-boxed.test.js @@ -0,0 +1,3 @@ +test("abc", () => { + expect(new Number(2)).not.toEqual(new Number(1)); +}); diff --git a/test/js/node/test/parallel/test-util-isDeepStrictEqual.js b/test/js/node/test/parallel/test-util-isDeepStrictEqual.js new file mode 100644 index 0000000000..31c5112b1a --- /dev/null +++ b/test/js/node/test/parallel/test-util-isDeepStrictEqual.js @@ -0,0 +1,94 @@ +'use strict'; + +// Confirm functionality of `util.isDeepStrictEqual()`. + +require('../common'); + +const assert = require('assert'); +const util = require('util'); + +function utilIsDeepStrict(a, b) { + assert.strictEqual(util.isDeepStrictEqual(a, b), true); + assert.strictEqual(util.isDeepStrictEqual(b, a), true); +} + +function notUtilIsDeepStrict(a, b) { + assert.strictEqual(util.isDeepStrictEqual(a, b), false); + assert.strictEqual(util.isDeepStrictEqual(b, a), false); +} + +// Handle boxed primitives +{ + const boxedString = new String('test'); + const boxedSymbol = Object(Symbol()); + // notUtilIsDeepStrict(new Boolean(true), Object(false)); // TODO + notUtilIsDeepStrict(Object(true), new Number(1)); + // notUtilIsDeepStrict(new Number(2), new Number(1)); // TODO + // notUtilIsDeepStrict(boxedSymbol, Object(Symbol())); // TODO + notUtilIsDeepStrict(boxedSymbol, {}); + utilIsDeepStrict(boxedSymbol, boxedSymbol); + utilIsDeepStrict(Object(true), Object(true)); + utilIsDeepStrict(Object(2), Object(2)); + utilIsDeepStrict(boxedString, Object('test')); + boxedString.slow = true; + // notUtilIsDeepStrict(boxedString, Object('test')); // TODO + boxedSymbol.slow = true; + notUtilIsDeepStrict(boxedSymbol, {}); + utilIsDeepStrict(Object(BigInt(1)), Object(BigInt(1))); + // notUtilIsDeepStrict(Object(BigInt(1)), Object(BigInt(2))); // TODO + + const booleanish = new Boolean(true); + Object.defineProperty(booleanish, Symbol.toStringTag, { value: 'String' }); + Object.setPrototypeOf(booleanish, String.prototype); + notUtilIsDeepStrict(booleanish, new String('true')); + + const numberish = new Number(42); + Object.defineProperty(numberish, Symbol.toStringTag, { value: 'String' }); + Object.setPrototypeOf(numberish, String.prototype); + notUtilIsDeepStrict(numberish, new String('42')); + + const stringish = new String('0'); + Object.defineProperty(stringish, Symbol.toStringTag, { value: 'Number' }); + Object.setPrototypeOf(stringish, Number.prototype); + notUtilIsDeepStrict(stringish, new Number(0)); + + const bigintish = new Object(BigInt(42)); + Object.defineProperty(bigintish, Symbol.toStringTag, { value: 'String' }); + Object.setPrototypeOf(bigintish, String.prototype); + notUtilIsDeepStrict(bigintish, new String('42')); + + const symbolish = new Object(Symbol('fhqwhgads')); + Object.defineProperty(symbolish, Symbol.toStringTag, { value: 'String' }); + Object.setPrototypeOf(symbolish, String.prototype); + notUtilIsDeepStrict(symbolish, new String('fhqwhgads')); +} + +// Handle symbols (enumerable only) +{ + const symbol1 = Symbol(); + const obj1 = { [symbol1]: 1 }; + const obj2 = { [symbol1]: 1 }; + const obj3 = { [Symbol()]: 1 }; + const obj4 = { }; + // Add a non enumerable symbol as well. It is going to be ignored! + Object.defineProperty(obj2, Symbol(), { value: 1 }); + Object.defineProperty(obj4, symbol1, { value: 1 }); + notUtilIsDeepStrict(obj1, obj3); + utilIsDeepStrict(obj1, obj2); + // notUtilIsDeepStrict(obj1, obj4); // TODO + // TypedArrays have a fast path. Test for this as well. + const a = new Uint8Array(4); + const b = new Uint8Array(4); + a[symbol1] = true; + b[symbol1] = false; + // notUtilIsDeepStrict(a, b); // TODO + b[symbol1] = true; + utilIsDeepStrict(a, b); + // The same as TypedArrays is valid for boxed primitives + const boxedStringA = new String('test'); + const boxedStringB = new String('test'); + boxedStringA[symbol1] = true; + // notUtilIsDeepStrict(boxedStringA, boxedStringB); // TODO + boxedStringA[symbol1] = true; + utilIsDeepStrict(a, b); +}