diff --git a/packages/ember-runtime/lib/system/set.js b/packages/ember-runtime/lib/system/set.js deleted file mode 100644 index d4519e059fa..00000000000 --- a/packages/ember-runtime/lib/system/set.js +++ /dev/null @@ -1,513 +0,0 @@ -/** -@module ember -@submodule ember-runtime -*/ -import Ember from "ember-metal/core"; // Ember.isNone, Ember.A - -import { get } from "ember-metal/property_get"; -import { set } from "ember-metal/property_set"; -import { guidFor } from "ember-metal/utils"; -import isNone from 'ember-metal/is_none'; -import { fmt } from "ember-runtime/system/string"; -import CoreObject from "ember-runtime/system/core_object"; -import MutableEnumerable from "ember-runtime/mixins/mutable_enumerable"; -import Enumerable from "ember-runtime/mixins/enumerable"; -import Copyable from "ember-runtime/mixins/copyable"; -import { - Freezable, - FROZEN_ERROR -} from "ember-runtime/mixins/freezable"; -import EmberError from "ember-metal/error"; -import { - propertyWillChange, - propertyDidChange -} from "ember-metal/property_events"; -import { aliasMethod } from "ember-metal/mixin"; -import { computed } from "ember-metal/computed"; - -/** - An unordered collection of objects. - - A Set works a bit like an array except that its items are not ordered. You - can create a set to efficiently test for membership for an object. You can - also iterate through a set just like an array, even accessing objects by - index, however there is no guarantee as to their order. - - All Sets are observable via the Enumerable Observer API - which works - on any enumerable object including both Sets and Arrays. - - ## Creating a Set - - You can create a set like you would most objects using - `new Ember.Set()`. Most new sets you create will be empty, but you can - also initialize the set with some content by passing an array or other - enumerable of objects to the constructor. - - Finally, you can pass in an existing set and the set will be copied. You - can also create a copy of a set by calling `Ember.Set#copy()`. - - ```javascript - // creates a new empty set - var foundNames = new Ember.Set(); - - // creates a set with four names in it. - var names = new Ember.Set(["Charles", "Tom", "Juan", "Alex"]); // :P - - // creates a copy of the names set. - var namesCopy = new Ember.Set(names); - - // same as above. - var anotherNamesCopy = names.copy(); - ``` - - ## Adding/Removing Objects - - You generally add or remove objects from a set using `add()` or - `remove()`. You can add any type of object including primitives such as - numbers, strings, and booleans. - - Unlike arrays, objects can only exist one time in a set. If you call `add()` - on a set with the same object multiple times, the object will only be added - once. Likewise, calling `remove()` with the same object multiple times will - remove the object the first time and have no effect on future calls until - you add the object to the set again. - - NOTE: You cannot add/remove `null` or `undefined` to a set. Any attempt to do - so will be ignored. - - In addition to add/remove you can also call `push()`/`pop()`. Push behaves - just like `add()` but `pop()`, unlike `remove()` will pick an arbitrary - object, remove it and return it. This is a good way to use a set as a job - queue when you don't care which order the jobs are executed in. - - ## Testing for an Object - - To test for an object's presence in a set you simply call - `Ember.Set#contains()`. - - ## Observing changes - - When using `Ember.Set`, you can observe the `"[]"` property to be - alerted whenever the content changes. You can also add an enumerable - observer to the set to be notified of specific objects that are added and - removed from the set. See [Ember.Enumerable](/api/classes/Ember.Enumerable.html) - for more information on enumerables. - - This is often unhelpful. If you are filtering sets of objects, for instance, - it is very inefficient to re-filter all of the items each time the set - changes. It would be better if you could just adjust the filtered set based - on what was changed on the original set. The same issue applies to merging - sets, as well. - - ## Other Methods - - `Ember.Set` primary implements other mixin APIs. For a complete reference - on the methods you will use with `Ember.Set`, please consult these mixins. - The most useful ones will be `Ember.Enumerable` and - `Ember.MutableEnumerable` which implement most of the common iterator - methods you are used to on Array. - - Note that you can also use the `Ember.Copyable` and `Ember.Freezable` - APIs on `Ember.Set` as well. Once a set is frozen it can no longer be - modified. The benefit of this is that when you call `frozenCopy()` on it, - Ember will avoid making copies of the set. This allows you to write - code that can know with certainty when the underlying set data will or - will not be modified. - - @class Set - @namespace Ember - @extends Ember.CoreObject - @uses Ember.MutableEnumerable - @uses Ember.Copyable - @uses Ember.Freezable - @since Ember 0.9 - @deprecated - @private -*/ -export default CoreObject.extend(MutableEnumerable, Copyable, Freezable, { - - // .......................................................... - // IMPLEMENT ENUMERABLE APIS - // - - /** - This property will change as the number of objects in the set changes. - - @property length - @type number - @default 0 - @private - */ - length: 0, - - /** - Clears the set. This is useful if you want to reuse an existing set - without having to recreate it. - - ```javascript - var colors = new Ember.Set(["red", "green", "blue"]); - colors.length; // 3 - colors.clear(); - colors.length; // 0 - ``` - - @method clear - @return {Ember.Set} An empty Set - @private - */ - clear() { - if (this.isFrozen) { throw new EmberError(FROZEN_ERROR); } - - var len = get(this, 'length'); - if (len === 0) { return this; } - - var guid; - - this.enumerableContentWillChange(len, 0); - propertyWillChange(this, 'firstObject'); - propertyWillChange(this, 'lastObject'); - - for (var i=0; i < len; i++) { - guid = guidFor(this[i]); - delete this[guid]; - delete this[i]; - } - - set(this, 'length', 0); - - propertyDidChange(this, 'firstObject'); - propertyDidChange(this, 'lastObject'); - this.enumerableContentDidChange(len, 0); - - return this; - }, - - /** - Returns true if the passed object is also an enumerable that contains the - same objects as the receiver. - - ```javascript - var colors = ["red", "green", "blue"], - same_colors = new Ember.Set(colors); - - same_colors.isEqual(colors); // true - same_colors.isEqual(["purple", "brown"]); // false - ``` - - @method isEqual - @param {Ember.Set} obj the other object. - @return {Boolean} - @private - */ - isEqual(obj) { - // fail fast - if (!Enumerable.detect(obj)) { - return false; - } - - var loc = get(this, 'length'); - if (get(obj, 'length') !== loc) { - return false; - } - - while (--loc >= 0) { - if (!obj.contains(this[loc])) { - return false; - } - } - - return true; - }, - - /** - Adds an object to the set. Only non-`null` objects can be added to a set - and those can only be added once. If the object is already in the set or - the passed value is null this method will have no effect. - - This is an alias for `Ember.MutableEnumerable.addObject()`. - - ```javascript - var colors = new Ember.Set(); - colors.add("blue"); // ["blue"] - colors.add("blue"); // ["blue"] - colors.add("red"); // ["blue", "red"] - colors.add(null); // ["blue", "red"] - colors.add(undefined); // ["blue", "red"] - ``` - - @method add - @param {Object} obj The object to add. - @return {Ember.Set} The set itself. - @private - */ - add: aliasMethod('addObject'), - - /** - Removes the object from the set if it is found. If you pass a `null` value - or an object that is already not in the set, this method will have no - effect. This is an alias for `Ember.MutableEnumerable.removeObject()`. - - ```javascript - var colors = new Ember.Set(["red", "green", "blue"]); - colors.remove("red"); // ["blue", "green"] - colors.remove("purple"); // ["blue", "green"] - colors.remove(null); // ["blue", "green"] - ``` - - @method remove - @param {Object} obj The object to remove - @return {Ember.Set} The set itself. - @private - */ - remove: aliasMethod('removeObject'), - - /** - Removes the last element from the set and returns it, or `null` if it's empty. - - ```javascript - var colors = new Ember.Set(["green", "blue"]); - colors.pop(); // "blue" - colors.pop(); // "green" - colors.pop(); // null - ``` - - @method pop - @return {Object} The removed object from the set or null. - @private - */ - pop() { - if (get(this, 'isFrozen')) { - throw new EmberError(FROZEN_ERROR); - } - - var obj = this.length > 0 ? this[this.length-1] : null; - this.remove(obj); - return obj; - }, - - /** - Inserts the given object on to the end of the set. It returns - the set itself. - - This is an alias for `Ember.MutableEnumerable.addObject()`. - - ```javascript - var colors = new Ember.Set(); - colors.push("red"); // ["red"] - colors.push("green"); // ["red", "green"] - colors.push("blue"); // ["red", "green", "blue"] - ``` - - @method push - @return {Ember.Set} The set itself. - @private - */ - push: aliasMethod('addObject'), - - /** - Removes the last element from the set and returns it, or `null` if it's empty. - - This is an alias for `Ember.Set.pop()`. - - ```javascript - var colors = new Ember.Set(["green", "blue"]); - colors.shift(); // "blue" - colors.shift(); // "green" - colors.shift(); // null - ``` - - @method shift - @return {Object} The removed object from the set or null. - @private - */ - shift: aliasMethod('pop'), - - /** - Inserts the given object on to the end of the set. It returns - the set itself. - - This is an alias of `Ember.Set.push()` - - ```javascript - var colors = new Ember.Set(); - colors.unshift("red"); // ["red"] - colors.unshift("green"); // ["red", "green"] - colors.unshift("blue"); // ["red", "green", "blue"] - ``` - - @method unshift - @return {Ember.Set} The set itself. - @private - */ - unshift: aliasMethod('push'), - - /** - Adds each object in the passed enumerable to the set. - - This is an alias of `Ember.MutableEnumerable.addObjects()` - - ```javascript - var colors = new Ember.Set(); - colors.addEach(["red", "green", "blue"]); // ["red", "green", "blue"] - ``` - - @method addEach - @param {Ember.Enumerable} objects the objects to add. - @return {Ember.Set} The set itself. - @private - */ - addEach: aliasMethod('addObjects'), - - /** - Removes each object in the passed enumerable to the set. - - This is an alias of `Ember.MutableEnumerable.removeObjects()` - - ```javascript - var colors = new Ember.Set(["red", "green", "blue"]); - colors.removeEach(["red", "blue"]); // ["green"] - ``` - - @method removeEach - @param {Ember.Enumerable} objects the objects to remove. - @return {Ember.Set} The set itself. - @private - */ - removeEach: aliasMethod('removeObjects'), - - // .......................................................... - // PRIVATE ENUMERABLE SUPPORT - // - - init(items) { - Ember.deprecate('Ember.Set is deprecated and will be removed in a future release.'); - this._super(...arguments); - - if (items) { - this.addObjects(items); - } - }, - - // implement Ember.Enumerable - nextObject(idx) { - return this[idx]; - }, - - // more optimized version - firstObject: computed(function() { - return this.length > 0 ? this[0] : undefined; - }), - - // more optimized version - lastObject: computed(function() { - return this.length > 0 ? this[this.length-1] : undefined; - }), - - // implements Ember.MutableEnumerable - addObject(obj) { - if (get(this, 'isFrozen')) { - throw new EmberError(FROZEN_ERROR); - } - - if (isNone(obj)) { - return this; // nothing to do - } - - var guid = guidFor(obj); - var idx = this[guid]; - var len = get(this, 'length'); - var added; - - if (idx>=0 && idx=0 && idx=0; - }, - - copy() { - var C = this.constructor; - var ret = new C(); - var loc = get(this, 'length'); - - set(ret, 'length', loc); - while (--loc >= 0) { - ret[loc] = this[loc]; - ret[guidFor(this[loc])] = loc; - } - return ret; - }, - - toString() { - var len = this.length; - var array = []; - var idx; - - for (idx = 0; idx < len; idx++) { - array[idx] = this[idx]; - } - return fmt("Ember.Set<%@>", [array.join(',')]); - } -}); diff --git a/packages/ember-runtime/tests/legacy_1x/system/set_test.js b/packages/ember-runtime/tests/legacy_1x/system/set_test.js deleted file mode 100644 index 03d13401a40..00000000000 --- a/packages/ember-runtime/tests/legacy_1x/system/set_test.js +++ /dev/null @@ -1,339 +0,0 @@ -import Ember from "ember-metal/core"; -import isNone from 'ember-metal/is_none'; -import Set from "ember-runtime/system/set"; -import EmberObject from 'ember-runtime/system/object'; -import EmberArray from "ember-runtime/mixins/array"; - -// NOTE: This test is adapted from the 1.x series of unit tests. The tests -// are the same except for places where we intend to break the API we instead -// validate that we warn the developer appropriately. -// -// * Changed Set.clone() call to Set.copy() - -// ======================================================================== -// Set Tests -// ======================================================================== - -var a, b, c ; // global variables - -QUnit.module("creating Set instances", { - - setup() { - // create objects... - a = { name: "a" }; - b = { name: "b" }; - c = { name: "c" }; - }, - - teardown() { - a = undefined; - b = undefined; - c = undefined; - } - -}); - -QUnit.test("new Set() should create empty set", function() { - ignoreDeprecation(function() { - var set = new Set(); - equal(set.length, 0); - }); -}); - -QUnit.test("new Set([1,2,3]) should create set with three items in them", function() { - ignoreDeprecation(function() { - var set = new Set(Ember.A([a,b,c])); - equal(set.length, 3); - equal(set.contains(a), true); - equal(set.contains(b), true); - equal(set.contains(c), true); - }); -}); - -QUnit.test("new Set() should accept anything that implements EmberArray", function() { - var arrayLikeObject = EmberObject.createWithMixins(EmberArray, { - _content: [a,b,c], - length: 3, - objectAt(idx) { return this._content[idx]; } - }); - - ignoreDeprecation(function() { - var set = new Set(arrayLikeObject); - equal(set.length, 3); - equal(set.contains(a), true); - equal(set.contains(b), true); - equal(set.contains(c), true); - }); -}); - -var set; // global variables - -// The tests below also end up testing the contains() method pretty -// exhaustively. -QUnit.module("Set.add + Set.contains", { - - setup() { - ignoreDeprecation(function() { - set = new Set(); - }); - }, - - teardown() { - set = undefined; - } - -}); - -QUnit.test("should add an EmberObject", function() { - var obj = EmberObject.create(); - - var oldLength = set.length; - set.add(obj); - equal(set.contains(obj), true, "contains()"); - equal(set.length, oldLength+1, "new set length"); -}); - -QUnit.test("should add a regular hash", function() { - var obj = {}; - - var oldLength = set.length; - set.add(obj); - equal(set.contains(obj), true, "contains()"); - equal(set.length, oldLength+1, "new set length"); -}); - -QUnit.test("should add a string", function() { - var obj = "String!"; - - var oldLength = set.length; - set.add(obj); - equal(set.contains(obj), true, "contains()"); - equal(set.length, oldLength+1, "new set length"); -}); - -QUnit.test("should add a number", function() { - var obj = 23; - - var oldLength = set.length; - set.add(obj); - equal(set.contains(obj), true, "contains()"); - equal(set.length, oldLength+1, "new set length"); -}); - -QUnit.test("should add bools", function() { - var oldLength = set.length; - - set.add(true); - equal(set.contains(true), true, "contains(true)"); - equal(set.length, oldLength+1, "new set length"); - - set.add(false); - equal(set.contains(false), true, "contains(false)"); - equal(set.length, oldLength+2, "new set length"); -}); - -QUnit.test("should add 0", function() { - var oldLength = set.length; - - set.add(0); - equal(set.contains(0), true, "contains(0)"); - equal(set.length, oldLength+1, "new set length"); -}); - -QUnit.test("should add a function", function() { - var obj = function() { return "Test function"; }; - - var oldLength = set.length; - set.add(obj); - equal(set.contains(obj), true, "contains()"); - equal(set.length, oldLength+1, "new set length"); -}); - -QUnit.test("should NOT add a null", function() { - set.add(null); - equal(set.length, 0); - equal(set.contains(null), false); -}); - -QUnit.test("should NOT add an undefined", function() { - set.add(undefined); - equal(set.length, 0); - equal(set.contains(undefined), false); -}); - -QUnit.test("adding an item, removing it, adding another item", function() { - var item1 = "item1"; - var item2 = "item2"; - - set.add(item1); // add to set - set.remove(item1); //remove from set - set.add(item2); - - equal(set.contains(item1), false, "set.contains(item1)"); - - set.add(item1); // re-add to set - equal(set.length, 2, "set.length"); -}); - -QUnit.module("Set.remove + Set.contains", { - - // generate a set with every type of object, but none of the specific - // ones we add in the tests below... - setup() { - ignoreDeprecation(function() { - set = new Set(Ember.A([ - EmberObject.create({ dummy: true }), - { isHash: true }, - "Not the String", - 16, true, false, 0])); - }); - }, - - teardown() { - set = undefined; - } - -}); - -QUnit.test("should remove an EmberObject and reduce length", function() { - var obj = EmberObject.create(); - set.add(obj); - equal(set.contains(obj), true); - var oldLength = set.length; - - set.remove(obj); - equal(set.contains(obj), false, "should be removed"); - equal(set.length, oldLength-1, "should be 1 shorter"); -}); - -QUnit.test("should remove a regular hash and reduce length", function() { - var obj = {}; - set.add(obj); - equal(set.contains(obj), true); - var oldLength = set.length; - - set.remove(obj); - equal(set.contains(obj), false, "should be removed"); - equal(set.length, oldLength-1, "should be 1 shorter"); -}); - -QUnit.test("should remove a string and reduce length", function() { - var obj = "String!"; - set.add(obj); - equal(set.contains(obj), true); - var oldLength = set.length; - - set.remove(obj); - equal(set.contains(obj), false, "should be removed"); - equal(set.length, oldLength-1, "should be 1 shorter"); -}); - -QUnit.test("should remove a number and reduce length", function() { - var obj = 23; - set.add(obj); - equal(set.contains(obj), true); - var oldLength = set.length; - - set.remove(obj); - equal(set.contains(obj), false, "should be removed"); - equal(set.length, oldLength-1, "should be 1 shorter"); -}); - -QUnit.test("should remove a bools and reduce length", function() { - var oldLength = set.length; - set.remove(true); - equal(set.contains(true), false, "should be removed"); - equal(set.length, oldLength-1, "should be 1 shorter"); - - set.remove(false); - equal(set.contains(false), false, "should be removed"); - equal(set.length, oldLength-2, "should be 2 shorter"); -}); - -QUnit.test("should remove 0 and reduce length", function() { - var oldLength = set.length; - set.remove(0); - equal(set.contains(0), false, "should be removed"); - equal(set.length, oldLength-1, "should be 1 shorter"); -}); - -QUnit.test("should remove a function and reduce length", function() { - var obj = function() { return "Test function"; }; - set.add(obj); - equal(set.contains(obj), true); - var oldLength = set.length; - - set.remove(obj); - equal(set.contains(obj), false, "should be removed"); - equal(set.length, oldLength-1, "should be 1 shorter"); -}); - -QUnit.test("should NOT remove a null", function() { - var oldLength = set.length; - set.remove(null); - equal(set.length, oldLength); -}); - -QUnit.test("should NOT remove an undefined", function() { - var oldLength = set.length; - set.remove(undefined); - equal(set.length, oldLength); -}); - -QUnit.test("should ignore removing an object not in the set", function() { - var obj = EmberObject.create(); - var oldLength = set.length; - set.remove(obj); - equal(set.length, oldLength); -}); - -QUnit.module("Set.pop + Set.copy", { - // generate a set with every type of object, but none of the specific - // ones we add in the tests below... - setup() { - ignoreDeprecation(function() { - set = new Set(Ember.A([ - EmberObject.create({ dummy: true }), - { isHash: true }, - "Not the String", - 16, false])); - }); - }, - - teardown() { - set = undefined; - } -}); - -QUnit.test("the pop() should remove an arbitrary object from the set", function() { - var oldLength = set.length; - var obj = set.pop(); - ok(!isNone(obj), 'pops up an item'); - equal(set.length, oldLength-1, 'length shorter by 1'); -}); - -QUnit.test("should pop false and 0", function() { - ignoreDeprecation(function() { - set = new Set(Ember.A([false])); - ok(set.pop() === false, "should pop false"); - - set = new Set(Ember.A([0])); - ok(set.pop() === 0, "should pop 0"); - }); -}); - -QUnit.test("the copy() should return an identical set", function() { - var oldLength = set.length; - var obj; - - ignoreDeprecation(function() { - obj = set.copy(); - }); - - equal(oldLength, obj.length, 'length of the clone should be same'); - equal(obj.contains(set[0]), true); - equal(obj.contains(set[1]), true); - equal(obj.contains(set[2]), true); - equal(obj.contains(set[3]), true); - equal(obj.contains(set[4]), true); -}); diff --git a/packages/ember-runtime/tests/system/set/copyable_suite_test.js b/packages/ember-runtime/tests/system/set/copyable_suite_test.js deleted file mode 100644 index d04a6dd20be..00000000000 --- a/packages/ember-runtime/tests/system/set/copyable_suite_test.js +++ /dev/null @@ -1,45 +0,0 @@ -import CopyableTests from 'ember-runtime/tests/suites/copyable'; -import Set from "ember-runtime/system/set"; -import {generateGuid} from 'ember-metal/utils'; -import {get} from 'ember-metal/property_get'; - -CopyableTests.extend({ - name: 'Ember.Set Copyable', - - newObject() { - var set, originalCopy; - ignoreDeprecation(function() { - set = new Set(); - }); - - set.addObject(generateGuid()); - - originalCopy = set.copy; - set.copy = function() { - var ret; - - ignoreDeprecation(function() { - ret = originalCopy.apply(set, arguments); - }); - - return ret; - }; - - return set; - }, - - isEqual(a, b) { - if (!(a instanceof Set)) { - return false; - } - - if (!(b instanceof Set)) { - return false; - } - - return get(a, 'firstObject') === get(b, 'firstObject'); - }, - - shouldBeFreezable: true -}).run(); - diff --git a/packages/ember-runtime/tests/system/set/enumerable_suite_test.js b/packages/ember-runtime/tests/system/set/enumerable_suite_test.js deleted file mode 100644 index 4ff3e5a1a1c..00000000000 --- a/packages/ember-runtime/tests/system/set/enumerable_suite_test.js +++ /dev/null @@ -1,37 +0,0 @@ -import MutableEnumerableTests from 'ember-runtime/tests/suites/mutable_enumerable'; -import Set from "ember-runtime/system/set"; -import {get} from "ember-metal/property_get"; - -MutableEnumerableTests.extend({ - - name: 'Ember.Set', - - newObject(ary) { - var ret; - ary = ary ? ary.slice() : this.newFixture(3); - - ignoreDeprecation(function() { - ret = new Set(); - ret.addObjects(ary); - }); - - return ret; - }, - - mutate(obj) { - ignoreDeprecation(function() { - obj.addObject(get(obj, 'length')+1); - }); - }, - - toArray(obj) { - var ret; - - ignoreDeprecation(function() { - ret = obj.toArray ? obj.toArray() : obj.slice(); // make a copy. - }); - - return ret; - } - -}).run(); diff --git a/packages/ember-runtime/tests/system/set/extra_test.js b/packages/ember-runtime/tests/system/set/extra_test.js deleted file mode 100644 index f3329f872c7..00000000000 --- a/packages/ember-runtime/tests/system/set/extra_test.js +++ /dev/null @@ -1,98 +0,0 @@ -import {get} from "ember-metal/property_get"; -import {addObserver} from "ember-metal/observer"; -import Set from "ember-runtime/system/set"; - -QUnit.module('Set.init'); - -QUnit.test('passing an array to new Set() should instantiate w/ items', function() { - var aSet; - - var ary = [1,2,3]; - var count = 0; - - ignoreDeprecation(function() { - aSet = new Set(ary); - }); - - equal(get(aSet, 'length'), 3, 'should have three items'); - aSet.forEach((x) => { - ok(ary.indexOf(x)>=0, 'should find passed item in array'); - count++; - }); - equal(count, 3, 'iterating should have returned three objects'); -}); - -QUnit.module('Set.clear'); - -QUnit.test('should clear a set of its content', function() { - var aSet; - var count = 0; - - ignoreDeprecation(function() { - aSet = new Set([1,2,3]); - }); - - equal(get(aSet, 'length'), 3, 'should have three items'); - ok(get(aSet, 'firstObject'), 'firstObject should return an object'); - ok(get(aSet, 'lastObject'), 'lastObject should return an object'); - addObserver(aSet, '[]', function() { count++; }); - - aSet.clear(); - equal(get(aSet, 'length'), 0, 'should have 0 items'); - equal(count, 1, 'should have notified of content change'); - equal(get(aSet, 'firstObject'), null, 'firstObject should return nothing'); - equal(get(aSet, 'lastObject'), null, 'lastObject should return nothing'); - - count = 0; - aSet.forEach(function() { count++; }); - equal(count, 0, 'iterating over items should not invoke callback'); - -}); - -// .......................................................... -// Set.pop -// - -QUnit.module('Set.pop'); - -QUnit.test('calling pop should return an object and remove it', function() { - var aSet, obj; - var count = 0; - - ignoreDeprecation(function() { - aSet = new Set([1,2,3]); - }); - - while (count<10 && (obj = aSet.pop())) { - equal(aSet.contains(obj), false, 'set should no longer contain object'); - count++; - equal(get(aSet, 'length'), 3-count, 'length should be shorter'); - } - - equal(count, 3, 'should only pop 3 objects'); - equal(get(aSet, 'length'), 0, 'final length should be zero'); - equal(aSet.pop(), null, 'extra pops should do nothing'); -}); - -// .......................................................... -// Set.aliases -// - -QUnit.module('Set aliases'); - -QUnit.test('method aliases', function() { - var aSet; - - ignoreDeprecation(function() { - aSet = new Set(); - }); - - equal(aSet.add, aSet.addObject, 'add -> addObject'); - equal(aSet.remove, aSet.removeObject, 'remove -> removeObject'); - equal(aSet.addEach, aSet.addObjects, 'addEach -> addObjects'); - equal(aSet.removeEach, aSet.removeObjects, 'removeEach -> removeObjects'); - - equal(aSet.push, aSet.addObject, 'push -> addObject'); - equal(aSet.unshift, aSet.addObject, 'unshift -> addObject'); - equal(aSet.shift, aSet.pop, 'shift -> pop'); -});