Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidates asserts#equal branches for keyed collections (Map/Set) and supports deep equality of Map keys #3258

Merged
merged 13 commits into from
Nov 4, 2019
Merged
Prev Previous commit
Next Next commit
Formats changes
  • Loading branch information
jamesseanwright committed Nov 3, 2019
commit 3b5c42bbb3d1568239a8c83e958b3fa194aadd55
6 changes: 2 additions & 4 deletions std/testing/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ function buildMessage(diffResult: ReadonlyArray<DiffResult<string>>): string[] {
return messages;
}

function isKeyedCollection(
x: unknown
): x is Set<unknown> {
return [Symbol.iterator, 'size'].every(k => k in (x as Set<unknown>));
function isKeyedCollection(x: unknown): x is Set<unknown> {
return [Symbol.iterator, "size"].every(k => k in (x as Set<unknown>));
}

export function equal(c: unknown, d: unknown): boolean {
Expand Down
21 changes: 3 additions & 18 deletions std/testing/asserts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,11 @@ test(function testingEqual(): void {
)
);

assert(
equal(
new Map([[{x: 1}, true]]),
new Map([[{x: 1}, true]])
)
);
assert(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, true]])));

assert(
!equal(
new Map([[{x: 1}, true]]),
new Map([[{x: 1}, false]])
)
);
assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, false]])));

assert(
!equal(
new Map([[{x: 1}, true]]),
new Map([[{x: 2}, false]])
)
);
assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 2 }, false]])));

assert(equal([1, 2, 3], [1, 2, 3]));
assert(equal([1, [2, 3]], [1, [2, 3]]));
Expand Down