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
Declares type for keyed collections
  • Loading branch information
jamesseanwright committed Nov 3, 2019
commit 6b3e73fb3ce7c04293556831c6f1217c98fe2aff
6 changes: 4 additions & 2 deletions std/testing/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ function buildMessage(diffResult: ReadonlyArray<DiffResult<string>>): string[] {
return messages;
}

function isKeyedCollection(x: unknown): x is Map<unknown, unknown> | Set<unknown> {
return [Symbol.iterator, 'has', 'size'].every(key => key in (x as Map<unknown, unknown> | Set<unknown>));
type KeyedCollection = Map<unknown, unknown> | Set<unknown>;

function isKeyedCollection(x: unknown): x is KeyedCollection {
return [Symbol.iterator, 'has', 'size'].every(key => key in (x as KeyedCollection));
}

export function equal(c: unknown, d: unknown): boolean {
Expand Down