mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-25 17:45:36 +00:00
Refs #1629. Fixed: aSet removeObject: for an object not a member is not an error.
This commit is contained in:
1 parent
8e6634168a
commit
aab8ade15b
2 files changed
+17
-7
No files matched your search
@@ -108,13 +108,19 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
*/
|
||||
- (void)removeObject:(id)anObject
|
||||
{
|
||||
var object = [self member:anObject];
|
||||
|
||||
if (object === nil || object === undefined)
|
||||
// Removing nil is an error.
|
||||
if (anObject === nil || anObject === undefined)
|
||||
[CPException raise:CPInvalidArgumentException reason:@"attempt to remove nil or undefined"];
|
||||
|
||||
delete _contents[[object UID]];
|
||||
_count--;
|
||||
// anObject might be isEqual: another object in the set. We need the exact instance so we can remove it by UID.
|
||||
var object = [self member:anObject];
|
||||
|
||||
// ...but removing an object not present in the set is not an error.
|
||||
if (object !== nil)
|
||||
{
|
||||
delete _contents[[object UID]];
|
||||
_count--;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -182,16 +182,20 @@
|
||||
[set2 addObject:dict1];
|
||||
[set2 removeObject:dict2];
|
||||
[self assertTrue:[set2 count] === 0];
|
||||
|
||||
// Removing an object not in the set is not an error.
|
||||
[set2 removeObject:dict2];
|
||||
}
|
||||
|
||||
- (void)testRemoveZeroObject
|
||||
{
|
||||
var set = [CPSet new];
|
||||
|
||||
// In Objective-J this is equivalent to [set addObject:[CPNumber numberWithInt:0]];
|
||||
[set addObject:0];
|
||||
// [self assertTrue:[set containsObject:0]];
|
||||
[self assertTrue:[set containsObject:0] message:@"adding 0 to a set should work"];
|
||||
[set removeObject:0];
|
||||
[self assertFalse:[set containsObject:0]];
|
||||
[self assertFalse:[set containsObject:0] message:@"removing 0 from a set should work"];
|
||||
}
|
||||
|
||||
- (void)testAddNilObject
|
||||
|
||||
Reference in new issue
Block a user