From: Feross Aboukhadijeh Date: Fri, 2 Dec 2016 20:22:33 +0000 (-0600) Subject: test: remove checks for TYPED_ARRAY_SUPPORT X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=85caf8ae6f654a19c1e95948c65a291d0ba1f811;p=buffer.git test: remove checks for TYPED_ARRAY_SUPPORT We only support browsers with typed arrays now, so this is a pointless check. --- diff --git a/test/basic.js b/test/basic.js index b289b3a..b30c507 100644 --- a/test/basic.js +++ b/test/basic.js @@ -8,15 +8,11 @@ test('instanceof Buffer', function (t) { }) test('convert to Uint8Array in modern browsers', function (t) { - if (B.TYPED_ARRAY_SUPPORT) { - var buf = new B([1, 2]) - var uint8array = new Uint8Array(buf.buffer) - t.ok(uint8array instanceof Uint8Array) - t.equal(uint8array[0], 1) - t.equal(uint8array[1], 2) - } else { - t.pass('object impl: skipping test') - } + var buf = new B([1, 2]) + var uint8array = new Uint8Array(buf.buffer) + t.ok(uint8array instanceof Uint8Array) + t.equal(uint8array[0], 1) + t.equal(uint8array[1], 2) t.end() }) @@ -50,11 +46,8 @@ test('setting index value should modify buffer contents', function (t) { test('storing negative number should cast to unsigned', function (t) { var buf = new B(1) - if (B.TYPED_ARRAY_SUPPORT) { - // This does not work with the object implementation -- nothing we can do! - buf[0] = -3 - t.equal(buf[0], 253) - } + buf[0] = -3 + t.equal(buf[0], 253) buf = new B(1) buf.writeInt8(-3, 0) @@ -64,21 +57,17 @@ test('storing negative number should cast to unsigned', function (t) { }) test('test that memory is copied from array-like', function (t) { - if (B.TYPED_ARRAY_SUPPORT) { - var u = new Uint8Array(4) - var b = new B(u) - b[0] = 1 - b[1] = 2 - b[2] = 3 - b[3] = 4 + var u = new Uint8Array(4) + var b = new B(u) + b[0] = 1 + b[1] = 2 + b[2] = 3 + b[3] = 4 - t.equal(u[0], 0) - t.equal(u[1], 0) - t.equal(u[2], 0) - t.equal(u[3], 0) - } else { - t.pass('object impl: skipping test') - } + t.equal(u[0], 0) + t.equal(u[1], 0) + t.equal(u[2], 0) + t.equal(u[3], 0) t.end() }) diff --git a/test/constructor.js b/test/constructor.js index b3e3240..96dd2f9 100644 --- a/test/constructor.js +++ b/test/constructor.js @@ -55,27 +55,25 @@ test('new buffer from ArrayBuffer', function (t) { }) test('new buffer from ArrayBuffer, shares memory', function (t) { - if (Buffer.TYPED_ARRAY_SUPPORT) { - var u = new Uint8Array([0, 1, 2, 3]) - var arraybuffer = u.buffer - var b = new B(arraybuffer) - t.equal(b.length, 4) - t.equal(b[0], 0) - t.equal(b[1], 1) - t.equal(b[2], 2) - t.equal(b[3], 3) - t.equal(b[4], undefined) - - // changing the Uint8Array (and thus the ArrayBuffer), changes the Buffer - u[0] = 10 - t.equal(b[0], 10) - u[1] = 11 - t.equal(b[1], 11) - u[2] = 12 - t.equal(b[2], 12) - u[3] = 13 - t.equal(b[3], 13) - } + var u = new Uint8Array([0, 1, 2, 3]) + var arraybuffer = u.buffer + var b = new B(arraybuffer) + t.equal(b.length, 4) + t.equal(b[0], 0) + t.equal(b[1], 1) + t.equal(b[2], 2) + t.equal(b[3], 3) + t.equal(b[4], undefined) + + // changing the Uint8Array (and thus the ArrayBuffer), changes the Buffer + u[0] = 10 + t.equal(b[0], 10) + u[1] = 11 + t.equal(b[1], 11) + u[2] = 12 + t.equal(b[2], 12) + u[3] = 13 + t.equal(b[3], 13) t.end() }) diff --git a/test/slice.js b/test/slice.js index b2cc290..d8cd20e 100644 --- a/test/slice.js +++ b/test/slice.js @@ -2,8 +2,6 @@ var B = require('../').Buffer var test = require('tape') test('modifying buffer created by .slice() modifies original memory', function (t) { - if (!B.TYPED_ARRAY_SUPPORT) return t.end() - var buf1 = new B(26) for (var i = 0; i < 26; i++) { buf1[i] = i + 97 // 97 is ASCII a @@ -19,8 +17,6 @@ test('modifying buffer created by .slice() modifies original memory', function ( }) test('modifying parent buffer modifies .slice() buffer\'s memory', function (t) { - if (!B.TYPED_ARRAY_SUPPORT) return t.end() - var buf1 = new B(26) for (var i = 0; i < 26; i++) { buf1[i] = i + 97 // 97 is ASCII a diff --git a/test/write.js b/test/write.js index 6e85afc..9c10368 100644 --- a/test/write.js +++ b/test/write.js @@ -65,12 +65,6 @@ test('hex of write{Uint,Int}{8,16,32}{LE,BE}', function (t) { }) test('hex of write{Uint,Int}{8,16,32}{LE,BE} with overflow', function (t) { - if (!B.TYPED_ARRAY_SUPPORT) { - t.pass('object impl: skipping overflow test') - t.end() - return - } - t.plan(3 * (2 * 2 * 2 + 2)) var hex = [ '', '03', '00', '030000', '000000',