diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 22:39:18 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 22:39:18 -0800 |
| commit | 666674327f009e9b1013218fc384f193b64c6997 (patch) | |
| tree | acebae7b425b469584eb0a5bec396899c2739501 /tst/either.test.ts | |
| parent | 594ce452693a71b501d3aff3f35ef3732c06c341 (diff) | |
| download | pengueno-666674327f009e9b1013218fc384f193b64c6997.tar.gz pengueno-666674327f009e9b1013218fc384f193b64c6997.zip | |
Adds unit tests
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(() => { |
