mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-14 14:41:28 +00:00
New: CPString 'compare:' method handles nil and CPNull in correct way
This is the same way as Cocoa works. Also added test case.
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
@import "CPSortDescriptor.j"
|
||||
@import "CPURL.j"
|
||||
@import "CPValue.j"
|
||||
@import "CPNull.j"
|
||||
|
||||
@class CPException
|
||||
@class CPURL
|
||||
@@ -496,6 +497,9 @@ var CPStringUIDs = new CFMutableDictionary(),
|
||||
return [self compare:aString options:CPCaseInsensitiveSearch];
|
||||
}
|
||||
|
||||
// This is for speed
|
||||
var CPStringNull = [CPNull null];
|
||||
|
||||
/*!
|
||||
Compares the receiver to the specified string, using options.
|
||||
@param aString the string with which to compare
|
||||
@@ -504,6 +508,10 @@ var CPStringUIDs = new CFMutableDictionary(),
|
||||
*/
|
||||
- (CPComparisonResult)compare:(CPString)aString options:(int)aMask
|
||||
{
|
||||
if (aString === nil) return CPOrderedDescending;
|
||||
|
||||
if (aString === CPStringNull) [CPException raise:CPInvalidArgumentException reason:"compare: argument can't be 'CPNull'"];
|
||||
|
||||
var lhs = self,
|
||||
rhs = aString;
|
||||
|
||||
|
||||
@@ -566,4 +566,10 @@
|
||||
[self assert:"This is a test none" equals:[noneString stringByTrimmingCharactersInSet:set]];
|
||||
}
|
||||
|
||||
- (void)testCompareWithNil
|
||||
{
|
||||
[self assert:CPOrderedDescending equals:[@"Objective-J" compare:nil]];
|
||||
[self assertThrows:function () { [@"Objective-J" compare:[CPNull null]] }];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user