import { Arbitrary, default as fc } from 'fast-check'; import { Attempt } from '../../main/ts/bedrock/core/Attempt'; import { assert } from 'chai'; export const arbAttemptFailed = (arbe: Arbitrary): Arbitrary> => arbe.map>(Attempt.failed); export const arbAttemptPassed = (arba: Arbitrary): Arbitrary> => arba.map>(Attempt.passed); export const arbAttempt = (arbe: Arbitrary, arba: Arbitrary): Arbitrary> => fc.oneof(arbAttemptFailed(arbe), arbAttemptPassed(arba)); export const assertErrors = (expected: E, actual: Attempt): void => { Attempt.cata(actual, (errs) => { assert.deepEqual(errs, expected); }, () => { assert.fail('Expected errors: ' + JSON.stringify(expected)); }); }; export const assertResult = (expected: A, actual: Attempt): void => { Attempt.cata(actual, (errs) => { assert.fail('Unexpected errors: ' + JSON.stringify(errs)); }, result => { assert.deepEqual(result, expected); }); };