import { assert, assertEquals, Err, ErrPromise, isOptionPromise, isResultPromise, NonePromise, Ok, OkPromise, type Option, OptionPromise, Result, ResultPromise, Some, SomePromise, testCase, } from "./deps"; type ExpectedValue = | OptionPromise | Option | Result | ResultPromise | Promise | string | number; type Expectation = ((v: ExpectedValue) => void | never) | ExpectedValue; type Task = { action: (ms: Option) => ExpectedValue; /** Value expected to be returned from `action`, or a function to check the returned value with */ expected: Expectation; /** * Value expected to be passed to promise.then(), or a function to check it with * if this value is omitted, the return from `action` may not be a promise like */ expectedThen?: Expectation; /** * Value expected to be passed to option.map()/result.map(), or a function to check it with * if this value is omitted, there may be no map function on the return from `action` */ expectedMap?: Expectation; }; function isPromise(p: unknown): p is Promise { return p instanceof Promise; } function promisify(arg: T) { return Promise.resolve(arg); } function sleep(ms: number): Promise { return Promise.resolve(ms / 1_000.0); } const tasks: { [key: string]: Task } = { "Option.mapOrElse to number": { action: (ms: Option) => { return ms.mapOrElse( () => 0, (ms) => ms, ); }, expected: 101, }, "Option.mapOrElse to Option": { action: (ms: Option) => ms.mapOrElse( () => Some(0), Some, ), expected: Some(102), expectedMap: 102, }, "Option.mapOrElse to OptionPromise compile error: return type is Promise