Skip to content

Commit

Permalink
Handle negative zero as a distinct value (because it is)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorris committed Sep 18, 2024
1 parent 518fd0d commit ecf98b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Tuple.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function Tuple(...args)

if(!mode)
{
part = JSON.stringify(part.map(p => `${typeof p}::${p}`));
part = JSON.stringify(part.map(p => `${typeof p}::${Object.is(p, -0) ? '-0' : p}`));

if(!maps)
{
Expand Down
9 changes: 9 additions & 0 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,15 @@ tests.push(test('Dict JSON Test', t => {
assert.strictEqual(JSON.stringify(d1), '{"id":1,"name":"Test"}');
}));

tests.push(test('Negative Zero Test', t => {
const positive = Tuple(Object, 0);
const negative = Tuple(Object, -0);
assert.ok(Object.is(positive[1], 0));
assert.ok(Object.is(negative[1], -0));
assert.ok(!Object.is(positive[1], -0));
assert.ok(!Object.is(negative[1], 0));
}));

test(`Ensure memory isn\'t leaking for scalar keys`, async t => {
await Promise.allSettled(tests)

Expand Down

0 comments on commit ecf98b3

Please sign in to comment.