-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.test.ts
64 lines (58 loc) · 1.67 KB
/
function.test.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import * as fn from './function.ts'
import { describe, it } from 'node:test'
import * as assert from 'assert'
import { Binary, Unary } from './data.ts'
const add: Binary<number, number, number> = a => b => a + b
const str: Unary<any, string> = x => x + ''
describe('function', () => {
describe('pipe', () => {
it('should pipe the end of one function into the start of the next', () => {
assert.equal(
fn.pipe(
1,
add(1),
add(1),
add(1),
add(1),
),
5
)
})
it('should do nothing without functions', () => {
assert.equal(
// @ts-ignore
fn.pipe(1),
1
)
})
})
describe('compose', () => {
it('should compose functions left-to-right', () => {
assert.equal(
fn.compose(
add(1),
add(1),
str,
)(1),
'3'
)
})
it('should create the id function without arguments', () => {
assert.equal(
// @ts-ignore
fn.compose()(1),
1
)
})
})
describe('once', () => {
it('should only allow a function to be called once', () => {
const test = fn.spy(() => true)
const once_test = fn.once(test)
once_test()
const result = once_test()
assert.equal(result, undefined)
assert.equal(test.calls.length, 1)
})
})
})