deno.land / x / rambda@v9.1.1 / source / cond.spec.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { always } from './always.js'import { cond } from './cond.js'import { equals } from './equals.js'import { T } from './T.js'
test('returns a function', () => { expect(typeof cond([])).toBe('function')})
test('returns a conditional function', () => { const fn = cond([ [ equals(0), always('water freezes at 0°C') ], [ equals(100), always('water boils at 100°C') ], [ T, function (temp){ return 'nothing special happens at ' + temp + '°C' }, ], ]) expect(fn(0)).toBe('water freezes at 0°C') expect(fn(50)).toBe('nothing special happens at 50°C') expect(fn(100)).toBe('water boils at 100°C')})
test('no winner', () => { const fn = cond([ [ equals('foo'), always(1) ], [ equals('bar'), always(2) ], ]) expect(fn('quux')).toBeUndefined()})
test('predicates are tested in order', () => { const fn = cond([ [ T, always('foo') ], [ T, always('bar') ], [ T, always('baz') ], ]) expect(fn()).toBe('foo')})
test('pass all inputs',() => { cond([ [()=> true, (...x) => { expect(x).toEqual([1,2,3]) }] ])(1,2,3)})
rambda

Version Info

Tagged at
2 months ago