Move Tokenizer tests loading into the helper HTML5Lib Tokenizer Test class
Helps keeping the test-case class uncluttered
This commit is contained in:
@@ -16,9 +16,6 @@
|
||||
#import "HTMLParser.h"
|
||||
#import "HTMLDocument.h"
|
||||
|
||||
static NSString * const HTML5LibTests = @"html5lib-tests";
|
||||
static NSString * const TOKENIZER = @"tokenizer";
|
||||
|
||||
#pragma mark - Extensions
|
||||
|
||||
@implementation HTMLParseErrorToken (Testing)
|
||||
@@ -33,7 +30,7 @@ static NSString * const TOKENIZER = @"tokenizer";
|
||||
#pragma mark - HTML5Lib Test Suite
|
||||
|
||||
@interface HTMLKitTokenizerTests : XCTestCase
|
||||
@property (nonatomic, strong) NSString *testFile;
|
||||
@property (nonatomic, strong) NSString *testName;
|
||||
@property (nonatomic, strong) NSArray *testsList;
|
||||
@end
|
||||
|
||||
@@ -43,7 +40,7 @@ static NSString * const TOKENIZER = @"tokenizer";
|
||||
{
|
||||
XCTestSuite *suite = [[XCTestSuite alloc] initWithName:NSStringFromClass(self)];
|
||||
|
||||
NSDictionary *testsMap = [self loadHTML5LibTokenizerTests];
|
||||
NSDictionary *testsMap = [HTML5LibTokenizerTest loadHTML5LibTokenizerTests];
|
||||
[testsMap enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||
[self addTestCaseForTestFile:key withTests:obj toTestSuite:suite];
|
||||
}];
|
||||
@@ -56,56 +53,21 @@ static NSString * const TOKENIZER = @"tokenizer";
|
||||
NSArray *allInvocations = [self testInvocations];
|
||||
for (NSInvocation *invocation in allInvocations) {
|
||||
XCTestCase *testCase = [[self alloc] initWithInvocation:invocation
|
||||
testFile:testFile
|
||||
testName:testFile
|
||||
tests:tests];
|
||||
[suite addTest:testCase];
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSDictionary *)loadHTML5LibTokenizerTests
|
||||
{
|
||||
NSString *path = [[NSBundle bundleForClass:self.class] resourcePath];
|
||||
path = [path stringByAppendingPathComponent:HTML5LibTests];
|
||||
path = [path stringByAppendingPathComponent:TOKENIZER];
|
||||
|
||||
NSMutableDictionary *testsMap = [NSMutableDictionary dictionary];
|
||||
NSArray *testFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
|
||||
|
||||
for (NSString *testFile in testFiles) {
|
||||
if (![testFile.pathExtension isEqualToString:@"test"]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *jsonPath = [path stringByAppendingPathComponent:testFile];
|
||||
NSString *json = [NSString stringWithContentsOfFile:jsonPath encoding:NSUTF8StringEncoding error:nil];
|
||||
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil];
|
||||
NSArray *jsonTests = [dictionary objectForKey:@"tests"];
|
||||
NSMutableArray *tests = [NSMutableArray array];
|
||||
|
||||
for (NSDictionary *test in jsonTests) {
|
||||
HTML5LibTokenizerTest *html5libTest = [[HTML5LibTokenizerTest alloc] initWithTestDictionary:test];
|
||||
html5libTest.testFile = testFile.stringByDeletingPathExtension;
|
||||
[tests addObject:html5libTest];
|
||||
}
|
||||
[testsMap setObject:tests forKey:testFile];
|
||||
}
|
||||
|
||||
return testsMap;
|
||||
}
|
||||
|
||||
#pragma mark - Instance
|
||||
|
||||
- (instancetype)initWithInvocation:(NSInvocation *)invocation
|
||||
testFile:(NSString *)testFile
|
||||
testName:(NSString *)testName
|
||||
tests:(NSArray *)tests
|
||||
{
|
||||
self = [super initWithInvocation:invocation];
|
||||
if (self) {
|
||||
_testFile = testFile;
|
||||
_testName = testName;
|
||||
_testsList = tests;
|
||||
}
|
||||
return self;
|
||||
@@ -114,7 +76,7 @@ static NSString * const TOKENIZER = @"tokenizer";
|
||||
- (NSString *)name
|
||||
{
|
||||
NSInvocation *invocation = [self invocation];
|
||||
NSString *title = self.testFile.stringByDeletingPathExtension;
|
||||
NSString *title = self.testName.stringByDeletingPathExtension;
|
||||
return [NSString stringWithFormat:@"-[%@ %@_%@]", self.class, NSStringFromSelector(invocation.selector), title];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user