06e959e7a5
CI / check (pull_request) Failing after 1m39s
Cover high-priority untested modules: - util: base32, result, refs-field, storage-root, log-tag - util-agent: storage (normalizeWorkflowConfig, resolveStorageRoot), run (parseArgv) - agent-builtin: tools (read-file, write-file, run-command), session, detail 627 → 719 tests (+92), all passing. Refs #35
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { ok, err } from '../src/result.js';
|
|
|
|
describe('result', () => {
|
|
describe('ok', () => {
|
|
it('wraps a value', () => {
|
|
const r = ok(42);
|
|
expect(r).toEqual({ ok: true, value: 42 });
|
|
});
|
|
|
|
it('wraps a string value', () => {
|
|
const r = ok('hello');
|
|
expect(r.ok).toBe(true);
|
|
if (r.ok) expect(r.value).toBe('hello');
|
|
});
|
|
});
|
|
|
|
describe('err', () => {
|
|
it('wraps an error', () => {
|
|
const r = err('fail');
|
|
expect(r).toEqual({ ok: false, error: 'fail' });
|
|
});
|
|
|
|
it('wraps an Error object', () => {
|
|
const e = new Error('boom');
|
|
const r = err(e);
|
|
expect(r.ok).toBe(false);
|
|
if (!r.ok) expect(r.error).toBe(e);
|
|
});
|
|
});
|
|
|
|
describe('type narrowing', () => {
|
|
it('narrows ok result', () => {
|
|
const r = ok(10) as ReturnType<typeof ok<number>> | ReturnType<typeof err<string>>;
|
|
if (r.ok) {
|
|
expect(r.value).toBe(10);
|
|
} else {
|
|
expect.unreachable();
|
|
}
|
|
});
|
|
|
|
it('narrows err result', () => {
|
|
const r = err('bad') as ReturnType<typeof ok<number>> | ReturnType<typeof err<string>>;
|
|
if (!r.ok) {
|
|
expect(r.error).toBe('bad');
|
|
} else {
|
|
expect.unreachable();
|
|
}
|
|
});
|
|
});
|
|
});
|