From bdaeb8b6a32613047cd36244d0569a45fb2aa7f7 Mon Sep 17 00:00:00 2001 From: Rainer Dreyer Date: Fri, 16 Nov 2012 02:21:06 +0200 Subject: [PATCH] Added tests Added unit tests and removed unnecessary string conversion. --- index.js | 4 ---- test/buffer.js | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 258695d..522dd93 100644 --- a/index.js +++ b/index.js @@ -416,10 +416,6 @@ Buffer.concat = function (list, totalLength) { var pos = 0; for (var i = 0; i < list.length; i++) { var buf = list[i]; - // To deal with string objects - if (!Buffer.isBuffer(buf)) { - buf = new Buffer(buf); - } buf.copy(buffer, pos); pos += buf.length; } diff --git a/test/buffer.js b/test/buffer.js index 4486602..f54c5d2 100644 --- a/test/buffer.js +++ b/test/buffer.js @@ -73,7 +73,7 @@ test('hex buffer to ascii', function (t) { t.end(); }); -test("hex of write{Uint,Int}{8,16,32}{LE,BE}", function(t) { +test("hex of write{Uint,Int}{8,16,32}{LE,BE}", function (t) { t.plan(2*(2*2*2+2)); ["UInt","Int"].forEach(function(x){ [8,16,32].forEach(function(y){ @@ -99,3 +99,23 @@ test("hex of write{Uint,Int}{8,16,32}{LE,BE}", function(t) { }); t.end(); }); + +test("concat() a varying number of buffers", function (t) { + t.plan(5); + var zero = []; + var one = [ new buffer.Buffer('asdf') ]; + var long = []; + for (var i = 0; i < 10; i++) long.push(new buffer.Buffer('asdf')); + + var flatZero = buffer.Buffer.concat(zero); + var flatOne = buffer.Buffer.concat(one); + var flatLong = buffer.Buffer.concat(long); + var flatLongLen = buffer.Buffer.concat(long, 40); + + t.equal(flatZero.length, 0); + t.equal(flatOne.toString(), 'asdf'); + t.equal(flatOne, one[0]); + t.equal(flatLong.toString(), (new Array(10+1).join('asdf'))); + t.equal(flatLongLen.toString(), (new Array(10+1).join('asdf'))); + t.end(); +}); -- 2.34.1