mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-02 11:12:58 +00:00
Updating CPData and CPDate to be subclassable. Only non-subclassable toll free bridged object is CPURL at this point.
This commit is contained in:
1 parent
a09878dcb4
commit
8e5471d0fe
3 files changed
+57
-3
No files matched your search
@@ -36,6 +36,7 @@
|
||||
|
||||
+ (id)alloc
|
||||
{
|
||||
if ([self class] !== CPData) return [super alloc];
|
||||
return new CFMutableData();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 1, 1, 0, 0, 0, 0));
|
||||
|
||||
+ (id)alloc
|
||||
{
|
||||
if ([self class] !== CPDate) return [super alloc];
|
||||
return new Date;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,48 @@
|
||||
@implementation SubclassTollFreeTest : OJTestCase
|
||||
|
||||
- (void)testThatSubclassTollFreeDoesAllowForSubclassing
|
||||
- (void)testThatSubclassTollFreeDoesAllowForSubclassingDictionary
|
||||
{
|
||||
var target = [[MyDict alloc] init];
|
||||
[OJAssert assert:@"a" equals:[target newMessage]];
|
||||
[OJAssert assert:0 equals:[target count]];
|
||||
}
|
||||
|
||||
- (void)testThatSubclassTollFreeDoesAllowForSubclassingString
|
||||
{
|
||||
var target = [[MyString alloc] initWithString:@"adsf"];
|
||||
[OJAssert assert:@"a" equals:[target newMessage]];
|
||||
[OJAssert assert:4 equals:[target length]];
|
||||
|
||||
var target2 = "agdsa";
|
||||
[OJAssert assertThrows:function(){ [target2 newMessage]; }];
|
||||
[OJAssert assert:5 equals:[target2 length]];
|
||||
}
|
||||
|
||||
- (void)testThatSubclassTollFreeDoesAllowForSubclassingNumber
|
||||
{
|
||||
[OJAssert assert:@"a" equals:[[[MyDict alloc] init] newMessage]];
|
||||
[OJAssert assert:@"a" equals:[[[MyString alloc] init] newMessage]];
|
||||
[OJAssert assert:@"a" equals:[[[MyNum alloc] init] newMessage]];
|
||||
}
|
||||
|
||||
- (void)testThatSubclassTollFreeDoesAllowForSubclassingException
|
||||
{
|
||||
[OJAssert assert:@"a" equals:[[[MyException alloc] init] newMessage]];
|
||||
}
|
||||
|
||||
- (void)testThatSubclassTollFreeDoesAllowForSubclassingArray
|
||||
{
|
||||
[OJAssert assert:@"a" equals:[[[MyArray alloc] init] newMessage]];
|
||||
}
|
||||
|
||||
- (void)testThatSubclassTollFreeDoesAllowForSubclassingDate
|
||||
{
|
||||
[OJAssert assert:@"a" equals:[[[MyDate alloc] init] newMessage]];
|
||||
}
|
||||
|
||||
- (void)testThatSubclassTollFreeDoesAllowForSubclassingData
|
||||
{
|
||||
[OJAssert assert:@"a" equals:[[[MyData alloc] init] newMessage]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@import <Foundation/CPDictionary.j>
|
||||
@@ -57,3 +91,21 @@
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MyDate : CPDate
|
||||
|
||||
- (id)newMessage
|
||||
{
|
||||
return "a";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MyData : CPData
|
||||
|
||||
- (id)newMessage
|
||||
{
|
||||
return "a";
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user