-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14e8828
commit 2bb6a6a
Showing
62 changed files
with
728 additions
and
2,125 deletions.
There are no files selected for viewing
21 changes: 0 additions & 21 deletions
21
test/simple/test-stream-big-packet.js → test/parallel/test-stream-big-packet.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
test/simple/test-stream-big-push.js → test/parallel/test-stream-big-push.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var Duplex = require('../../').Transform; | ||
|
||
var stream = new Duplex({ objectMode: true }); | ||
|
||
assert(stream._readableState.objectMode); | ||
assert(stream._writableState.objectMode); | ||
|
||
var written; | ||
var read; | ||
|
||
stream._write = function (obj, _, cb) { | ||
written = obj; | ||
cb(); | ||
}; | ||
|
||
stream._read = function () {}; | ||
|
||
stream.on('data', function (obj) { | ||
read = obj; | ||
}); | ||
|
||
stream.push({ val: 1 }); | ||
stream.end({ val: 2 }); | ||
|
||
process.on('exit', function () { | ||
assert(read.val === 1); | ||
assert(written.val === 2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var gotEnd = false; | ||
|
||
// Make sure we don't miss the end event for paused 0-length streams | ||
|
||
var Readable = require('../../').Readable; | ||
var stream = new Readable(); | ||
var calledRead = false; | ||
stream._read = function() { | ||
assert(!calledRead); | ||
calledRead = true; | ||
this.push(null); | ||
}; | ||
|
||
stream.on('data', function() { | ||
throw new Error('should not ever get data'); | ||
}); | ||
stream.pause(); | ||
|
||
setTimeout(function() { | ||
stream.on('end', function() { | ||
gotEnd = true; | ||
}); | ||
stream.resume(); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert(gotEnd); | ||
assert(calledRead); | ||
console.log('ok'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var assert = require('assert'); | ||
var common = require('../common'); | ||
|
||
var stream = require('../../'); | ||
|
||
var readable = new stream.Readable; | ||
|
||
// _read is a noop, here. | ||
readable._read = Function(); | ||
|
||
// default state of a stream is not "paused" | ||
assert.ok(!readable.isPaused()); | ||
|
||
// make the stream start flowing... | ||
readable.on('data', Function()); | ||
|
||
// still not paused. | ||
assert.ok(!readable.isPaused()); | ||
|
||
readable.pause(); | ||
assert.ok(readable.isPaused()); | ||
readable.resume(); | ||
assert.ok(!readable.isPaused()); |
21 changes: 0 additions & 21 deletions
21
test/simple/test-stream-pipe-after-end.js → test/parallel/test-stream-pipe-after-end.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
test/simple/test-stream-pipe-cleanup.js → test/parallel/test-stream-pipe-cleanup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
...simple/test-stream-pipe-error-handling.js → ...rallel/test-stream-pipe-error-handling.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var common = require('../common'); | ||
var stream = require('../../'); | ||
var assert = require('assert'); | ||
var util = require('util'); | ||
|
||
function Writable() { | ||
this.writable = true; | ||
require('stream').Stream.call(this); | ||
} | ||
util.inherits(Writable, require('stream').Stream); | ||
|
||
function Readable() { | ||
this.readable = true; | ||
require('stream').Stream.call(this); | ||
} | ||
util.inherits(Readable, require('stream').Stream); | ||
|
||
var passed = false; | ||
|
||
var w = new Writable(); | ||
w.on('pipe', function(src) { | ||
passed = true; | ||
}); | ||
|
||
var r = new Readable(); | ||
r.pipe(w); | ||
|
||
assert.ok(passed); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var common = require('../common.js'); | ||
var Readable = require('../../').Readable; | ||
var assert = require('assert'); | ||
|
||
var s = new Readable({ | ||
highWaterMark: 20, | ||
encoding: 'ascii' | ||
}); | ||
|
||
var list = ['1', '2', '3', '4', '5', '6']; | ||
|
||
s._read = function (n) { | ||
var one = list.shift(); | ||
if (!one) { | ||
s.push(null); | ||
} else { | ||
var two = list.shift(); | ||
s.push(one); | ||
s.push(two); | ||
} | ||
}; | ||
|
||
var v = s.read(0); | ||
|
||
// ACTUALLY [1, 3, 5, 6, 4, 2] | ||
|
||
process.on("exit", function () { | ||
assert.deepEqual(s._readableState.buffer, | ||
['1', '2', '3', '4', '5', '6']); | ||
console.log("ok"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var Readable = require('../../').Readable; | ||
var util = require('util'); | ||
|
||
util.inherits(MyStream, Readable); | ||
function MyStream(options) { | ||
Readable.call(this, options); | ||
this._chunks = 3; | ||
} | ||
|
||
MyStream.prototype._read = function(n) { | ||
switch (this._chunks--) { | ||
case 0: | ||
return this.push(null); | ||
case 1: | ||
return setTimeout(function() { | ||
this.push('last chunk'); | ||
}.bind(this), 100); | ||
case 2: | ||
return this.push('second to last chunk'); | ||
case 3: | ||
return process.nextTick(function() { | ||
this.push('first chunk'); | ||
}.bind(this)); | ||
default: | ||
throw new Error('?'); | ||
} | ||
}; | ||
|
||
var ms = new MyStream(); | ||
var results = []; | ||
ms.on('readable', function() { | ||
var chunk; | ||
while (null !== (chunk = ms.read())) | ||
results.push(chunk + ''); | ||
}); | ||
|
||
var expect = [ 'first chunksecond to last chunk', 'last chunk' ]; | ||
process.on('exit', function() { | ||
assert.equal(ms._chunks, -1); | ||
assert.deepEqual(results, expect); | ||
console.log('ok'); | ||
}); |
21 changes: 0 additions & 21 deletions
21
test/simple/test-stream-readable-event.js → test/parallel/test-stream-readable-event.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
...le/test-stream-readable-flow-recursion.js → ...el/test-stream-readable-flow-recursion.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.