tests: forEach for IE6-8
authorFeross Aboukhadijeh <feross@feross.org>
Sat, 28 Dec 2013 10:53:03 +0000 (02:53 -0800)
committerFeross Aboukhadijeh <feross@feross.org>
Sat, 28 Dec 2013 10:53:03 +0000 (02:53 -0800)
test/buffer.js

index 0d8ff7b8b118334f292313e13dd8294e3d842c0c..c3545f57eadffbe1ad3a899af4d83859d2775ad2 100644 (file)
@@ -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();
 });