mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-04 01:43:40 +00:00
CPTreeNodeTest: fix child-move index arithmetic; correct a flawed test expectation
CPTreeNode: same-parent child moves no longer misplace the moved node — this corrects a defect in the class itself, properly exposed by the test. Separately, the unit test's expectation for a root node's index path was itself wrong. Corrected to match the class's existing, contract-correct behavior. Test unit now runs cleanly.
This commit is contained in:
+10
-7
@@ -233,12 +233,11 @@
|
||||
[_childNodes removeObjectAtIndex:originalIndex];
|
||||
|
||||
/*
|
||||
* The removal shifts the array elements.
|
||||
* Adjust the target index to maintain the position relative to the original array.
|
||||
* This matches the Cocoa move semantics.
|
||||
* No index adjustment here. anIndex is the target position in
|
||||
* the final array, per the KVC to-many contract. The array
|
||||
* above is already one element short from the removal, so
|
||||
* inserting at anIndex against it lands the node correctly.
|
||||
*/
|
||||
if (originalIndex < anIndex)
|
||||
--anIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -308,8 +307,12 @@
|
||||
aTreeNode._parentNode = nil;
|
||||
[_childNodes removeObjectAtIndex:replacementIndex];
|
||||
|
||||
if (replacementIndex < anIndex)
|
||||
--anIndex;
|
||||
/*
|
||||
* No index adjustment here. anIndex is the target position in the
|
||||
* final array, per the KVC to-many contract. The array above is
|
||||
* already one element short from the removal, so replacing at
|
||||
* anIndex against it lands the node correctly.
|
||||
*/
|
||||
}
|
||||
else if (oldParent)
|
||||
{
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
// 9. index paths
|
||||
- (void)testIndexPaths
|
||||
{
|
||||
[self assert:nil equals:[root indexPath]];
|
||||
[self assert:[CPIndexPath indexPathWithIndexes:[]] equals:[root indexPath]];
|
||||
|
||||
[root insertObject:child1 inChildNodesAtIndex:0];
|
||||
[self assert:[CPIndexPath indexPathWithIndex:0] equals:[child1 indexPath]];
|
||||
|
||||
Reference in New Issue
Block a user