From fdd7a8d2bce894305e5b857381e88444c262731d Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Wed, 28 Jul 2010 19:03:43 -0400 Subject: [PATCH] Fix for issue #782 (CPIndexSet shiftIndexesStartingAtIndex:by: bug) --- Foundation/CPIndexSet.j | 4 ++-- Tests/Foundation/CPIndexSetTest.j | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Foundation/CPIndexSet.j b/Foundation/CPIndexSet.j index 266c7273e..91855dc9b 100644 --- a/Foundation/CPIndexSet.j +++ b/Foundation/CPIndexSet.j @@ -698,12 +698,12 @@ var range = _ranges[i], maximum = CPMaxRange(range); - if (anIndex > maximum) + if (anIndex >= maximum) break; // If our index is within our range, but not the first index, // then this range will be split. - if (anIndex > range.location && anIndex < maximum) + if (anIndex > range.location) { // Split the range into shift and unshifted. shifted = CPMakeRange(anIndex + aDelta, maximum - anIndex); diff --git a/Tests/Foundation/CPIndexSetTest.j b/Tests/Foundation/CPIndexSetTest.j index c38778903..b244b8e1d 100644 --- a/Tests/Foundation/CPIndexSetTest.j +++ b/Tests/Foundation/CPIndexSetTest.j @@ -366,6 +366,13 @@ function descriptionWithoutEntity(aString) // negative delta for downward shift [_set shiftIndexesStartingAtIndex:1 by:-1]; [self assertTrue:[_set containsIndexes:[CPIndexSet indexSetWithIndexesInRange:startRange]]]; + + // test for fix to issue #746 (last item is mistakenly shifted) + _set = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, 1)]; + [self assertTrue:[_set lastIndex] === 0]; + + [_set shiftIndexesStartingAtIndex:[_set lastIndex] + 1 by:1]; + [self assertTrue:[_set lastIndex] === 0]; } - (void)tearDown