mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-06 17:12:50 +00:00
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:
commit
25f51eb5cd
2 files changed
+18
-2
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user