-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest.js
More file actions
29 lines (26 loc) · 1.07 KB
/
test.js
File metadata and controls
29 lines (26 loc) · 1.07 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
import test from 'ava';
import splitOnFirst from './index.js';
test('main', t => {
t.deepEqual(splitOnFirst('a-b-c', '-'), ['a', 'b-c']);
t.deepEqual(splitOnFirst('key:value:value2', ':'), ['key', 'value:value2']);
t.deepEqual(splitOnFirst('a---b---c', '---'), ['a', 'b---c']);
t.deepEqual(splitOnFirst('a-b-c', '+'), []);
t.deepEqual(splitOnFirst('abc', ''), []);
t.deepEqual(splitOnFirst('', ''), []);
t.throws(() => {
splitOnFirst('abc', null);
}, {
instanceOf: TypeError,
message: 'Expected `separator` to be of type `string` or `RegExp`',
});
});
test('regex', t => {
t.deepEqual(splitOnFirst('a,b,c', /[.,]/), ['a', 'b,c']);
t.deepEqual(splitOnFirst('abc', /z/), []);
t.deepEqual(splitOnFirst('hello world test', /\s/), ['hello', 'world test']);
t.deepEqual(splitOnFirst('a+b+c', /\+/), ['a', 'b+c']);
t.deepEqual(splitOnFirst('aaa-bbb', /a+/), ['', '-bbb']);
t.deepEqual(splitOnFirst('Hello-World', /hello/i), ['', '-World']);
t.deepEqual(splitOnFirst('a-b-c-d', /-/g), ['a', 'b-c-d']);
t.deepEqual(splitOnFirst('hello🚀world', /🚀/), ['hello', 'world']);
});