import { Value, is, preserves, strip } from '../src/index'; import '../src/node_support'; declare global { namespace jest { interface Matchers { is(expected: Value): R; toThrowFilter(f: (e: Error) => boolean): R; } } } expect.extend({ is(actual, expected) { return is(actual, expected) ? { message: () => preserves`expected ${actual} not to be Preserves.is to ${expected}`, pass: true } : { message: () => preserves`expected ${actual} to be Preserves.is to ${expected}`, pass: false }; }, toThrowFilter(thunk, f) { try { thunk(); return { message: () => preserves`expected an exception`, pass: false }; } catch (e) { if (f(e)) { return { message: () => preserves`expected an exception not matching the filter`, pass: true }; } else { return { message: () => preserves`expected an exception matching the filter: ${e.constructor.name}`, pass: false }; } } } }); export class Pointer { v: Value; constructor(v: Value) { this.v = v; } equals(other: any, is: (a: any, b: any) => boolean) { return Object.is(other.constructor, this.constructor) && is(this.v, other.v); } asPreservesText(): string { return '#!' + this.v.asPreservesText(); } } export function decodePointer(v: Value): Pointer { return new Pointer(strip(v)); } export function encodePointer(w: Pointer): Value { return w.v; }