]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#463] Popcorn.isArray() to support FF3.6; +18 Unit tests
authorrwldrn <waldron.rick@gmail.com>
Fri, 1 Apr 2011 20:43:43 +0000 (16:43 -0400)
committerrwldrn <waldron.rick@gmail.com>
Fri, 1 Apr 2011 20:43:43 +0000 (16:43 -0400)
popcorn.js
test/popcorn.unit.js

index 8b064aafd63f849374e86052b5a82b156b96e42f..c68ce3516390412b34dbd4ed582a13436dbd91b6 100644 (file)
@@ -13,6 +13,7 @@
   forEach = Array.prototype.forEach,
   hasOwn = Object.prototype.hasOwnProperty,
   slice = Array.prototype.slice,
+  toString = Object.prototype.toString,
 
   //  ID string matching
   rIdExp  = /^(#([\w\-\_\.]+))$/,
 
       return size;
     },
+    isArray: Array.isArray || function( array ) {
+           return toString.call( array ) === "[object Array]";
+    }, 
     nop: function () {}
   });
 
index 0f63263743651292588a665be32a77b67b44e9e3..12e877f0ae13443445b507e709b443e786eb008c 100755 (executable)
@@ -164,6 +164,39 @@ test("guid", function () {
   }
 
 });
+test("isArray", function() {
+
+  expect(18);
+
+  var empty = [], 
+      fastSmall = [1], 
+      slow = [],
+      slowSmall = [], 
+      all = null;
+
+  slowSmall[999999] = 0;
+  slowSmall.length = 0;
+  slow.slow = 0;
+
+  all = [ [], [1], new Array, Array(0),'abc'.match(/(a)/g), slow, slowSmall ];
+
+  all.forEach(function( a ) { 
+    ok( Popcorn.isArray(a), "Popcorn.isArray("+JSON.stringify(a)+")" ); 
+  });
+
+  equal( Popcorn.isArray.length, 1, "Popcorn.isArray.length, 1" );
+  
+  ok( !Popcorn.isArray(), "!Popcorn.isArray(), false");
+  ok( !Popcorn.isArray({}), "!Popcorn.isArray({}), false");
+  ok( !Popcorn.isArray(null), "!Popcorn.isArray(null), false");
+  ok( !Popcorn.isArray(undefined), "!Popcorn.isArray(undefined)");
+  ok( !Popcorn.isArray(17), "!Popcorn.isArray(17), false");
+  ok( !Popcorn.isArray("Array"), "!Popcorn.isArray('Array'), false");
+  ok( !Popcorn.isArray(Math.PI), "!Popcorn.isArray(Math.PI), false");
+  ok( !Popcorn.isArray(true), "!Popcorn.isArray(true), false");
+  ok( !Popcorn.isArray(false), "!Popcorn.isArray(false), false");
+  ok( !Popcorn.isArray( {__proto__: Array.prototype, length:1, 0:1, 1:2} ), "{__proto__: Array.prototype, length:1, 0:1, 1:2}");
+});
 
 
 test("Protected", function () {
@@ -1920,11 +1953,11 @@ test("Parser Support", function () {
     }
   });
 
-       Popcorn.parser( "parseAudio", function( data ){
-         ok( typeof data.json === "object", "data.json exists");
-         plus();
-         return data.json;
-       });
+  Popcorn.parser( "parseAudio", function( data ){
+    ok( typeof data.json === "object", "data.json exists");
+    plus();
+    return data.json;
+  });
 
   audiocorn.parseAudio("data/parserAudio.json", function() {