Fixed: comparing a CPNumber vs nil or CPNull didn't throw an exception.

In Objective-C, both `[@34 compare:nil]` and `[@34 compare:[CPNull null]]` throw invalid argument exceptions.

This fix makes the same true in Objective-J.

Refs #1959.
This commit is contained in:
Alexander Ljungberg committed 2013-07-15 10:47:38 +01:00
1 parent 315e3fccf3
commit 0f53ceda30
2 files changed
+20

No files matched your search

+5
View File
@@ -20,6 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "CPException.j"
@import "CPNull.j"
@import "CPObject.j"
@import "CPObjJRuntime.j"
@@ -314,6 +316,9 @@ FIXME: Do we need this?
- (CPComparisonResult)compare:(CPNumber)aNumber
{
if (aNumber === nil || aNumber['isa'] === CPNull)
[CPException raise:CPInvalidArgumentException reason:"nil argument"];
if (self > aNumber)
return CPOrderedDescending;
else if (self < aNumber)
+15
View File
@@ -0,0 +1,15 @@
@import <Foundation/CPNumber.j>
@implementation CPNumberTest : OJTestCase
- (void)testCompareWithNil
{
[self assertThrows:function () { [34 compare:nil] }];
}
- (void)testCompareWithCPNull
{
[self assertThrows:function () { [34 compare:[CPNull null]] }];
}
@end