Skip to content

Commit

Permalink
Support Sets in asserts.equals (denoland/std#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Sharshakov authored and ry committed Apr 22, 2019
1 parent 6df5291 commit eff23ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions testing/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ export class AssertionError extends Error {
export function equal(c: unknown, d: unknown): boolean {
const seen = new Map();
return (function compare(a: unknown, b: unknown) {
if (a && a instanceof Set && b && b instanceof Set) {
if (a.size !== b.size) {
return false;
}
for (const item of b) {
if (!a.has(item)) {
return false;
}
}
return true;
}
// Have to render RegExp & Date for string comparison
// unless it's mistreated as object
if (
Expand Down
6 changes: 6 additions & 0 deletions testing/asserts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ test(function testingEqual() {
assert(!equal(/deno/, /node/));
assert(equal(new Date(2019, 0, 3), new Date(2019, 0, 3)));
assert(!equal(new Date(2019, 0, 3), new Date(2019, 1, 3)));
assert(equal(new Set([1]), new Set([1])));
assert(!equal(new Set([1]), new Set([2])));
assert(equal(new Set([1, 2, 3]), new Set([3, 2, 1])));
assert(!equal(new Set([1, 2]), new Set([3, 2, 1])));
assert(!equal(new Set([1, 2, 3]), new Set([4, 5, 6])));
assert(equal(new Set("denosaurus"), new Set("denosaurussss")));
});

test(function testingNotEquals() {
Expand Down

0 comments on commit eff23ab

Please sign in to comment.