diff options
author | Gil Pedersen <git@gpost.dk> | 2013-03-14 17:01:14 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-03-15 03:13:10 +0400 |
commit | e8f80bf479d79bcd3c8bff7fba70aea483e66449 (patch) | |
tree | 7eaa9e752fb32e4a3937cc24d64beed396ff241e /test | |
parent | 1f53cfdeae5549a0ecacbd8cd89d60d4faf17768 (diff) |
stream: Never call decoder.end() multiple times
Updated version that does what it says without assigning state.decoder.
Diffstat (limited to 'test')
-rw-r--r-- | test/simple/test-stream2-set-encoding.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/simple/test-stream2-set-encoding.js b/test/simple/test-stream2-set-encoding.js index 8c5973fb637..931cf48f51e 100644 --- a/test/simple/test-stream2-set-encoding.js +++ b/test/simple/test-stream2-set-encoding.js @@ -74,11 +74,15 @@ TestReader.prototype._read = function(n) { setTimeout(function() { if (this.pos >= this.len) { + // double push(null) to test eos handling + this.push(null); return this.push(null); } n = Math.min(n, this.len - this.pos); if (n <= 0) { + // double push(null) to test eos handling + this.push(null); return this.push(null); } @@ -204,6 +208,41 @@ test('setEncoding hex with read(13)', function(t) { tr.emit('readable'); }); +test('setEncoding base64', function(t) { + var tr = new TestReader(100); + tr.setEncoding('base64'); + var out = []; + var expect = + [ 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYQ==' ]; + + tr.on('readable', function flow() { + var chunk; + while (null !== (chunk = tr.read(10))) + out.push(chunk); + }); + + tr.on('end', function() { + t.same(out, expect); + t.end(); + }); + + // just kick it off. + tr.emit('readable'); +}); + test('encoding: utf8', function(t) { var tr = new TestReader(100, { encoding: 'utf8' }); var out = []; @@ -310,3 +349,37 @@ test('encoding: hex with read(13)', function(t) { // just kick it off. tr.emit('readable'); }); + +test('encoding: base64', function(t) { + var tr = new TestReader(100, { encoding: 'base64' }); + var out = []; + var expect = + [ 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYWFhYWFh', + 'YWFhYWFhYW', + 'FhYQ==' ]; + + tr.on('readable', function flow() { + var chunk; + while (null !== (chunk = tr.read(10))) + out.push(chunk); + }); + + tr.on('end', function() { + t.same(out, expect); + t.end(); + }); + + // just kick it off. + tr.emit('readable'); +}); |