@@ -2,6 +2,8 @@ var test = require('tape')
2
2
var fs = require ( 'fs' )
3
3
var split = require ( './' )
4
4
5
+ var bufferFrom = Buffer . from && Buffer . from !== Uint8Array . from
6
+
5
7
function splitTest ( matcher , cb ) {
6
8
if ( ! cb ) {
7
9
cb = matcher
@@ -35,27 +37,31 @@ test('custom matcher', function (t) {
35
37
t . equals ( items . length , 5 )
36
38
t . equals ( items . join ( ' ' ) , 'hello yes this is dog' )
37
39
t . end ( )
40
+ } ) ;
41
+
42
+ [ 'hello yes ' , 'this' , ' is d' , 'og' ] . map ( function ( chunk ) {
43
+ return bufferFrom ? Buffer . from ( chunk ) : new Buffer ( chunk )
44
+ } ) . forEach ( function ( chunk ) {
45
+ splitStream . write ( chunk )
38
46
} )
39
- splitStream . write ( new Buffer ( 'hello yes ' ) )
40
- splitStream . write ( new Buffer ( 'this' ) )
41
- splitStream . write ( new Buffer ( ' is d' ) )
42
- splitStream . write ( new Buffer ( 'og' ) )
43
47
splitStream . end ( )
44
48
} )
45
49
46
50
test ( 'long matcher' , function ( t ) {
51
+ var data = 'hello yes this is dog'
47
52
var splitStream = splitTest ( 'this' , function ( err , items ) {
48
53
if ( err ) throw err
49
54
t . equals ( items . length , 2 )
50
55
t . equals ( items [ 0 ] . toString ( ) , 'hello yes ' )
51
56
t . equals ( items [ 1 ] . toString ( ) , ' is dog' )
52
57
t . end ( )
53
58
} )
54
- splitStream . write ( new Buffer ( 'hello yes this is dog' ) )
59
+ splitStream . write ( bufferFrom ? Buffer . from ( data ) : new Buffer ( data ) )
55
60
splitStream . end ( )
56
61
} )
57
62
58
63
test ( 'matcher at index 0 check' , function ( t ) {
64
+ var data = '\nhello\nmax'
59
65
var splitStream = splitTest ( function ( err , items ) {
60
66
if ( err ) throw err
61
67
@@ -65,7 +71,7 @@ test('matcher at index 0 check', function (t) {
65
71
t . end ( )
66
72
} )
67
73
68
- splitStream . write ( new Buffer ( '\nhello\nmax' ) )
74
+ splitStream . write ( bufferFrom ? Buffer . from ( data ) : new Buffer ( data ) )
69
75
splitStream . end ( )
70
76
} )
71
77
0 commit comments