Skip to content
Merged
6 changes: 6 additions & 0 deletions test/Test/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ exports.testNumberShow = function(showNumber) {
]);
};
};

exports.objectIs = function(l) {
return function(r) {
return Object.is(l, r);
};
};
9 changes: 7 additions & 2 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,10 @@ testRecordInstances = do

testSignum :: AlmostEff
testSignum = do
assert "signum positive zero" $ signum 0.0 == 0.0
assert "signum negative zero" $ signum (-0.0) == (-0.0)
assert "signum positive zero" $ objectIs (signum 0.0) 0.0
assert "signum negative zero" $ objectIs (signum (-0.0)) (-0.0)

-- Seems to be only way to check whether zero is `-0.0` or `0.0`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that our show doesn't distinguish negative and positive zero. But, you can still distinguish them without the FFI:

show (1.0/0.0) == "Infinity"
show (1.0/(-0.0)) == "-Infinity"

-- See "Case 2" in
-- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#using_object.is
foreign import objectIs :: Number -> Number -> Boolean