Add -descendantNodeAtIndexPath: and tests to CPTreeNode

This commit is contained in:
Andreas authored and Andreas Falk committed 2010-11-13 12:06:43 +01:00
1 parent ab4dd1ac6d
commit 3a8773baec
2 files changed
+40

No files matched your search

+12
View File
@@ -87,6 +87,18 @@
[_childNodes[count] sortWithSortDescriptors:sortDescriptors recursively:YES];
}
- (CPTreeNode)descendantNodeAtIndexPath:(CPIndexPath)indexPath
{
var count = [indexPath length],
node = self;
for(var i = 0; i < count; i++) {
node = [node objectInChildNodesAtIndex:[indexPath indexAtPosition:i]];
}
return node;
}
@end
var CPTreeNodeRepresentedObjectKey = @"CPTreeNodeRepresentedObjectKey",
+28
View File
@@ -0,0 +1,28 @@
@import <AppKit/CPTreeNode.j>
@implementation CPTreeNodeTest : OJTestCase
{
CPTreeNode treeNode;
CPTreeNode childNode;
}
- (void)setUp
{
treeNode = [CPTreeNode treeNodeWithRepresentedObject:nil];
childNode = [CPTreeNode treeNodeWithRepresentedObject:nil];
[treeNode insertObject:childNode inChildNodesAtIndex:0];
}
- (void)testDescendantNodeAtIndexPath
{
var indexPath = [CPIndexPath indexPathWithIndex:0];
[self assert:childNode equals:[treeNode descendantNodeAtIndexPath:indexPath]];
indexPath = [CPIndexPath indexPathWithIndex:1];
[self assert:nil equals:[treeNode descendantNodeAtIndexPath:indexPath]];
}
@end