diff --git a/Foundation/CPArray/CPMutableArray.j b/Foundation/CPArray/CPMutableArray.j index f62ae1c06..2f6fcc58f 100644 --- a/Foundation/CPArray/CPMutableArray.j +++ b/Foundation/CPArray/CPMutableArray.j @@ -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) diff --git a/Tests/Foundation/CPArrayTest.j b/Tests/Foundation/CPArrayTest.j index 75951c471..a99dfc931 100644 --- a/Tests/Foundation/CPArrayTest.j +++ b/Tests/Foundation/CPArrayTest.j @@ -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