/
asserts.js
24 lines (20 loc) · 1.12 KB
/
asserts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { assert, assertEquals } from "https://deno.land/std@0.65.0/testing/asserts.ts";
const $$value = Symbol.for("TypeValue");
const $$tag = Symbol.for("Tag");
export const assertIsDefined = value => typeof value !== "undefined";
// NOTE: assertIsEquivalent has a different signature than the other assert* which could lead into confusion
export const assertIsEquivalent = (containerA, containerB) => assert(isEquivalent(containerA, containerB));
export const assertIsNone = value => !value && typeof value === "object";
// isEquivalent :: Setoid a|a -> Setoid b|b -> Boolean
export const isEquivalent = (containerA, containerB) => {
// When the container are Setoids...
if (Reflect.getPrototypeOf(containerA).hasOwnProperty("equals")) return containerA.equals(containerB);
else if (
Reflect.has(containerA, $$value) && Reflect.has(containerB, $$value)
&& containerA[$$tag] === containerB[$$tag]
) {
return !assertEquals(containerA[$$value], containerB[$$value]);
} else if (Reflect.has(containerA, $$tag) && Reflect.has(containerB, $$tag)) {
return containerA[$$tag] === containerB[$$tag];
} else return false;
};