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
+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