diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5f19d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json diff --git a/README.md b/README.md index 81c5a97..10decef 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,11 @@ pull( ### merge(left, right, compare?) -return a stream that is the merge of left and right streams. -merge pulls a chunk from both `left` and `right` and then -compares them. `compare` has the same signature as `Array#sort(compare)`. -If the two chunks are compared the same, the chunk from the right stream +Return a stream that is the merge of left and right streams. + +merge pulls a chunk from both `left` and `right` and then compares them. +`compare` has a similar signature as `Array#sort(compare)` +**but if the two chunks are compared the same**, the chunk from the right stream is taken, but the left chunk is dropped. Otherwise, the lowest chunk is passed to the stream. diff --git a/test/index.js b/test/index.js index 2a7abef..e0a1e18 100644 --- a/test/index.js +++ b/test/index.js @@ -1,4 +1,3 @@ - var tape = require('tape') var pull = require('pull-stream') @@ -9,7 +8,7 @@ tape('empty', function (t) { pull( merge(pull.values([]), pull.values([])), pull.collect(function (err, ary) { - console.log(ary) + // console.log(ary) t.deepEqual(ary, []) t.end() }) @@ -22,7 +21,7 @@ tape('equal', function (t) { pull( merge(pull.values([1]), pull.values([1])), pull.collect(function (err, ary) { - console.log(ary) + // console.log(ary) t.deepEqual(ary, [1]) t.end() }) @@ -35,7 +34,7 @@ tape('different', function (t) { pull( merge(pull.values([1]), pull.values([2])), pull.collect(function (err, ary) { - console.log(ary) + // console.log(ary) t.deepEqual(ary, [1, 2]) t.end() }) @@ -48,7 +47,7 @@ tape('different', function (t) { pull( merge(pull.values([2, 3]), pull.values([1])), pull.collect(function (err, ary) { - console.log(ary) + // console.log(ary) t.deepEqual(ary, [1, 2, 3]) t.end() }) @@ -56,15 +55,13 @@ tape('different', function (t) { }) -return - - +// return tape('simple', function (t) { pull( merge(pull.values([0, 2, 4, 6]), pull.values([1,3,5,7])), pull.collect(function (err, ary) { - console.log(ary) + // console.log(ary) t.deepEqual(ary, [0,1,2,3,4,5,6,7]) t.end() }) @@ -72,13 +69,13 @@ tape('simple', function (t) { }) -return +// return tape('overwrite', function (t) { pull( merge(pull.values([0, 2, 3, 5, 6]), pull.values([1,4,5,7])), pull.collect(function (err, ary) { t.deepEqual(ary, [0,1,2,3,4,5,6,7]) - console.log(ary) + // console.log(ary) t.end() }) ) diff --git a/test/merge.js b/test/merge.js index fb0ab95..d49b59c 100644 --- a/test/merge.js +++ b/test/merge.js @@ -1,15 +1,19 @@ var async = require('interleavings') var pull = require('pull-stream') -var assert = require('assert') +var tape = require('tape') var merge = require('../') -async.test(strange, function (err, results, stats) { - console.log(results) - assert.equal(stats.failures, 0) - console.log('passed') +tape('merge.js', t => { + t.plan(101) + async.test(strange(t), function (err, results, stats) { + // console.log(results) + t.equal(stats.failures, 0, 'no failures') }) -function strange (async) { +}) + +function strange (t) { + return function (async) { function p (read) { return function (abort, cb) { @@ -29,20 +33,20 @@ function strange (async) { function (read) { return function (abort, cb) { read(abort, function (end, data) { - console.log(end, data) + // console.log(end, data) cb(end, data) }) } }, pull.collect(function (err, ary) { - console.log(ary) + // console.log(ary) - assert.deepEqual(ary, [1,2,3,4,5,6,7,8,9,10,11,12]) + t.deepEqual(ary, [1,2,3,4,5,6,7,8,9,10,11,12]) async.done() }) ) - } +} //strange(async(17, function (err, result) { // if(result.error)