UNPKG

fast-check

Version:

Property based testing framework for JavaScript (like QuickCheck)

27 lines (26 loc) 997 B
import { LazyArbitrary } from './_internals/LazyArbitrary.js'; import { Map as SMap, safeMapSet, safeMapGet } from '../utils/globals.js'; const safeGetOwnPropertyNames = Object.getOwnPropertyNames; function createLazyArbsPool() { const lazyArbsPool = new SMap(); const getLazyFromPool = (key) => { let lazyArb = safeMapGet(lazyArbsPool, key); if (lazyArb !== undefined) { return lazyArb; } lazyArb = new LazyArbitrary(String(key)); safeMapSet(lazyArbsPool, key, lazyArb); return lazyArb; }; return getLazyFromPool; } export /**@__NO_SIDE_EFFECTS__*/function letrec(builder) { const getLazyFromPool = createLazyArbsPool(); const strictArbs = builder(getLazyFromPool); const declaredArbitraryNames = safeGetOwnPropertyNames(strictArbs); for (const name of declaredArbitraryNames) { const lazyArb = getLazyFromPool(name); lazyArb.underlying = strictArbs[name]; } return strictArbs; }