Collections cannot contain Collections.

By having both the constructor and the setComponents checking
a white- and a blacklist for allowed types, we ensure that no
Collections can be added through these methods to the list of
components.
This commit is contained in:
Marc Jansen
2012-06-21 18:18:00 +02:00
parent 8d8819ec3c
commit 340caf2720
2 changed files with 129 additions and 4 deletions

View File

@@ -29,6 +29,16 @@ describe("ol.geom.Collection", function() {
expect( c ).toBeA( ol.geom.Collection );
});
it("cannot construct instances when passed illegal components", function() {
// collection cannot contain collections
expect(function(){
c = new ol.geom.Collection([
new ol.geom.Collection()
]);
}).toThrow();
});
it("inherits from ol.geom.Geometry", function() {
expect( c ).toBeA( ol.geom.Geometry );
});
@@ -81,7 +91,7 @@ describe("ol.geom.Collection", function() {
]),
0
);
var components = c.getComponents();
expect( components.length ).toBe( 4 );
@@ -92,6 +102,17 @@ describe("ol.geom.Collection", function() {
});
it("cannot add instances of 'ol.geom.Collection'", function(){
expect(function(){
c.addComponent(
new ol.geom.Collection([
new ol.geom.Point(5,25),
new ol.geom.Point(6,36)
])
);
}).toThrow();
});
it("has a method to remove components", function() {
c.setComponents([
new ol.geom.Point(0,10),