diff options
Diffstat (limited to 'node_modules/bl/test/test.js')
-rw-r--r-- | node_modules/bl/test/test.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/node_modules/bl/test/test.js b/node_modules/bl/test/test.js index c95b1ba48..989534c91 100644 --- a/node_modules/bl/test/test.js +++ b/node_modules/bl/test/test.js @@ -53,6 +53,20 @@ tape('multi bytes from single buffer', function (t) { t.equal(bl.slice(0, 4).toString('ascii'), 'abcd') t.equal(bl.slice(0, 3).toString('ascii'), 'abc') t.equal(bl.slice(1, 4).toString('ascii'), 'bcd') + t.equal(bl.slice(-4, -1).toString('ascii'), 'abc') + + t.end() +}) + +tape('multi bytes from single buffer (negative indexes)', function (t) { + var bl = new BufferList() + bl.append(new Buffer('buffer')) + + t.equal(bl.length, 6) + + t.equal(bl.slice(-6, -1).toString('ascii'), 'buffe') + t.equal(bl.slice(-6, -2).toString('ascii'), 'buff') + t.equal(bl.slice(-5, -2).toString('ascii'), 'uff') t.end() }) @@ -72,6 +86,7 @@ tape('multiple bytes from multiple buffers', function (t) { t.equal(bl.slice(3, 6).toString('ascii'), 'def') t.equal(bl.slice(3, 8).toString('ascii'), 'defgh') t.equal(bl.slice(5, 10).toString('ascii'), 'fghij') + t.equal(bl.slice(-7, -4).toString('ascii'), 'def') t.end() }) @@ -537,6 +552,50 @@ tape('copy an interval between two buffers', function (t) { t.end() }) +tape('shallow slice across buffer boundaries', function (t) { + var bl = new BufferList(['First', 'Second', 'Third']) + + t.equal(bl.shallowSlice(3, 13).toString(), 'stSecondTh') + t.end() +}) + +tape('shallow slice within single buffer', function (t) { + var bl = new BufferList(['First', 'Second', 'Third']) + + t.equal(bl.shallowSlice(5, 10).toString(), 'Secon') + t.end() +}) + +tape('shallow slice single buffer', function (t) { + t.plan(3) + var bl = new BufferList(['First', 'Second', 'Third']) + + t.equal(bl.shallowSlice(0, 5).toString(), 'First') + t.equal(bl.shallowSlice(5, 11).toString(), 'Second') + t.equal(bl.shallowSlice(11, 16).toString(), 'Third') +}) + +tape('shallow slice with negative or omitted indices', function (t) { + t.plan(4) + var bl = new BufferList(['First', 'Second', 'Third']) + + t.equal(bl.shallowSlice().toString(), 'FirstSecondThird') + t.equal(bl.shallowSlice(5).toString(), 'SecondThird') + t.equal(bl.shallowSlice(5, -3).toString(), 'SecondTh') + t.equal(bl.shallowSlice(-8).toString(), 'ondThird') +}) + +tape('shallow slice does not make a copy', function (t) { + t.plan(1) + var buffers = [new Buffer('First'), new Buffer('Second'), new Buffer('Third')] + var bl = (new BufferList(buffers)).shallowSlice(5, -3) + + buffers[1].fill('h') + buffers[2].fill('h') + + t.equal(bl.toString(), 'hhhhhhhh') +}) + tape('duplicate', function (t) { t.plan(2) |