(decode, uncork, multi, next)
| 45 | } |
| 46 | |
| 47 | function test(decode, uncork, multi, next) { |
| 48 | console.log(`# decode=${decode} uncork=${uncork} multi=${multi}`); |
| 49 | let counter = 0; |
| 50 | let expectCount = 0; |
| 51 | function cnt(msg) { |
| 52 | expectCount++; |
| 53 | const expect = expectCount; |
| 54 | return common.mustSucceed(() => { |
| 55 | counter++; |
| 56 | assert.strictEqual(counter, expect); |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | const w = new stream.Writable({ decodeStrings: decode }); |
| 61 | w._write = common.mustNotCall('Should not call _write'); |
| 62 | |
| 63 | const expectChunks = decode ? [ |
| 64 | { encoding: 'buffer', |
| 65 | chunk: [104, 101, 108, 108, 111, 44, 32] }, |
| 66 | { encoding: 'buffer', |
| 67 | chunk: [119, 111, 114, 108, 100] }, |
| 68 | { encoding: 'buffer', |
| 69 | chunk: [33] }, |
| 70 | { encoding: 'buffer', |
| 71 | chunk: [10, 97, 110, 100, 32, 116, 104, 101, 110, 46, 46, 46] }, |
| 72 | { encoding: 'buffer', |
| 73 | chunk: [250, 206, 190, 167, 222, 173, 190, 239, 222, 202, 251, 173] }, |
| 74 | ] : [ |
| 75 | { encoding: 'ascii', chunk: 'hello, ' }, |
| 76 | { encoding: 'utf8', chunk: 'world' }, |
| 77 | { encoding: 'buffer', chunk: [33] }, |
| 78 | { encoding: 'latin1', chunk: '\nand then...' }, |
| 79 | { encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' }, |
| 80 | ]; |
| 81 | |
| 82 | let actualChunks; |
| 83 | w._writev = function(chunks, cb) { |
| 84 | actualChunks = chunks.map(function(chunk) { |
| 85 | return { |
| 86 | encoding: chunk.encoding, |
| 87 | chunk: Buffer.isBuffer(chunk.chunk) ? |
| 88 | Array.prototype.slice.call(chunk.chunk) : chunk.chunk |
| 89 | }; |
| 90 | }); |
| 91 | cb(); |
| 92 | }; |
| 93 | |
| 94 | w.cork(); |
| 95 | w.write('hello, ', 'ascii', cnt('hello')); |
| 96 | w.write('world', 'utf8', cnt('world')); |
| 97 | |
| 98 | if (multi) |
| 99 | w.cork(); |
| 100 | |
| 101 | w.write(Buffer.from('!'), 'buffer', cnt('!')); |
| 102 | w.write('\nand then...', 'latin1', cnt('and then')); |
| 103 | |
| 104 | if (multi) |
no test coverage detected
searching dependent graphs…