mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-08 18:01:00 +00:00
SortUsingDescriptors: Using the selector in the descriptor instead of always using compare:
This commit is contained in:
1 parent
dc30092b60
commit
d7ff93f7f2
2 files changed
+21
-5
No files matched your search
@@ -340,7 +340,7 @@
|
||||
while (i--)
|
||||
{
|
||||
var d = [descriptors objectAtIndex:i];
|
||||
[jsDescriptors addObject:{ "k": [d key], "a": [d ascending]}];
|
||||
[jsDescriptors addObject:{ "k": [d key], "a": [d ascending], "s": [d selector]}];
|
||||
}
|
||||
sortArrayUsingJSDescriptors(self, jsDescriptors);
|
||||
}
|
||||
@@ -460,7 +460,8 @@ var sortArrayUsingJSDescriptors = function sortArrayUsingJSDescriptors(a, d)
|
||||
cn,
|
||||
aUID,
|
||||
bUID,
|
||||
key;
|
||||
key,
|
||||
dd;
|
||||
|
||||
if (dl < 0)
|
||||
return;
|
||||
@@ -511,9 +512,10 @@ var sortArrayUsingJSDescriptors = function sortArrayUsingJSDescriptors(a, d)
|
||||
cn = dl;
|
||||
do
|
||||
{
|
||||
key = d[cn].k;
|
||||
o = [C1[key] compare:C2[key]];
|
||||
if (o && !d[cn].a)
|
||||
dd = d[cn];
|
||||
key = dd.k;
|
||||
o = objj_msgSend(C1[key], dd.s, C2[key]);
|
||||
if (o && !dd.a)
|
||||
o = -o;
|
||||
} while (cn-- && o == CPOrderedSame)
|
||||
if (o >= 0)
|
||||
|
||||
@@ -539,6 +539,20 @@
|
||||
[self assertTrue:d.indexOf("y: 6") !== -1 message:"Can't find 'y: 6' in description of array " + d];
|
||||
}
|
||||
|
||||
- (void)testSortUsingDescriptorsWithDifferentSelectors
|
||||
{
|
||||
var a = [CPDictionary dictionaryWithJSObject:{"a": "AB", "b": "ba"}],
|
||||
b = [CPDictionary dictionaryWithJSObject:{"a": "aa", "b": "BB"}],
|
||||
array = [a, b],
|
||||
d1 = [[CPSortDescriptor sortDescriptorWithKey:@"a" ascending:YES selector:@selector(compare:)]],
|
||||
d2 = [[CPSortDescriptor sortDescriptorWithKey:@"a" ascending:YES selector:@selector(caseInsensitiveCompare:)]],
|
||||
s1 = [array sortedArrayUsingDescriptors:d1],
|
||||
s2 = [array sortedArrayUsingDescriptors:d2];
|
||||
|
||||
[self assertTrue:s1[0] === a message:s1[0] + " is larger then " + a + " when sorting case sensitive"];
|
||||
[self assertTrue:s2[1] === a message:s2[1] + " is larger then " + a + " when sorting case insensitive"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation AlwaysEqual : CPObject
|
||||
|
||||
Reference in new issue
Block a user