-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathsplit.js
More file actions
38 lines (34 loc) · 1.27 KB
/
split.js
File metadata and controls
38 lines (34 loc) · 1.27 KB
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
import v from '../voca';
describe('split', function() {
it('should split a string into chunks', function() {
expect(v.split('stellar bomb', ' ')).toEqual(['stellar', 'bomb']);
expect(v.split(' ', ' ')).toEqual(['', '', '', '']);
expect(v.split('dying star', /\s/)).toEqual(['dying', 'star']);
expect(v.split('*dying*star*', /\*/)).toEqual(['', 'dying', 'star', '']);
expect(v.split('', '')).toEqual([]);
expect(v.split('star', '')).toEqual(['s', 't', 'a', 'r']);
});
it('should split a number into chunks', function() {
expect(v.split(0)).toEqual(['0']);
expect(v.split(1560, '6')).toEqual(['15', '0']);
expect(v.split(-1.6, /\./)).toEqual(['-1', '6']);
});
it('should split the string representation of an object', function() {
expect(v.split('rising star', ' ')).toEqual(['rising', 'star']);
expect(
v.split(
{
toString: function() {
return 'rising-star';
},
},
/\-/
)
).toEqual(['rising', 'star']);
});
it('should return the string as an item of an array for an empty separator', function() {
expect(v.split('star')).toEqual(['star']);
expect(v.split('star', null)).toEqual(['star']);
expect(v.split('star', undefined)).toEqual(['star']);
});
});