forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Via revealing constructor pattern. Referenced to discussion in issue nodejs/readable-stream#102 of iojs/readable-stream
- Loading branch information
Showing
7 changed files
with
245 additions
and
2 deletions.
There are no files selected for viewing
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
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
19 changes: 19 additions & 0 deletions
19
test/parallel/test-stream-readable-revealing-constructor.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var Readable = require('stream').Readable; | ||
|
||
var _readCalled = false; | ||
function _read(n) { | ||
_readCalled = true; | ||
this.push(null); | ||
} | ||
|
||
var r = new Readable({ read: _read }); | ||
r.resume(); | ||
|
||
process.on('exit', function () { | ||
assert.equal(r._read, _read); | ||
assert(_readCalled); | ||
console.log('ok'); | ||
}); |
32 changes: 32 additions & 0 deletions
32
test/parallel/test-stream-transform-revealing-constructor.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var Transform = require('stream').Transform; | ||
|
||
var _transformCalled = false; | ||
function _transform(d, e, n) { | ||
_transformCalled = true; | ||
n(); | ||
} | ||
|
||
var _flushCalled = false; | ||
function _flush(n) { | ||
_flushCalled = true; | ||
n(); | ||
} | ||
|
||
var t = new Transform({ | ||
transform: _transform, | ||
flush: _flush | ||
}); | ||
|
||
t.end(new Buffer('blerg')); | ||
t.resume(); | ||
|
||
process.on('exit', function () { | ||
assert.equal(t._transform, _transform); | ||
assert.equal(t._flush, _flush); | ||
assert(_transformCalled); | ||
assert(_flushCalled); | ||
console.log('ok'); | ||
}); |
44 changes: 44 additions & 0 deletions
44
test/parallel/test-stream-writable-revealing-constructor.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var Writable = require('stream').Writable; | ||
|
||
(function one() { | ||
var _writeCalled = false; | ||
function _write(d, e, n) { | ||
_writeCalled = true; | ||
} | ||
|
||
var w = new Writable({ write: _write }); | ||
w.end(new Buffer('blerg')); | ||
|
||
process.on('exit', function () { | ||
assert.equal(w._write, _write); | ||
assert(_writeCalled); | ||
console.log('ok 1'); | ||
}); | ||
}()); | ||
|
||
(function two() { | ||
var _writevCalled = false; | ||
var dLength = 0; | ||
|
||
function _writev(d, n) { | ||
dLength = d.length; | ||
_writevCalled = true; | ||
} | ||
|
||
var w = new Writable({ writev: _writev }); | ||
w.cork(); | ||
|
||
w.write(new Buffer('blerg')); | ||
w.write(new Buffer('blerg')); | ||
w.end(); | ||
|
||
process.on('exit', function () { | ||
assert.equal(w._writev, _writev); | ||
assert.equal(dLength, 2); | ||
assert(_writevCalled); | ||
console.log('ok 2'); | ||
}); | ||
}()); |