Support for unique collections

This commit is contained in:
Tim Schaub
2017-04-11 21:29:30 -06:00
parent 8b0e1b638b
commit d28f50465b
3 changed files with 117 additions and 1 deletions

View File

@@ -298,4 +298,67 @@ describe('ol.collection', function() {
});
});
describe('unique collection', function() {
it('allows unique items in the constructor', function() {
new ol.Collection([{}, {}, {}], {unique: true});
});
it('throws if duplicate items are passed to the contructor', function() {
var item = {};
var call = function() {
new ol.Collection([item, item], {unique: true});
};
expect(call).to.throwException();
});
it('allows unique items to be added via push', function() {
var unique = new ol.Collection(undefined, {unique: true});
unique.push({});
unique.push({});
});
it('throws if duplicate items are added via push', function() {
var unique = new ol.Collection(undefined, {unique: true});
var item = {};
unique.push(item);
var call = function() {
unique.push(item);
};
expect(call).to.throwException();
});
it('allows unique items to be added via insertAt', function() {
var unique = new ol.Collection(undefined, {unique: true});
unique.insertAt(0, {});
unique.insertAt(0, {});
});
it('throws if duplicate items are added via insertAt', function() {
var unique = new ol.Collection(undefined, {unique: true});
var item = {};
unique.insertAt(0, item);
var call = function() {
unique.insertAt(0, item);
};
expect(call).to.throwException();
});
it('allows unique items to be added via setAt', function() {
var unique = new ol.Collection(undefined, {unique: true});
unique.setAt(0, {});
unique.setAt(1, {});
});
it('throws if duplicate items are added via setAt', function() {
var unique = new ol.Collection(undefined, {unique: true});
var item = {};
unique.setAt(0, item);
var call = function() {
unique.setAt(1, item);
};
expect(call).to.throwException();
});
});
});