mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-13 06:01:28 +00:00
New: CPObject instancesImplementSelector:(SEL)aSelector
Tests if instances of given class implement a selector. With test. Note: The naming is from cocoa where this method is semi-public.
This commit is contained in:
+15
-5
@@ -275,13 +275,13 @@ CPLog(@"Got some class: %@", inst);
|
||||
}
|
||||
|
||||
/*!
|
||||
Tests if the receiver implements the provided selector regardless of inheritance.
|
||||
@param aSelector the selector for which to test the receiver
|
||||
@return \c YES if the receiver implements the selector
|
||||
Tests if instances of a given class implement the provided selector regardless of inheritance.
|
||||
@param aSelector the selector for which to test the class
|
||||
@return \c YES if instances of the class implement the selector
|
||||
*/
|
||||
- (BOOL)implementsSelector:(SEL)aSelector
|
||||
+ (BOOL)instancesImplementSelector:(SEL)aSelector
|
||||
{
|
||||
var methods = class_copyMethodList([self class]),
|
||||
var methods = class_copyMethodList(self),
|
||||
count = methods.length;
|
||||
|
||||
while (count--)
|
||||
@@ -291,6 +291,16 @@ CPLog(@"Got some class: %@", inst);
|
||||
return NO;
|
||||
}
|
||||
|
||||
/*!
|
||||
Tests if the receiver implements the provided selector regardless of inheritance.
|
||||
@param aSelector the selector for which to test the receiver
|
||||
@return \c YES if the receiver implements the selector
|
||||
*/
|
||||
- (BOOL)implementsSelector:(SEL)aSelector
|
||||
{
|
||||
return [[self class] instancesImplementSelector:aSelector];
|
||||
}
|
||||
|
||||
/*!
|
||||
Test whether instances of this class conforms to the provided protocol.
|
||||
@param aProtocol the protocol for which to test the class
|
||||
|
||||
@@ -25,6 +25,15 @@
|
||||
[self assertFalse:[receiver implementsSelector:@selector(notImplementedInSuperNorReceiver)]];
|
||||
}
|
||||
|
||||
- (void)testInstancesImplementSelector
|
||||
{
|
||||
[self assertTrue:[Receiver instancesImplementSelector:@selector(implementedInReceiverAndSuper)]];
|
||||
[self assertTrue:[Receiver instancesImplementSelector:@selector(implementedInReceiverOnly)]];
|
||||
|
||||
[self assertFalse:[Receiver instancesImplementSelector:@selector(implementedInSuperOnly)]];
|
||||
[self assertFalse:[Receiver instancesImplementSelector:@selector(notImplementedInSuperNorReceiver)]];
|
||||
}
|
||||
|
||||
- (void)testVersion
|
||||
{
|
||||
// zero by default
|
||||
|
||||
Reference in New Issue
Block a user