diff --git a/HTMLKit.xcodeproj/project.pbxproj b/HTMLKit.xcodeproj/project.pbxproj
index 1e8c80f..5667236 100644
--- a/HTMLKit.xcodeproj/project.pbxproj
+++ b/HTMLKit.xcodeproj/project.pbxproj
@@ -42,6 +42,8 @@
625D0F041C2717DE00D7BEB0 /* HTMLNode+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 625D0F011C2717DE00D7BEB0 /* HTMLNode+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
625EE4571CBAA41D00F2CC8E /* HTMLKitTestObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 625EE4561CBAA41D00F2CC8E /* HTMLKitTestObserver.m */; };
625EE4581CBAA41D00F2CC8E /* HTMLKitTestObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 625EE4561CBAA41D00F2CC8E /* HTMLKitTestObserver.m */; };
+ 625EE45B1CBB171300F2CC8E /* HTMLKitTestUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 625EE45A1CBB171300F2CC8E /* HTMLKitTestUtil.m */; };
+ 625EE45C1CBB171300F2CC8E /* HTMLKitTestUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 625EE45A1CBB171300F2CC8E /* HTMLKitTestUtil.m */; };
628AF6301BC99A6C00496128 /* CSSNthExpressionsParserTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 628AF62E1BC99A6C00496128 /* CSSNthExpressionsParserTests.m */; };
62D8345A19FB1AC4009205A9 /* HTML5LibTokenizerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 62D8345819FB1AC4009205A9 /* HTML5LibTokenizerTest.m */; };
62EC7AE71AEEAC6F0015D3BE /* HTMLKitMutationAlgorithmsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 62EC7AE51AEEAC6F0015D3BE /* HTMLKitMutationAlgorithmsTests.m */; };
@@ -397,6 +399,8 @@
625D0F011C2717DE00D7BEB0 /* HTMLNode+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HTMLNode+Private.h"; sourceTree = ""; };
625EE4551CBAA41D00F2CC8E /* HTMLKitTestObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLKitTestObserver.h; sourceTree = ""; };
625EE4561CBAA41D00F2CC8E /* HTMLKitTestObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTMLKitTestObserver.m; sourceTree = ""; };
+ 625EE4591CBB171300F2CC8E /* HTMLKitTestUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLKitTestUtil.h; sourceTree = ""; };
+ 625EE45A1CBB171300F2CC8E /* HTMLKitTestUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTMLKitTestUtil.m; sourceTree = ""; };
626652F81C03D30F00C3F121 /* HTMLKitErrorDomain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTMLKitErrorDomain.h; sourceTree = ""; };
6279F87119E17DC700F12EE5 /* HTMLParserInsertionModes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTMLParserInsertionModes.h; sourceTree = ""; };
6279F87219E1808D00F12EE5 /* HTMLElement.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = HTMLElement.h; sourceTree = ""; };
@@ -659,6 +663,8 @@
625A14CB19C7829400AD0C32 /* Supporting Files */,
625EE4551CBAA41D00F2CC8E /* HTMLKitTestObserver.h */,
625EE4561CBAA41D00F2CC8E /* HTMLKitTestObserver.m */,
+ 625EE4591CBB171300F2CC8E /* HTMLKitTestUtil.h */,
+ 625EE45A1CBB171300F2CC8E /* HTMLKitTestUtil.m */,
);
name = Tests;
path = HTMLKitTests;
@@ -1175,6 +1181,7 @@
624FC37B1AE591D80015DDF9 /* HTMLKitNodesTests.m in Sources */,
621FBE5B1BDAD68700BC9555 /* CSSSelectorParserTests.m in Sources */,
621FBE5E1BDAD90200BC9555 /* CSSCombinatorSelectorTests.m in Sources */,
+ 625EE45B1CBB171300F2CC8E /* HTMLKitTestUtil.m in Sources */,
628AF6301BC99A6C00496128 /* CSSNthExpressionsParserTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1256,6 +1263,7 @@
62ECBFD91C0B6E2E00AF847B /* CSSTypeSelectorTests.m in Sources */,
62ECBFDA1C0B6E2E00AF847B /* CSSAttributeSelectorTests.m in Sources */,
62ECBFDB1C0B6E2E00AF847B /* CSSNThExpressionSelectorTests.m in Sources */,
+ 625EE45C1CBB171300F2CC8E /* HTMLKitTestUtil.m in Sources */,
62ECBFDC1C0B6E2E00AF847B /* CSSCombinatorSelectorTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
diff --git a/HTMLKitTests/HTML5LibTokenizerTest.h b/HTMLKitTests/HTML5LibTokenizerTest.h
index 893973d..7fefe44 100644
--- a/HTMLKitTests/HTML5LibTokenizerTest.h
+++ b/HTMLKitTests/HTML5LibTokenizerTest.h
@@ -10,7 +10,7 @@
@interface HTML5LibTokenizerTest : NSObject
-@property (nonatomic, copy) NSString *testName;
+@property (nonatomic, copy) NSString *testFile;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *input;
@property (nonatomic, strong) NSArray *output;
diff --git a/HTMLKitTests/HTML5LibTokenizerTest.m b/HTMLKitTests/HTML5LibTokenizerTest.m
index e5a09e9..f864634 100644
--- a/HTMLKitTests/HTML5LibTokenizerTest.m
+++ b/HTMLKitTests/HTML5LibTokenizerTest.m
@@ -39,7 +39,7 @@ static NSString * const TOKENIZER = @"tokenizer";
+ (NSArray *)loadTestsWithFileAtPath:(NSString *)filePath
{
- NSString *testName = filePath.lastPathComponent.stringByDeletingLastPathComponent;
+ NSString *testFile = filePath.lastPathComponent;
NSString *json = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
@@ -52,7 +52,7 @@ static NSString * const TOKENIZER = @"tokenizer";
for (NSDictionary *test in jsonTests) {
HTML5LibTokenizerTest *html5libTest = [[HTML5LibTokenizerTest alloc] initWithTestDictionary:test];
- html5libTest.testName = testName;
+ html5libTest.testFile = testFile;
[tests addObject:html5libTest];
}
return tests;
diff --git a/HTMLKitTests/HTMLKitTestObserver.m b/HTMLKitTests/HTMLKitTestObserver.m
index 37210b2..fc81acf 100644
--- a/HTMLKitTests/HTMLKitTestObserver.m
+++ b/HTMLKitTests/HTMLKitTestObserver.m
@@ -69,7 +69,7 @@
NSUInteger totalCount = _cases.count;
NSUInteger failureCount = failedTests.count;
- [reportDescription appendFormat:@"HTML5Lib test file: [%@] - failed: [%lu] out of [%lu] total tests\n", _name, failureCount, _cases.count];
+ [reportDescription appendFormat:@"HTML5Lib test %@ failed [%lu] out of [%lu] total tests\n", _name, failureCount, _cases.count];
for (NSDictionary *testCase in failedTests) {
[reportDescription appendFormat:@"Failed test for input: %@\n", testCase[@"input"]];
diff --git a/HTMLKitTests/HTMLKitTestUtil.h b/HTMLKitTests/HTMLKitTestUtil.h
new file mode 100644
index 0000000..47abfae
--- /dev/null
+++ b/HTMLKitTests/HTMLKitTestUtil.h
@@ -0,0 +1,15 @@
+//
+// HTMLKitTestUtil.h
+// HTMLKit
+//
+// Created by Iska on 11/04/16.
+// Copyright © 2016 BrainCookie. All rights reserved.
+//
+
+#import
+
+@interface HTMLKitTestUtil : NSObject
+
++ (NSInvocation *)addTestToClass:(Class)cls withName:(NSString *)name block:(id)block;
+
+@end
diff --git a/HTMLKitTests/HTMLKitTestUtil.m b/HTMLKitTests/HTMLKitTestUtil.m
new file mode 100644
index 0000000..ac43bee
--- /dev/null
+++ b/HTMLKitTests/HTMLKitTestUtil.m
@@ -0,0 +1,29 @@
+//
+// HTMLKitTestUtil.m
+// HTMLKit
+//
+// Created by Iska on 11/04/16.
+// Copyright © 2016 BrainCookie. All rights reserved.
+//
+
+#import "HTMLKitTestUtil.h"
+#import
+
+@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;
+}
+
+@end
diff --git a/HTMLKitTests/HTMLKitTokenizerTests.m b/HTMLKitTests/HTMLKitTokenizerTests.m
index 7845f8a..b11d918 100644
--- a/HTMLKitTests/HTMLKitTokenizerTests.m
+++ b/HTMLKitTests/HTMLKitTokenizerTests.m
@@ -7,10 +7,10 @@
//
#import
-#import
+
+#import "HTMLKitTestUtil.h"
#import "HTML5LibTokenizerTest.h"
-
#import "HTMLTokenizer.h"
#import "HTMLTokenizerStates.h"
#import "HTMLTokens.h"
@@ -32,7 +32,6 @@
#pragma mark - HTML5Lib Test Suite
@interface HTMLKitTokenizerTests : XCTestCase
-@property (nonatomic, strong) NSString *testName;
@property (nonatomic, strong) NSArray *testsList;
@end
@@ -52,19 +51,12 @@
+ (void)addTestCaseForTestFile:(NSString *)testFile withTests:(NSArray *)tests toTestSuite:(XCTestSuite *)suite
{
- IMP implementation = imp_implementationWithBlock(^ (HTMLKitTokenizerTests *instance){
- [instance runTests];
- });
- const char *types = [[NSString stringWithFormat:@"%s%s%s", @encode(id), @encode(id), @encode(SEL)] UTF8String];
-
NSString *testName = [testFile.stringByDeletingPathExtension stringByReplacingOccurrencesOfString:@"-" withString:@"_"];
- NSString *selectorName = [NSString stringWithFormat:@"testTokenizer__%@", testName];
- SEL selector = NSSelectorFromString(selectorName);
- class_addMethod(self, selector, implementation, types);
+ testName = [NSString stringWithFormat:@"testTokenizer__%@", testName];
- NSMethodSignature *signature = [self instanceMethodSignatureForSelector:selector];
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
- invocation.selector = selector;
+ NSInvocation *invocation = [HTMLKitTestUtil addTestToClass:self withName:testName block:^ (HTMLKitTokenizerTests *instance){
+ [instance runTests];
+ }];
XCTestCase *testCase = [[self alloc] initWithInvocation:invocation tests:tests];
[suite addTest:testCase];
@@ -81,18 +73,6 @@
return self;
}
-- (NSString *)name
-{
- NSInvocation *invocation = [self invocation];
- NSString *title = self.testName.stringByDeletingPathExtension;
- return [NSString stringWithFormat:@"-[%@ %@_%@]", self.class, NSStringFromSelector(invocation.selector), title];
-}
-
-- (NSString *)description
-{
- return self.name;
-}
-
#pragma mark - Tests
- (void)runTests
@@ -109,7 +89,7 @@
NSArray *tokens = tokenizer.allObjects;
NSString *message = [NSString stringWithFormat:@"HTML5Lib test in file: \'%@\' Title: '%@'\nInput: '%@'\nExpected:\n%@\nActual:\n%@\n",
- self.testName,
+ test.testFile,
test.title,
test.input,
expectedTokens,
diff --git a/HTMLKitTests/HTMLKitTreeConstructionTests.m b/HTMLKitTests/HTMLKitTreeConstructionTests.m
index befef66..f001278 100644
--- a/HTMLKitTests/HTMLKitTreeConstructionTests.m
+++ b/HTMLKitTests/HTMLKitTreeConstructionTests.m
@@ -7,7 +7,8 @@
//
#import
-#import
+
+#import "HTMLKitTestUtil.h"
#import "HTMLKitTestObserver.h"
#import "HTML5LibTreeConstructionTest.h"
@@ -31,8 +32,6 @@
{
HTMLKitTestObserver *_observer;
}
-
-@property (nonatomic, strong) NSString *testName;
@property (nonatomic, strong) NSArray *testsList;
@end
@@ -51,19 +50,12 @@
+ (void)addTestCaseForTestFile:(NSString *)testFile withTests:(NSArray *)tests toTestSuite:(XCTestSuite *)suite
{
- IMP implementation = imp_implementationWithBlock(^ (HTMLKitTreeConstructionTests *instance){
- [instance runTests];
- });
- const char *types = [[NSString stringWithFormat:@"%s%s%s", @encode(id), @encode(id), @encode(SEL)] UTF8String];
-
NSString *testName = [testFile.stringByDeletingPathExtension stringByReplacingOccurrencesOfString:@"-" withString:@"_"];
- NSString *selectorName = [NSString stringWithFormat:@"testPareser__%@", testName];
- SEL selector = NSSelectorFromString(selectorName);
- class_addMethod(self, selector, implementation, types);
+ testName = [NSString stringWithFormat:@"testPareser__%@", testName];
- NSMethodSignature *signature = [self instanceMethodSignatureForSelector:selector];
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
- invocation.selector = selector;
+ NSInvocation *invocation = [HTMLKitTestUtil addTestToClass:self withName:testName block:^ (HTMLKitTreeConstructionTests *instance){
+ [instance runTests];
+ }];
XCTestCase *testCase = [[self alloc] initWithInvocation:invocation tests:tests];
[suite addTest:testCase];
@@ -80,16 +72,11 @@
return self;
}
-- (NSString *)description
-{
- return self.name;
-}
-
#pragma mark - Setup
- (void)setUp
{
- _observer = [[HTMLKitTestObserver alloc] initWithName:self.testName];
+ _observer = [[HTMLKitTestObserver alloc] initWithName:self.name];
[[XCTestObservationCenter sharedTestObservationCenter] addTestObserver:_observer];
[super setUp];