[hotfix] Ignore type checking for edge
[platform/framework/web/wrtjs.git] / device_home / node_modules / arraybuffer.slice / test / slice-buffer.js
1 var sliceBuffer=require("../index.js"),expect=require("expect.js");describe("sliceBuffer",(function(){describe("using standard slice",(function(){it("should slice correctly with only start provided",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;for(var t=sliceBuffer(e.buffer,3),n=new Uint8Array(t),i=(r=3,0);r<e.length;r++,i++)expect(e[r]).to.equal(n[i])})),it("should slice correctly with start and end provided",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;for(var t=sliceBuffer(e.buffer,3,8),n=new Uint8Array(t),i=(r=3,0);r<8;r++,i++)expect(e[r]).to.equal(n[i])})),it("should slice correctly with negative start",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;for(var t=sliceBuffer(e.buffer,-3),n=new Uint8Array(t),i=(r=e.length-3,0);r<e.length;r++,i++)expect(e[r]).to.equal(n[i])})),it("should slice correctly with negative end",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;for(var t=sliceBuffer(e.buffer,0,-3),n=new Uint8Array(t),i=(r=0,0);r<e.length-3;r++,i++)expect(e[r]).to.equal(n[i])})),it("should slice correctly with negative start and end",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;for(var t=sliceBuffer(e.buffer,-6,-3),n=new Uint8Array(t),i=(r=e.length-6,0);r<e.length-3;r++,i++)expect(e[r]).to.equal(n[i])})),it("should slice correctly with equal start and end",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=sliceBuffer(e.buffer,1,1);expect(t.byteLength).to.equal(0)})),it("should slice correctly when end larger than buffer",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=sliceBuffer(e.buffer,0,100);expect(new Uint8Array(t)).to.eql(e)})),it("shoud slice correctly when start larger than end",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=sliceBuffer(e.buffer,6,5);expect(t.byteLength).to.equal(0)}))})),describe("using fallback",(function(){it("should slice correctly with only start provided",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=e.buffer;t.slice=void 0;for(var n=sliceBuffer(t,3),i=new Uint8Array(n),l=(r=3,0);r<e.length;r++,l++)expect(e[r]).to.equal(i[l])})),it("should slice correctly with start and end provided",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=e.buffer;t.slice=void 0;for(var n=sliceBuffer(t,3,8),i=new Uint8Array(n),l=(r=3,0);r<8;r++,l++)expect(e[r]).to.equal(i[l])})),it("should slice correctly with negative start",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=e.buffer;t.slice=void 0;for(var n=sliceBuffer(t,-3),i=new Uint8Array(n),l=(r=e.length-3,0);r<e.length;r++,l++)expect(e[r]).to.equal(i[l])})),it("should slice correctly with negative end",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=e.buffer;t.slice=void 0;for(var n=sliceBuffer(t,0,-3),i=new Uint8Array(n),l=(r=0,0);r<e.length-3;r++,l++)expect(e[r]).to.equal(i[l])})),it("should slice correctly with negative start and end",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=e.buffer;t.slice=void 0;for(var n=sliceBuffer(t,-6,-3),i=new Uint8Array(n),l=(r=e.length-6,0);r<e.length-3;r++,l++)expect(e[r]).to.equal(i[l])})),it("should slice correctly with equal start and end",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=e.buffer;t.slice=void 0;var n=sliceBuffer(t,1,1);expect(n.byteLength).to.equal(0)})),it("should slice correctly when end larger than buffer",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=e.buffer;t.slice=void 0;var n=sliceBuffer(t,0,100),i=new Uint8Array(n);for(r=0;r<e.length;r++)expect(e[r]).to.equal(i[r])})),it("shoud slice correctly when start larger than end",(function(){for(var e=new Uint8Array(10),r=0;r<e.length;r++)e[r]=r;var t=e.buffer;t.slice=void 0;var n=sliceBuffer(t,6,5);expect(n.byteLength).to.equal(0)}))}))}));