Files
cappuccino/Tests/Objective-J/Preprocessor/BehaviorTests/ProtocolTest.j
T
Martin Carlberg d38125db13 New: Added Objective-J protocol support
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.
2013-08-09 19:02:45 +02:00

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