Files
HTMLKit/Tests/HTMLKitTestUtil.m
T
iska 356709a096 Use a weak-memory NSHashTable for referencing iterators in HTML Document
This breaks the retain cycle between the document and the attached node
iterator.

Fixes #4
2017-02-22 23:54:55 +01:00

36 lines
990 B
Objective-C

//
// HTMLKitTestUtil.m
// HTMLKit
//
// Created by Iska on 11/04/16.
// Copyright © 2016 BrainCookie. All rights reserved.
//
#import "HTMLKitTestUtil.h"
#import <objc/runtime.h>
@implementation HTMLKitTestUtil
+ (NSInvocation *)addTestToClass:(Class)cls withName:(NSString *)name block:(id)block
{
IMP implementation = imp_implementationWithBlock(block);
const char *types = [[NSString stringWithFormat:@"%s%s%s", @encode(id), @encode(id), @encode(SEL)] UTF8String];
SEL selector = NSSelectorFromString(name);
class_addMethod(cls, selector, implementation, types);
NSMethodSignature *signature = [cls instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
invocation.selector = selector;
return invocation;
}
+ (id)ivarForInstacne:(id)instance name:(NSString *)name
{
Ivar ivar = class_getInstanceVariable([instance class], [name UTF8String]);
return object_getIvar(instance, ivar);
}
@end