var Immutable = require("../../seamless-immutable.js");
var JSC       = require("jscheck");
var TestUtils = require("../TestUtils.js");
var assert    = require("chai").assert;
var _         = require("lodash")
var check     = TestUtils.check;

module.exports = function() {
  describe("#asObject", function() {
    it("works on arrays of various lengths", function() {
      check(100, [JSC.array()], function(mutableArray) {
        var keys   = mutableArray.map(function() { return JSC.string()(); })
        var values = mutableArray.map(function() { return JSC.any()(); })
        var array  = Immutable(mutableArray);

        var result = array.asObject(function(value, index) {
          // Check that the index argument we receive works as expected.
          assert.deepEqual(value, array[index], "Expected array[" + index + "] to be " + value);

          return [keys[index], values[index]]
        });

        _.each(function(key, index) {
          assert.deepEqual(values[index], result[key]);
        });
      });
    });

    // Sanity check to make sure our QuickCheck logic isn't off the rails.
    it("passes a basic sanity check on canned input", function() {
      var expected = Immutable({all: "your base", are: {belong: "to us"}});
      var actual   = Immutable([{key: "all", value: "your base"}, {key: "are", value: {belong: "to us"}}]).asObject(function(elem) {
        return [elem.key, elem.value];
      });

      assert.deepEqual(actual, expected);
    });
  });
};
@@ -1029,24 +1029,629 @@
 );%0A    %7D);%0A%0A
+    it(%22works without an iterator on arrays that are already organized properly%22, function() %7B%0A      check(100, %5BJSC.array()%5D, function(mutableArray) %7B%0A        var keys   = mutableArray.map(function() %7B return JSC.string()(); %7D)%0A        var values = mutableArray.map(function() %7B return JSC.any()(); %7D)%0A        var array  = Immutable(_.map(mutableArray, function(value, index) %7B%0A          return %5Bkeys%5Bindex%5D, values%5Bindex%5D%5D;%0A        %7D));%0A%0A        var result = array.asObject();%0A%0A        _.each(function(key, index) %7B%0A          assert.deepEqual(values%5Bindex%5D, result%5Bkey%5D);%0A        %7D);%0A      %7D);%0A    %7D);%0A%0A
     // Sanit

Add a test for calling #asObject with no arguments.