From 222e64bad3b443f1daa3c018212a64de8ec828ad Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 17 Oct 2022 15:49:34 -0700 Subject: [PATCH] Temporal: Fix mergeFields test for non-string keys Using assert.deepEqual was faulty here, since deepEqual doesn't take symbol keys into account. This test wasn't actually testing that the symbol keys were absent, and in fact passes if they are present. (Rather than fixing deepEqual, since we hope to deprecate it as per https://github.com/tc39/test262/issues/3476, add a custom assert function in the test.) --- .../mergeFields/non-string-properties.js | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js b/test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js index 2908be90ba8..2a48dbf62cc 100644 --- a/test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js +++ b/test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js @@ -13,22 +13,43 @@ info: | 5. Set additionalFields to ? ToObject(additionalFields). 6. Return ? DefaultMergeFields(fields, additionalFields). features: [Temporal] -includes: [deepEqual.js] ---*/ +function assertEntriesEqual(actual, expectedEntries, message) { + const names = Object.getOwnPropertyNames(actual); + const symbols = Object.getOwnPropertySymbols(actual); + const actualKeys = names.concat(symbols); + assert.sameValue( + actualKeys.length, + expectedEntries.length, + `${message}: expected object to have ${expectedEntries.length} properties, not ${actualKeys.length}:` + ); + for (var index = 0; index < actualKeys.length; index++) { + const actualKey = actualKeys[index]; + const expectedKey = expectedEntries[index][0]; + const expectedValue = expectedEntries[index][1]; + assert.sameValue(actualKey, expectedKey, `${message}: key ${index}:`); + assert.sameValue(actual[actualKey], expectedValue, `${message}: value ${index}:`); + } +} + const cal = new Temporal.Calendar("iso8601"); -assert.deepEqual( +assertEntriesEqual( cal.mergeFields({ 1: 2 }, { 3: 4 }), - { "1": 2, "3": 4 }, + [["1", 2], ["3", 4]], "number keys are actually string keys and are merged as such" ); -assert.deepEqual( +assertEntriesEqual( cal.mergeFields({ 1n: 2 }, { 2n: 4 }), - { "1": 2, "2": 4 }, + [["1", 2], ["2", 4]], "bigint keys are actually string keys and are merged as such" ); const foo = Symbol("foo"); const bar = Symbol("bar"); -assert.deepEqual(cal.mergeFields({ [foo]: 1 }, { [bar]: 2 }), {}, "symbol keys are not merged"); +assertEntriesEqual( + cal.mergeFields({ [foo]: 1 }, { [bar]: 2 }), + [], + "symbol keys are not merged" +);