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

splitAt.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
48
49
50
51
52
53
54
55
56
57
58
59
60
import { splitAt as splitAtRamda } from 'ramda'
import { splitAt } from './splitAt.js'
const list = [ 1, 2, 3 ]const str = 'foo bar'
test('with array', () => { const result = splitAt(2, list) expect(result).toEqual([ [ 1, 2 ], [ 3 ] ])})
test('with array - index is negative number', () => { const result = splitAt(-6, list) expect(result).toEqual([ [], list ])})
test('with array - index is out of scope', () => { const result = splitAt(4, list) expect(result).toEqual([ [ 1, 2, 3 ], [] ])})
test('with string', () => { const result = splitAt(4, str) expect(result).toEqual([ 'foo ', 'bar' ])})
test('with string - index is negative number', () => { const result = splitAt(-2, str) expect(result).toEqual([ 'foo b', 'ar' ])})
test('with string - index is out of scope', () => { const result = splitAt(10, str) expect(result).toEqual([ str, '' ])})
test('with array - index is out of scope', () => { const result = splitAt(4)(list) expect(result).toEqual([ [ 1, 2, 3 ], [] ])})
const badInputs = [ 1, true, /foo/g, {} ]const throwingBadInputs = [ null, undefined ]
test('with bad inputs', () => { throwingBadInputs.forEach(badInput => { expect(() => splitAt(1, badInput)).toThrowWithMessage(TypeError, `Cannot read property 'slice' of ${ badInput }`) expect(() => splitAtRamda(1, badInput)).toThrowWithMessage(TypeError, `Cannot read properties of ${ badInput } (reading 'slice')`) })
badInputs.forEach(badInput => { const result = splitAt(1, badInput) const ramdaResult = splitAtRamda(1, badInput) expect(result).toEqual(ramdaResult) })})
rambda

Version Info

Tagged at
2 months ago