diff --git a/Foundation/CPArray/CPMutableArray.j b/Foundation/CPArray/CPMutableArray.j index 308390429..629bb9382 100644 --- a/Foundation/CPArray/CPMutableArray.j +++ b/Foundation/CPArray/CPMutableArray.j @@ -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; diff --git a/Tests/Foundation/CPArrayTest.j b/Tests/Foundation/CPArrayTest.j index df51505f4..0c4e23cd4 100644 --- a/Tests/Foundation/CPArrayTest.j +++ b/Tests/Foundation/CPArrayTest.j @@ -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