forked from eighttrigrams/tsfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
starts_with.spec.ts
69 lines (45 loc) · 1.74 KB
/
starts_with.spec.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
65
66
67
68
69
import {startsWith} from '../../../src/comparator'
/**
* tsfun | startsWith
*
* Tests if the right hand side argument starts with the one given on the left hand side.
*
* startsWith operates on the List abstraction over Arrays and strings.
* although here, the arguments must be both either of type string or Array,
* and in the Array case both Array must contain the same type of arguments.
*/
describe('startsWith', () => {
it('array', () => {
expect(startsWith([1, 2, 3])([1, 2, 3, 4])).toBe(true)
expect(startsWith([1, 2, 3], [1, 2, 3, 4])).toBe(true)
expect(startsWith(['a', 'b', 'c'])(['a', 'b', 'c'])).toBe(true)
expect(startsWith(['a', 'b', 'c'], ['a', 'b', 'c'])).toBe(true)
})
it('array - false - too short', () =>
expect(
startsWith([1, 2, 3], [1, 2])
).toBe(false)
)
it('array - wrong', () =>
expect(
startsWith([1, 2], [3])
).toBe(false)
)
it('array - zero length', () =>
expect(
startsWith([], [])
).toBe(true)
)
it('typing', () => {
const result3: boolean = startsWith([1, 2])([1, 2])
const result4: boolean = startsWith([1, 2], [1, 2])
// WRONG - const result: boolean = startsWith([1, 2]) - second parameter list expected, to give a boolean
// incompatible types
// WRONG const result: boolean = startsWith([1, 2], 'abc')
// WRONG const result: boolean = startsWith([1, 2])('abc')
// WRONG const result: boolean = startsWith('abc', [1, 2])
// WRONG const result: boolean = startsWith('abc')([1, 2])
// incompatible array types
// WRONG const result: boolean = startsWith([1, 2], ['a', 'b'])
})
})