Browse files

Added broken test case for desired 'BufferList#take()' behavior.

It should return a Buffer instance whenever no encoding is specified
either as the last argument to 'take()', or as the 'encoding' property
on the BufferList instance. Otherwise it should return a String of
the desired encoding.
  • Loading branch information...
1 parent ae80ab3 commit 2dc22975290eb23b145c6a07ff40b897537e998e @TooTallNate TooTallNate committed Dec 30, 2010
Showing with 39 additions and 0 deletions.
  1. +39 −0 test/take.js
View
39 test/take.js
@@ -0,0 +1,39 @@
+// Test BufferList#take().
+var Buffer = require('buffer').Buffer;
+var BufferList = require('../bufferlist');
+var assert = require('assert');
+
+exports.join = function () {
+ var buf1 = new Buffer(5); buf1.write('abcde');
+ var buf2 = new Buffer(3); buf2.write('xyz');
+ var buf3 = new Buffer(5); buf3.write('11358');
+
+ var b = new BufferList;
+ b.push(buf1,buf2,buf3);
+
+ assert.eql(
+ b.take('binary'),
+ 'abcdexyz11358',
+ 'take entire BufferList at once'
+ );
+
+ assert.eql(
+ b.take(1, 'ascii'),
+ 'a',
+ 'take 1 byte with "ascii" encoding'
+ );
+
+ assert.ok(
+ Buffer.isBuffer(b.take(1)),
+ 'take without encoding returns Buffer'
+ );
+
+
+ // Now set the encoding
+ b.encoding = 'ascii';
+ assert.ok(
+ !Buffer.isBuffer(b.take(1)),
+ 'take with encoding returns String'
+ );
+};
+

0 comments on commit 2dc2297

Please sign in to comment.