diff --git a/Tests/base/NSDictionary/sort.m b/Tests/base/NSDictionary/sort.m index 81ccb71e3..a549b5ba7 100644 --- a/Tests/base/NSDictionary/sort.m +++ b/Tests/base/NSDictionary/sort.m @@ -7,37 +7,54 @@ int main() { - NSAutoreleasePool *arp = [NSAutoreleasePool new]; + START_SET("NSDictionary Sorting") + NSDictionary *d; + NSArray *keysOrderedByKeyedValue; - NSArray* values = [NSArray arrayWithObjects: - [NSNumber numberWithFloat:2.0], - [NSNumber numberWithFloat:1.0], - [NSNumber numberWithFloat:3.0], - [NSNumber numberWithFloat:4.0], - nil]; + NSArray *values = [NSArray arrayWithObjects: + [NSNumber numberWithFloat: 2.0], + [NSNumber numberWithFloat: 1.0], + [NSNumber numberWithFloat: 3.0], + [NSNumber numberWithFloat: 4.0], + nil]; - NSArray* keys = [NSArray arrayWithObjects: - @"shouldSortToSecond", - @"shouldSortToFirst", - @"shouldSortToThird", - @"shouldSortToFourth", - nil]; + NSArray *keys = [NSArray arrayWithObjects: + @"shouldSortToSecond", + @"shouldSortToFirst", + @"shouldSortToThird", + @"shouldSortToFourth", + nil]; - NSDictionary *d = [NSDictionary dictionaryWithObjects:values forKeys:keys]; - NSArray* keysOrderedByKeyedValue = [d keysSortedByValueUsingComparator: - ^NSComparisonResult(id obj1, id obj2) { - return [(NSNumber*)obj1 compare:(NSNumber*)obj2]; - }]; + NSArray *expected = [NSArray arrayWithObjects: + @"shouldSortToFirst", + @"shouldSortToSecond", + @"shouldSortToThird", + @"shouldSortToFourth", + nil]; - NSArray* expected = [NSArray arrayWithObjects: - @"shouldSortToFirst", - @"shouldSortToSecond", - @"shouldSortToThird", - @"shouldSortToFourth", - nil]; + d = [NSDictionary dictionaryWithObjects: values forKeys: keys]; + keysOrderedByKeyedValue = [d keysSortedByValueUsingSelector: + @selector(compare:)]; - PASS([keysOrderedByKeyedValue isEqual:expected], "Can sort a dictionary's keys by its values"); + PASS([keysOrderedByKeyedValue isEqual: expected], + "Can sort a dictionary's keys by its values using a selector"); +# ifndef __has_feature +# define __has_feature(x) 0 +# endif +# if __has_feature(blocks) + d = [NSDictionary dictionaryWithObjects: values forKeys: keys]; + keysOrderedByKeyedValue = [d keysSortedByValueUsingComparator: + ^NSComparisonResult(id obj1, id obj2) { + return [(NSNumber*)obj1 compare: (NSNumber*)obj2]; + }]; + + PASS([keysOrderedByKeyedValue isEqual: expected], + "Can sort a dictionary's keys by its values using a comparator"); +# else + SKIP("No Blocks support in the compiler.") +# endif + + END_SET("NSDictionary Sorting") - [arp release]; arp = nil; return 0; }