mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-03 11:34:25 +00:00
fix 2 bugs in CPIndexPath
1. we didn't return a copy of the indexes 2. indexPathByRemovingLastIndex didn't remove the last index
This commit is contained in:
1 parent
cd05d30f86
commit
21a50b990f
2 files changed
+27
-5
No files matched your search
@@ -83,6 +83,16 @@
|
||||
return [_indexes objectAtIndex:position];
|
||||
}
|
||||
|
||||
- (void)setIndexes:(CPArray)theIndexes
|
||||
{
|
||||
_indexes = [theIndexes copy];
|
||||
}
|
||||
|
||||
- (CPArray)indexes
|
||||
{
|
||||
return [_indexes copy];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Modification
|
||||
|
||||
@@ -93,7 +103,7 @@
|
||||
|
||||
- (CPIndexPath)indexPathByRemovingLastIndex
|
||||
{
|
||||
return [CPIndexPath indexPathWithIndexes:_indexes length:[self length]];
|
||||
return [CPIndexPath indexPathWithIndexes:_indexes length:[self length] - 1];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@@ -35,11 +35,23 @@
|
||||
|
||||
- (void)testIndexPathByRemovingLastIndex
|
||||
{
|
||||
var ip = [indexPath indexes];
|
||||
[ip removeLastObject];
|
||||
// Keep removing indexes until the indexPath is empty
|
||||
while ([indexPath length] > 0)
|
||||
{
|
||||
var expectedIndexes = [[indexPath indexes] copy];
|
||||
[expectedIndexes removeObject:[expectedIndexes lastObject]];
|
||||
|
||||
[self assert:[CPIndexPath indexPathWithIndexes:ip]
|
||||
equals:[indexPath indexPathByRemovingLastIndex]];
|
||||
indexPath = [indexPath indexPathByRemovingLastIndex];
|
||||
[self assert:[CPIndexPath indexPathWithIndexes:expectedIndexes] equals:indexPath];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testIndexes
|
||||
{
|
||||
var newIndexes = [indexPath indexes];
|
||||
[newIndexes removeObjectAtIndex:0];
|
||||
|
||||
[self assert:[indexPath indexes] notEqual:newIndexes];
|
||||
}
|
||||
|
||||
- (void)testCompareThrowsOnNil
|
||||
|
||||
Reference in new issue
Block a user