1var Readable = require('stream').Readable 2var tape = require('tape') 3var union = require('./') 4 5tape('numbers', function (t) { 6 var a = new Readable({objectMode: true}) 7 var b = new Readable({objectMode: true}) 8 a._read = b._read = function () {} 9 10 a.push(4) 11 a.push(6) 12 a.push(10) 13 a.push(14) 14 a.push(15) 15 a.push(20) 16 a.push(22) 17 a.push(null) 18 19 b.push(6) 20 b.push(11) 21 b.push(20) 22 b.push(null) 23 24 var u = union(a, b) 25 var expected = [4, 6, 10, 11, 14, 15, 20, 22] 26 27 u.on('data', function (data) { 28 t.same(data, expected.shift()) 29 }) 30 31 u.on('end', function () { 32 t.same(expected.length, 0, 'no more data') 33 t.end() 34 }) 35}) 36 37tape('string', function (t) { 38 var a = new Readable({objectMode: true}) 39 var b = new Readable({objectMode: true}) 40 a._read = b._read = function () {} 41 42 a.push('04') 43 a.push('06') 44 a.push('10') 45 a.push('14') 46 a.push('15') 47 a.push('20') 48 a.push('22') 49 a.push(null) 50 51 b.push('06') 52 b.push('11') 53 b.push('20') 54 b.push(null) 55 56 var u = union(a, b) 57 var expected = ['04', '06', '10', '11', '14', '15', '20', '22'] 58 59 u.on('data', function (data) { 60 t.same(data, expected.shift()) 61 }) 62 63 u.on('end', function () { 64 t.same(expected.length, 0, 'no more data') 65 t.end() 66 }) 67}) 68 69tape('objects', function (t) { 70 var a = new Readable({objectMode: true}) 71 var b = new Readable({objectMode: true}) 72 a._read = b._read = function () {} 73 74 a.push({key: '04'}) 75 a.push({key: '06'}) 76 a.push({key: '10'}) 77 a.push({key: '14'}) 78 a.push({key: '15'}) 79 a.push({key: '20'}) 80 a.push({key: '22'}) 81 a.push(null) 82 83 b.push({key: '06'}) 84 b.push({key: '11'}) 85 b.push({key: '20'}) 86 b.push(null) 87 88 var u = union(a, b) 89 var expected = [{key: '04'}, {key: '06'}, {key: '10'}, {key: '11'}, {key: '14'}, {key: '15'}, {key: '20'}, {key: '22'}] 90 91 u.on('data', function (data) { 92 t.same(data, expected.shift()) 93 }) 94 95 u.on('end', function () { 96 t.same(expected.length, 0, 'no more data') 97 t.end() 98 }) 99}) 100 101tape('custom objects', function (t) { 102 var a = new Readable({objectMode: true}) 103 var b = new Readable({objectMode: true}) 104 a._read = b._read = function () {} 105 106 a.push({bar: '04'}) 107 a.push({bar: '06'}) 108 a.push({bar: '10'}) 109 a.push({bar: '14'}) 110 a.push({bar: '15'}) 111 a.push({bar: '20'}) 112 a.push({bar: '22'}) 113 a.push(null) 114 115 b.push({bar: '06'}) 116 b.push({bar: '11'}) 117 b.push({bar: '20'}) 118 b.push(null) 119 120 var u = union(a, b, function (data) { 121 return data.bar 122 }) 123 124 var expected = [{bar: '04'}, {bar: '06'}, {bar: '10'}, {bar: '11'}, {bar: '14'}, {bar: '15'}, {bar: '20'}, {bar: '22'}] 125 126 u.on('data', function (data) { 127 t.same(data, expected.shift()) 128 }) 129 130 u.on('end', function () { 131 t.same(expected.length, 0, 'no more data') 132 t.end() 133 }) 134}) 135 136tape('destroy stream', function (t) { 137 var a = new Readable({objectMode: true}) 138 var b = new Readable({objectMode: true}) 139 140 a._read = function () {} 141 b._read = function () {} 142 143 t.plan(2) 144 145 a.destroy = function () { 146 t.ok(true) 147 } 148 149 b.destroy = function () { 150 t.ok(true) 151 } 152 153 union(a, b).destroy() 154}) 155