mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
Support Sets in asserts.equals (denoland/deno_std#350)
Original: 9432d70329
This commit is contained in:
parent
6df5291818
commit
eff23abc32
2 changed files with 17 additions and 0 deletions
|
@ -16,6 +16,17 @@ export class AssertionError extends Error {
|
||||||
export function equal(c: unknown, d: unknown): boolean {
|
export function equal(c: unknown, d: unknown): boolean {
|
||||||
const seen = new Map();
|
const seen = new Map();
|
||||||
return (function compare(a: unknown, b: unknown) {
|
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
|
// Have to render RegExp & Date for string comparison
|
||||||
// unless it's mistreated as object
|
// unless it's mistreated as object
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -40,6 +40,12 @@ test(function testingEqual() {
|
||||||
assert(!equal(/deno/, /node/));
|
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, 0, 3)));
|
||||||
assert(!equal(new Date(2019, 0, 3), new Date(2019, 1, 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() {
|
test(function testingNotEquals() {
|
||||||
|
|
Loading…
Reference in a new issue