From 38f85307f8c1b3099a85a85f844a0d0d62253d06 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 28 Dec 2013 02:53:03 -0800 Subject: [PATCH] tests: forEach for IE6-8 --- test/buffer.js | 104 +++++++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 46 deletions(-) diff --git a/test/buffer.js b/test/buffer.js index 0d8ff7b..c3545f5 100644 --- a/test/buffer.js +++ b/test/buffer.js @@ -126,26 +126,32 @@ test("hex of write{Uint,Int}{8,16,32}{LE,BE}", function (t) { "fd", "fdff", "fffd", "fdffffff", "fffffffd" ]; var reads = [ 3, 3, 3, 3, 3, -3, -3, -3, -3, -3 ]; - ["UInt","Int"].forEach(function(x){ - [8,16,32].forEach(function(y){ - var endianesses = (y === 8) ? [""] : ["LE","BE"]; - endianesses.forEach(function(z){ - var v1 = new B(y / 8); - var writefn = "write" + x + y + z; - var val = (x === "Int") ? -3 : 3; - v1[writefn](val, 0); - t.equal( - v1.toString("hex"), - hex.shift() - ); - var readfn = "read" + x + y + z; - t.equal( - v1[readfn](0), - reads.shift() - ); - }); - }); - }); + var xs = ["UInt","Int"]; + var ys = [8,16,32]; + for (var i = 0; i < xs.length; i++) { + var x = xs[i]; + for (var j = 0; j < ys.length; j++) { + var y = ys[j]; + var endianesses = (y === 8) ? [""] : ["LE","BE"]; + for (var k = 0; k < endianesses.length; k++) { + var z = endianesses[k]; + + var v1 = new B(y / 8); + var writefn = "write" + x + y + z; + var val = (x === "Int") ? -3 : 3; + v1[writefn](val, 0); + t.equal( + v1.toString("hex"), + hex.shift() + ); + var readfn = "read" + x + y + z; + t.equal( + v1[readfn](0), + reads.shift() + ); + } + } + } t.end(); }); @@ -159,32 +165,38 @@ test("hex of write{Uint,Int}{8,16,32}{LE,BE} with overflow", function (t) { undefined, 3, 0, 3, 0, undefined, 253, -256, 16777213, -256 ]; - ["UInt","Int"].forEach(function(x){ - [8,16,32].forEach(function(y){ - var endianesses = (y === 8) ? [""] : ["LE","BE"]; - endianesses.forEach(function(z){ - var v1 = new B(y / 8 - 1); - var next = new B(4); - next.writeUInt32BE(0, 0); - var writefn = "write" + x + y + z; - var val = (x === "Int") ? -3 : 3; - v1[writefn](val, 0, true); - t.equal( - v1.toString("hex"), - hex.shift() - ); - // check that nothing leaked to next buffer. - t.equal(next.readUInt32BE(0), 0); - // check that no bytes are read from next buffer. - next.writeInt32BE(~0, 0); - var readfn = "read" + x + y + z; - t.equal( - v1[readfn](0, true), - reads.shift() - ); - }); - }); - }); + var xs = ["UInt","Int"]; + var ys = [8,16,32]; + for (var i = 0; i < xs.length; i++) { + var x = xs[i]; + for (var j = 0; j < ys.length; j++) { + var y = ys[j]; + var endianesses = (y === 8) ? [""] : ["LE","BE"]; + for (var k = 0; k < endianesses.length; k++) { + var z = endianesses[k]; + + var v1 = new B(y / 8 - 1); + var next = new B(4); + next.writeUInt32BE(0, 0); + var writefn = "write" + x + y + z; + var val = (x === "Int") ? -3 : 3; + v1[writefn](val, 0, true); + t.equal( + v1.toString("hex"), + hex.shift() + ); + // check that nothing leaked to next buffer. + t.equal(next.readUInt32BE(0), 0); + // check that no bytes are read from next buffer. + next.writeInt32BE(~0, 0); + var readfn = "read" + x + y + z; + t.equal( + v1[readfn](0, true), + reads.shift() + ); + } + } + } t.end(); }); -- 2.34.1