diff options
author | Jeff Barczewski <jeff.barczewski@gmail.com> | 2013-03-30 22:32:06 -0500 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2013-07-03 15:07:01 -0700 |
commit | 26ca7d73ca9c45112f33579aa5a1293059010779 (patch) | |
tree | fc836a8f6d36f8f0e8e92f7c230f8bccda0744d0 /test | |
parent | 278183a902d50f63e334c0ecde52c0186a523192 (diff) | |
download | node-26ca7d73ca9c45112f33579aa5a1293059010779.tar.gz |
stream: objectMode transform should allow falsey values
If a transform stream has objectMode = true, it should
allow falsey values other than (null) like 0, false, ''.
null is reserved to indicate stream eof but other falsey
values should flow through properly.
Diffstat (limited to 'test')
-rw-r--r-- | test/simple/test-stream2-transform.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/simple/test-stream2-transform.js b/test/simple/test-stream2-transform.js index 7a32a3cce..9a7778b09 100644 --- a/test/simple/test-stream2-transform.js +++ b/test/simple/test-stream2-transform.js @@ -104,6 +104,28 @@ test('passthrough', function(t) { t.end(); }); +test('object passthrough', function (t) { + var pt = new PassThrough({ objectMode: true }); + + pt.write(1); + pt.write(true); + pt.write(false); + pt.write(0); + pt.write('foo'); + pt.write(''); + pt.write({ a: 'b'}); + pt.end(); + + t.equal(pt.read(), 1); + t.equal(pt.read(), true); + t.equal(pt.read(), false); + t.equal(pt.read(), 0); + t.equal(pt.read(), 'foo'); + t.equal(pt.read(), ''); + t.same(pt.read(), { a: 'b'}); + t.end(); +}); + test('simple transform', function(t) { var pt = new Transform; pt._transform = function(c, e, cb) { @@ -126,6 +148,32 @@ test('simple transform', function(t) { t.end(); }); +test('simple object transform', function(t) { + var pt = new Transform({ objectMode: true }); + pt._transform = function(c, e, cb) { + pt.push(JSON.stringify(c)); + cb(); + }; + + pt.write(1); + pt.write(true); + pt.write(false); + pt.write(0); + pt.write('foo'); + pt.write(''); + pt.write({ a: 'b'}); + pt.end(); + + t.equal(pt.read(), '1'); + t.equal(pt.read(), 'true'); + t.equal(pt.read(), 'false'); + t.equal(pt.read(), '0'); + t.equal(pt.read(), '"foo"'); + t.equal(pt.read(), '""'); + t.equal(pt.read(), '{"a":"b"}'); + t.end(); +}); + test('async passthrough', function(t) { var pt = new Transform; pt._transform = function(chunk, encoding, cb) { |