Add common test case class

This commit is contained in:
iska
2014-10-26 01:59:52 +02:00
parent f96c69c6f7
commit 8088d239df
3 changed files with 34 additions and 53 deletions
+2
View File
@@ -106,6 +106,7 @@
624493AB19CD0CBE00BCDDF4 /* HTMLToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTMLToken.m; sourceTree = "<group>"; };
624AC8FE19FBF4F700BD3C4A /* HTMLTokens.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTMLTokens.h; sourceTree = "<group>"; };
624AC90019FBF9ED00BD3C4A /* HTMLTokenizerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTMLTokenizerTests.m; sourceTree = "<group>"; };
624AC90319FBFD1A00BD3C4A /* HTMLKitTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTMLKitTests.h; sourceTree = "<group>"; };
624AC90419FBFE8A00BD3C4A /* html5lib-tests */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "html5lib-tests"; sourceTree = "<group>"; };
625A14AC19C7829400AD0C32 /* HTMLKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HTMLKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
625A14AF19C7829400AD0C32 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
@@ -266,6 +267,7 @@
62D8345719FB1AC4009205A9 /* HTML5LibTest.h */,
62D8345819FB1AC4009205A9 /* HTML5LibTest.m */,
624AC90019FBF9ED00BD3C4A /* HTMLTokenizerTests.m */,
624AC90319FBFD1A00BD3C4A /* HTMLKitTests.h */,
625A14D019C7829400AD0C32 /* HTMLKitTests.m */,
625A14CB19C7829400AD0C32 /* Supporting Files */,
);
+16
View File
@@ -0,0 +1,16 @@
//
// HTMLKitTests.h
// HTMLKit
//
// Created by Iska on 25/10/14.
// Copyright (c) 2014 BrainCookie. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "HTML5LibTest.h"
@interface HTMLKitTests : XCTestCase
- (NSArray *)loadTests:(NSString *)testsFile forComponent:(NSString *)component;
@end
+16 -53
View File
@@ -6,67 +6,30 @@
// Copyright (c) 2014 BrainCookie. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "HTMLTokenizer.h"
#import "HTMLKitTests.h"
@interface HTMLKitTests : XCTestCase
@end
static NSString * const HTML5LibTests = @"html5lib-tests";
@implementation HTMLKitTests
- (void)setUp
- (NSArray *)loadTests:(NSString *)testsFile forComponent:(NSString *)component
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
NSString *path = [[NSBundle bundleForClass:self.class] resourcePath];
path = [path stringByAppendingPathComponent:HTML5LibTests];
path = [path stringByAppendingPathComponent:component];
path = [path stringByAppendingPathComponent:testsFile];
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
NSString *json = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[json dataUsingEncoding:NSUTF8StringEncoding]
options:0
error:nil];
NSArray *jsonTests = [dictionary objectForKey:@"tests"];
- (void)testExample
{
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
}
- (void)testX
{
NSString *s = @"<!doctype html>\n\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n\n <title>The HTML5 Herald</title>\n <meta name=\"description\" content=\"The HTML5 Herald\">\n <meta name=\"author\" content=\"SitePoint\">\n\n <link rel=\"stylesheet\" href=\"css/styles.css?v=1.0\">\n\n <!--[if lt IE 9]>\n <script src=\"http://html5shiv.googlecode.com/svn/trunk/html5.js\"></script>\n <![endif]-->\n</head>\n\n<body>\n <script src=\"js/scripts.js\"></script>\n</body>\n</html>";
HTMLTokenizer *t = [[HTMLTokenizer alloc] initWithString:s];
HTMLToken *token = nil;
do {
token = [t nextToken];
NSLog(@"%@", token);
} while (token !=nil && ![token isEOFToken]);
}
- (void)testY
{
NSString *string = @"\\u003Efoo\\uFEFFbar";
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(\\\\u([0-9a-f]{4}))"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSArray *matches = [regex matchesInString:string options:0 range:NSMakeRange(0, string.length)];
for(NSTextCheckingResult *match in [matches reverseObjectEnumerator]) {
NSRange matchRange = [match rangeAtIndex:1];
NSRange hexRange = [match rangeAtIndex:2];
NSString *hexString = [string substringWithRange:hexRange];
NSScanner *scanner = [NSScanner scannerWithString:hexString];
unsigned int codepint;
[scanner scanHexInt:&codepint];
NSString *replacement = [NSString stringWithFormat:@"%C", (unichar)codepint];
string = [string stringByReplacingCharactersInRange:matchRange withString:replacement];
NSMutableArray *tests = [NSMutableArray array];
for (NSDictionary *test in jsonTests) {
[tests addObject:[[HTML5LibTest alloc] initWithFixture:test]];
}
NSLog(@"%@", string);
return tests;
}
@end