From 4fa52c8d2dfee63d4ff15603deb2dd9c5fde66aa Mon Sep 17 00:00:00 2001 From: rwaldron Date: Tue, 7 Dec 2021 15:27:15 -0500 Subject: [PATCH] test: expected behavior when bigint and number have "same" value --- .../built-ins/Map/bigint-number-same-value.js | 44 +++++++++++++++++++ .../built-ins/Set/bigint-number-same-value.js | 44 +++++++++++++++++++ test/built-ins/Set/valid-values.js | 2 +- 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 test/built-ins/Map/bigint-number-same-value.js create mode 100644 test/built-ins/Set/bigint-number-same-value.js diff --git a/test/built-ins/Map/bigint-number-same-value.js b/test/built-ins/Map/bigint-number-same-value.js new file mode 100644 index 0000000000..6df9086234 --- /dev/null +++ b/test/built-ins/Map/bigint-number-same-value.js @@ -0,0 +1,44 @@ +// Copyright (C) 2021 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-map.prototype.set +description: > + Observing the expected behavior of keys when a BigInt and Number have + the same value. +info: | + Map.prototype.set ( key , value ) + + ... + Let p be the Record {[[key]]: key, [[value]]: value}. + Append p as the last element of entries. + ... + +features: [BigInt] +---*/ + +const number = 9007199254740991; +const bigint = 9007199254740991n; + +const m = new Map([ + [number, number], + [bigint, bigint], +]); + +assert.sameValue(m.size, 2); +assert.sameValue(m.has(number), true); +assert.sameValue(m.has(bigint), true); + +assert.sameValue(m.get(number), number); +assert.sameValue(m.get(bigint), bigint); + +m.delete(number); +assert.sameValue(m.size, 1); +assert.sameValue(m.has(number), false); +m.delete(bigint); +assert.sameValue(m.size, 0); +assert.sameValue(m.has(bigint), false); + +m.set(number, number); +assert.sameValue(m.size, 1); +m.set(bigint, bigint); +assert.sameValue(m.size, 2); diff --git a/test/built-ins/Set/bigint-number-same-value.js b/test/built-ins/Set/bigint-number-same-value.js new file mode 100644 index 0000000000..49b8233213 --- /dev/null +++ b/test/built-ins/Set/bigint-number-same-value.js @@ -0,0 +1,44 @@ +// Copyright (C) 2021 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-set.prototype.add +description: > + Observing the expected behavior of keys when a BigInt and Number have + the same value. +info: | + Set.prototype.add ( value ) + + ... + For each element e of entries, do + If e is not empty and SameValueZero(e, value) is true, then + Return S. + If value is -0, set value to +0. + Append value as the last element of entries. + ... + +features: [BigInt] +---*/ + +const number = 9007199254740991; +const bigint = 9007199254740991n; + +const s = new Set([ + number, + bigint, +]); + +assert.sameValue(s.size, 2); +assert.sameValue(s.has(number), true); +assert.sameValue(s.has(bigint), true); + +s.delete(number); +assert.sameValue(s.size, 1); +assert.sameValue(s.has(number), false); +s.delete(bigint); +assert.sameValue(s.size, 0); +assert.sameValue(s.has(bigint), false); + +s.add(number); +assert.sameValue(s.size, 1); +s.add(bigint); +assert.sameValue(s.size, 2); diff --git a/test/built-ins/Set/valid-values.js b/test/built-ins/Set/valid-values.js index 7bedc9bc43..2f7e6a33c6 100644 --- a/test/built-ins/Set/valid-values.js +++ b/test/built-ins/Set/valid-values.js @@ -10,7 +10,7 @@ info: | For each element e of entries, do If e is not empty and SameValueZero(e, value) is true, then Return S. - If value is -0𝔽, set value to +0𝔽. + If value is -0, set value to +0. Append value as the last element of entries. ...