|
1 | 1 | import { describe, expect, it } from 'bun:test'; |
2 | 2 | import { pipe } from 'rambda'; |
3 | 3 | import { |
| 4 | + all, |
4 | 5 | chain, |
5 | 6 | equals, |
6 | 7 | Err, |
@@ -361,4 +362,34 @@ describe('Result - Curried Helpers', () => { |
361 | 362 | const result = pipe(new Err('Error'), equals(new Err('Different Error'))); |
362 | 363 | expect(result).toBe(false); |
363 | 364 | }); |
| 365 | + |
| 366 | + it('all should return Ok with all values when all are Ok', () => { |
| 367 | + const results = [ok<number, string>(1), ok<number, string>(2), ok<number, string>(3)]; |
| 368 | + const result = all(results); |
| 369 | + expect(result.isOk()).toBe(true); |
| 370 | + expect(result.unwrapOr([])).toEqual([1, 2, 3]); |
| 371 | + }); |
| 372 | + |
| 373 | + it('all should return Err with all errors when any are Err', () => { |
| 374 | + const results = [ok<number, string>(1), err<number, string>('error1'), err<number, string>('error2')]; |
| 375 | + const result = all(results); |
| 376 | + expect(result.isErr()).toBe(true); |
| 377 | + expect(result.match({ ok: (_) => [], err: (e) => e })).toEqual(['error1', 'error2']); |
| 378 | + }); |
| 379 | + |
| 380 | + it('all should return Ok with empty array for empty input', () => { |
| 381 | + const result = all<number, string>([]); |
| 382 | + expect(result.isOk()).toBe(true); |
| 383 | + expect(result.unwrapOr([])).toEqual([]); |
| 384 | + }); |
| 385 | + |
| 386 | + it('all should collect all errors from multiple Err', () => { |
| 387 | + const results = [ |
| 388 | + err<number, string>('Name required'), |
| 389 | + err<number, string>('Email invalid'), |
| 390 | + err<number, string>('Age too low'), |
| 391 | + ]; |
| 392 | + const result = all(results); |
| 393 | + expect(result.match({ ok: (_) => [], err: (e) => e })).toEqual(['Name required', 'Email invalid', 'Age too low']); |
| 394 | + }); |
364 | 395 | }); |
0 commit comments