File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,16 @@ import _split from './_split.js';
9
9
* @param {Node } z Node to split at.
10
10
*/
11
11
export default function split ( x , z ) {
12
- assert ( x instanceof Node ) ;
13
- assert ( z instanceof Node ) ;
14
12
if ( x === z ) {
15
13
return [ null , x ] ;
16
14
}
17
15
16
+ assert ( x instanceof Node ) ;
17
+ if ( z === null ) {
18
+ return [ x , null ] ;
19
+ }
20
+
21
+ assert ( z instanceof Node ) ;
18
22
_split ( z ) ;
19
23
return [ x , z ] ;
20
24
}
Original file line number Diff line number Diff line change
1
+ import test from 'ava' ;
2
+
3
+ import { list } from '@iterable-iterator/list' ;
4
+
5
+ import { str } from './_fixtures.js' ;
6
+
7
+ import { from , values , split } from '#module' ;
8
+
9
+ const macro = test . macro ( {
10
+ exec ( t , sequence , i ) {
11
+ const x = from ( sequence ) ;
12
+ let y = x ;
13
+ for ( let k = 0 ; k < i ; ++ k ) y = y . next ;
14
+ const [ s1 , s2 ] = split ( x , y ) ;
15
+ if ( x === y ) {
16
+ t . is ( s1 , null ) ;
17
+ t . is ( s2 , x ) ;
18
+ } else {
19
+ t . is ( s1 , x ) ;
20
+ t . is ( s2 , y ) ;
21
+ }
22
+
23
+ const left = list ( values ( s1 ) ) . join ( '' ) ;
24
+ const right = list ( values ( s2 ) ) . join ( '' ) ;
25
+ const expected = [ sequence . slice ( 0 , i ) , sequence . slice ( i ) ] ;
26
+ t . deepEqual ( [ left , right ] , expected ) ;
27
+ } ,
28
+ title ( title , sequence , i ) {
29
+ return title ?? `split(${ str ( sequence ) } , ${ i } )` ;
30
+ } ,
31
+ } ) ;
32
+
33
+ test ( macro , '' , 0 ) ;
34
+ test ( macro , 'a' , 0 ) ;
35
+ test ( macro , 'a' , 1 ) ;
36
+ test ( macro , 'ab' , 0 ) ;
37
+ test ( macro , 'ab' , 1 ) ;
38
+ test ( macro , 'ab' , 2 ) ;
39
+ test ( macro , 'abc' , 0 ) ;
40
+ test ( macro , 'abc' , 1 ) ;
41
+ test ( macro , 'abc' , 2 ) ;
42
+ test ( macro , 'abc' , 3 ) ;
43
+ test ( macro , 'abcd' , 0 ) ;
44
+ test ( macro , 'abcd' , 1 ) ;
45
+ test ( macro , 'abcd' , 2 ) ;
46
+ test ( macro , 'abcd' , 3 ) ;
47
+ test ( macro , 'abcd' , 4 ) ;
You can’t perform that action at this time.
0 commit comments