Skip to content

Commit

Permalink
fix(testing/assert): inequality of -0 and 0 (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
XMLHexagram authored Jan 4, 2022
1 parent a2a2cb5 commit 43c5946
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions testing/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ export function equal(c: unknown, d: unknown): boolean {
}
return a.getTime() === b.getTime();
}
if (typeof a === "number" && typeof b === "number") {
return Number.isNaN(a) && Number.isNaN(b) || a === b;
}
if (Object.is(a, b)) {
return true;
}
Expand Down
12 changes: 12 additions & 0 deletions testing/asserts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ import {
} from "./asserts.ts";
import { bold, gray, green, red, stripColor, yellow } from "../fmt/colors.ts";

Deno.test("testingEqualDifferentZero", () => {
assert(equal(0, -0));
assert(equal(0, +0));
assert(equal(+0, -0));
assert(equal([0], [-0]));
assert(equal(["hello", 12.21, 0], ["hello", 12.21, -0]));
assert(equal(["hello", 12.21, 0], ["hello", 12.21, +0]));
assert(equal(["hello", 12.21, -0], ["hello", 12.21, +0]));
assert(equal({ msg: "hello", case: 0 }, { msg: "hello", case: -0 }));
assert(equal({ msg: "hello", array: [0] }, { msg: "hello", array: [-0] }));
});

Deno.test("testingEqual", function (): void {
assert(equal("world", "world"));
assert(!equal("hello", "world"));
Expand Down

0 comments on commit 43c5946

Please sign in to comment.