diff options
Diffstat (limited to 'tst/either.test.ts')
| -rw-r--r-- | tst/either.test.ts | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tst/either.test.ts b/tst/either.test.ts index d87bcab..6f37508 100644 --- a/tst/either.test.ts +++ b/tst/either.test.ts @@ -1,4 +1,26 @@ -import { Either } from '@emprespresso/pengueno'; +import { Either } from '../lib/index'; + +describe('Either.basic', () => { + test('mapRight/mapLeft/swap', () => { + const r = Either.right<string, number>(2) + .mapRight((n) => n + 1) + .mapLeft((e) => e.toUpperCase()); + + expect(r.right().get()).toBe(3); + expect(r.swap().left().get()).toBe(3); + + const l = Either.left<string, number>('nope').mapRight((n) => n + 1); + expect(l.left().get()).toBe('nope'); + expect(l.swap().right().get()).toBe('nope'); + }); + + test('joinRight combines rights', () => { + const a = Either.right<string, number>(2); + const b = Either.right<string, number>(3); + const res = a.joinRight(b, (x, y) => x + y); + expect(res.right().get()).toBe(5); + }); +}); describe('Either.retrying', () => { beforeEach(() => { |
