// ========================================================================== // Project: SproutCore Costello - Property Observing Library // Copyright: ©2006-2011 Strobe Inc. and contributors. // Portions ©2008-2010 Apple Inc. All rights reserved. // License: Licensed under MIT license (see license.js) // ========================================================================== /*globals module test ok isObj equals expects */ var enumerables ; // global variables var DummyEnumerable = SC.Object.extend( SC.Enumerable, { content: [], length: function() { return this.content.length; }.property(), objectAt: function(idx) { return this.content[idx]; }, nextObject: function(idx) { return this.content[idx]; }, // add support for reduced properties. unknownProperty: function(key, value) { var ret = this.reducedProperty(key, value) ; if (ret === undefined) { if (value !== undefined) this[key] = value ; ret = value ; } return ret ; }, pushObject: function(object) { this.content.push(object) ; this.enumerableContentDidChange() ; } }); var runFunc = function(a,b) { return ['DONE', a, b]; } ; var invokeWhileOK = function() { return "OK"; } ; var invokeWhileNotOK = function() { return "FAIL"; }; var reduceTestFunc = function(prev, item, idx, e, pname) { return pname||'TEST'; } ; var CommonArray = [ { first: "Charles", gender: "male", californian: NO, ready: YES, visited: "Prague", doneTravelling: NO, run: runFunc, invokeWhileTest: invokeWhileOK, balance: 1 }, { first: "Jenna", gender: "female", californian: YES, ready: YES, visited: "Prague", doneTravelling: NO, run: runFunc, invokeWhileTest: invokeWhileOK, balance: 2 }, { first: "Peter", gender: "male", californian: NO, ready: YES, visited: "Prague", doneTravelling: NO, run: runFunc, invokeWhileTest: invokeWhileNotOK, balance: 3 }, { first: "Chris", gender: "male", californian: NO, ready: YES, visited: "Prague", doneTravelling: NO, run: runFunc, invokeWhileTest: invokeWhileOK, balance: 4 } ]; module("Real Array & DummyEnumerable", { setup: function() { enumerables = [SC.$A(CommonArray), DummyEnumerable.create({ content: CommonArray })] ; }, teardown: function() { delete enumerables; delete Array.prototype["@max(balance)"] ; // remove cached value delete Array.prototype["@min(balance)"] ; } }); test("should get enumerator that iterates through objects", function() { var src, ary2 = enumerables ; for (var idx2=0, len2=ary2.length; idx2