Merge pull request #1602 from mrcarlberg/sort_using_descriptors_with_key_path

Fixed sortUsingDescriptors: so it can handle sort descriptors with a key path
This commit is contained in:
aparajita committed 2012-07-12 08:19:46 -07:00
commit 25f51eb5cd
2 files changed
+18 -2

No files matched your search

+2 -2
View File
@@ -485,7 +485,7 @@ var sortArrayUsingJSDescriptors = function(a, d)
do
{
key = d[cn].k;
C1[key] = [A valueForKey:key];
C1[key] = [A valueForKeyPath:key];
} while (cn--)
c[aUID] = C1;
@@ -506,7 +506,7 @@ var sortArrayUsingJSDescriptors = function(a, d)
do
{
key = d[cn].k;
C2[key] = [B[i] valueForKey:key];
C2[key] = [B[i] valueForKeyPath:key];
} while (cn--)
c[bUID] = C2;
+16
View File
@@ -657,6 +657,22 @@
[self assertTrue:s2[1] === a message:s2[1] + " is larger then " + a + " when sorting case insensitive"];
}
- (void)testSortUsingDescriptorsWithKeyPath
{
var a = [CPDictionary dictionaryWithJSObject:{"a": "AB", "b": "ba"}],
b = [CPDictionary dictionaryWithJSObject:{"a": "aa", "b": "BB"}],
A = [CPDictionary dictionaryWithJSObject:{"x": a}],
B = [CPDictionary dictionaryWithJSObject:{"x": b}],
array = [A, B],
d1 = [[CPSortDescriptor sortDescriptorWithKey:@"x.b" ascending:YES selector:@selector(compare:)]],
d2 = [[CPSortDescriptor sortDescriptorWithKey:@"x.b" ascending:NO selector:@selector(compare:)]],
s1 = [array sortedArrayUsingDescriptors:d1],
s2 = [array sortedArrayUsingDescriptors:d2];
[self assertTrue:s1[1] === A message:s1[1] + " is larger then " + A + " when sorting ascending"];
[self assertTrue:s2[0] === A message:s2[0] + " is larger then " + A + " when sorting descending"];
}
@end
@implementation AlwaysEqual : CPObject