-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a mechanism for boxing nil arguments to prevent an exception when
generating an array of arguments #306 [#86329706]
- Loading branch information
Brian Croom
committed
Jan 17, 2015
1 parent
0d8a7ec
commit 01b7c35
Showing
7 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#import "CDRNil.h" | ||
|
||
@implementation CDRNil | ||
|
||
+ (instancetype)nilObject { | ||
return [[[self alloc] init] autorelease]; | ||
} | ||
|
||
- (BOOL)isEqual:(id)object { | ||
return object==self || [object isMemberOfClass:[self class]]; | ||
} | ||
|
||
- (NSString *)description { | ||
return @"<nil>"; | ||
} | ||
|
||
- (id)copyWithZone:(NSZone *)zone { | ||
return [self retain]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
* CDRNil is an internal class used to box 'nil' values when they need to be put into a | ||
* Cocoa collection. This is needed beside NSNull to allow differentiating between usages | ||
* of NSNull and true nils. | ||
*/ | ||
@interface CDRNil : NSObject <NSCopying> | ||
|
||
+ (instancetype)nilObject; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#import <Cedar/Cedar.h> | ||
#import "CDRNil.h" | ||
|
||
using namespace Cedar::Matchers; | ||
using namespace Cedar::Doubles; | ||
|
||
SPEC_BEGIN(CDRNilSpec) | ||
|
||
describe(@"CDRNil", ^{ | ||
__block CDRNil *nilObject; | ||
|
||
beforeEach(^{ | ||
nilObject = [CDRNil nilObject]; | ||
}); | ||
|
||
it(@"should return itself when copied", ^{ | ||
CDRNil *copiedNil = [[nilObject copy] autorelease]; | ||
copiedNil should be_same_instance_as(nilObject); | ||
}); | ||
|
||
it(@"should be equal to other instances of CDRNil", ^{ | ||
CDRNil *anotherNil = [CDRNil nilObject]; | ||
anotherNil should equal(nilObject); | ||
}); | ||
|
||
it(@"should have a clear description indicating what it represents", ^{ | ||
[nilObject description] should equal(@"<nil>"); | ||
}); | ||
}); | ||
|
||
SPEC_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters