Skip to content
This repository was archived by the owner on Jul 5, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function split (matcher, mapper, options) {
var maxLength = options && options.maxLength;
if('function' === typeof matcher)
mapper = matcher, matcher = null
if (!matcher)
if (typeof matcher !== "string" && !matcher)
matcher = /\r?\n/

function emit(stream, piece) {
Expand Down
38 changes: 38 additions & 0 deletions test/split.asynct.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,44 @@ exports ['split() works like String#split'] = function (test) {

}

exports ['split() handles empty string pattern like String#split'] = function (test) {
var readme = join(__filename)
, expected = fs.readFileSync(readme, 'utf-8').split('')
, cs = split('')
, actual = []
, ended = false
, x = spec(cs).through()

var a = new Stream ()

a.write = function (l) {
actual.push(l.trim())
}
a.end = function () {

ended = true
expected.forEach(function (v,k) {
//String.split will append an empty string ''
//if the string ends in a split pattern.
//es.split doesn't which was breaking this test.
//clearly, appending the empty string is correct.
//tests are passing though. which is the current job.
if(v)
it(actual[k]).like(v)
})
//give the stream time to close
process.nextTick(function () {
test.done()
x.validate()
})
}
a.writable = true

fs.createReadStream(readme, {flags: 'r'}).pipe(cs)
cs.pipe(a)

}

exports ['split() takes mapper function'] = function (test) {
var readme = join(__filename)
, expected = fs.readFileSync(readme, 'utf-8').split('\n')
Expand Down