mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
The Objective-J parser and compiler now handles protocol syntax. The Objective-J runtime has new functions to handle protocols. The method 'conformsToProtocol:' has been added to CPObject as an instance and a class method.
73 lines
1.3 KiB
Plaintext
73 lines
1.3 KiB
Plaintext
@import <Foundation/Foundation.j>
|
|
|
|
@protocol MyProtocol
|
|
|
|
- (int)myFunction:(int)aValue;
|
|
|
|
@end
|
|
|
|
@protocol MyProtocol2
|
|
|
|
- (int)myFunction2:(int)aValue;
|
|
|
|
@end
|
|
|
|
@protocol MyProtocol3 <MyProtocol, MyProtocol2>
|
|
|
|
- (int)myFunction3:(int)aValue;
|
|
|
|
@end
|
|
|
|
@implementation MyClass : CPObject <MyProtocol>
|
|
|
|
- (int)myOtherFunction:(int)aValue
|
|
{
|
|
return aValue * 2;
|
|
}
|
|
|
|
- (int)myFunction:(int)aValue
|
|
{
|
|
return aValue * 2;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation MyClass2 : CPObject <MyProtocol3>
|
|
|
|
- (int)myOtherFunction:(int)aValue
|
|
{
|
|
return aValue * 2;
|
|
}
|
|
|
|
- (int)myFunction:(int)aValue
|
|
{
|
|
return aValue * 2;
|
|
}
|
|
|
|
- (int)myFunction2:(int)aValue
|
|
{
|
|
return aValue * 2;
|
|
}
|
|
|
|
- (int)myFunction3:(int)aValue
|
|
{
|
|
return aValue * 2;
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation ProtocolTest : OJTestCase
|
|
|
|
- (void)testConformsToProtocol
|
|
{
|
|
[self assert:true equals:[[[MyClass alloc] init] conformsToProtocol:@protocol(MyProtocol)]];
|
|
[self assert:false equals:[[[MyClass alloc] init] conformsToProtocol:@protocol(MyProtocol2)]];
|
|
[self assert:false equals:[[[MyClass alloc] init] conformsToProtocol:@protocol(xxxxxx)]];
|
|
[self assert:true equals:[[[MyClass2 alloc] init] conformsToProtocol:@protocol(MyProtocol)]];
|
|
[self assert:true equals:[[[MyClass2 alloc] init] conformsToProtocol:@protocol(MyProtocol2)]];
|
|
[self assert:true equals:[[[MyClass2 alloc] init] conformsToProtocol:@protocol(MyProtocol3)]];
|
|
}
|
|
|
|
@end
|