From 8088d239df22b71e7ad328494e9cabe4eebe4406 Mon Sep 17 00:00:00 2001 From: iska Date: Sun, 26 Oct 2014 01:58:25 +0200 Subject: [PATCH] Add common test case class --- HTMLKit.xcodeproj/project.pbxproj | 2 + HTMLKitTests/HTMLKitTests.h | 16 +++++++ HTMLKitTests/HTMLKitTests.m | 69 +++++++------------------------ 3 files changed, 34 insertions(+), 53 deletions(-) create mode 100644 HTMLKitTests/HTMLKitTests.h diff --git a/HTMLKit.xcodeproj/project.pbxproj b/HTMLKit.xcodeproj/project.pbxproj index 1242840..4c1c9ac 100644 --- a/HTMLKit.xcodeproj/project.pbxproj +++ b/HTMLKit.xcodeproj/project.pbxproj @@ -106,6 +106,7 @@ 624493AB19CD0CBE00BCDDF4 /* HTMLToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTMLToken.m; sourceTree = ""; }; 624AC8FE19FBF4F700BD3C4A /* HTMLTokens.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTMLTokens.h; sourceTree = ""; }; 624AC90019FBF9ED00BD3C4A /* HTMLTokenizerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTMLTokenizerTests.m; sourceTree = ""; }; + 624AC90319FBFD1A00BD3C4A /* HTMLKitTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTMLKitTests.h; sourceTree = ""; }; 624AC90419FBFE8A00BD3C4A /* html5lib-tests */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "html5lib-tests"; sourceTree = ""; }; 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 */, ); diff --git a/HTMLKitTests/HTMLKitTests.h b/HTMLKitTests/HTMLKitTests.h new file mode 100644 index 0000000..11c586b --- /dev/null +++ b/HTMLKitTests/HTMLKitTests.h @@ -0,0 +1,16 @@ +// +// HTMLKitTests.h +// HTMLKit +// +// Created by Iska on 25/10/14. +// Copyright (c) 2014 BrainCookie. All rights reserved. +// + +#import +#import "HTML5LibTest.h" + +@interface HTMLKitTests : XCTestCase + +- (NSArray *)loadTests:(NSString *)testsFile forComponent:(NSString *)component; + +@end \ No newline at end of file diff --git a/HTMLKitTests/HTMLKitTests.m b/HTMLKitTests/HTMLKitTests.m index 5b601f8..c4326e8 100644 --- a/HTMLKitTests/HTMLKitTests.m +++ b/HTMLKitTests/HTMLKitTests.m @@ -6,67 +6,30 @@ // Copyright (c) 2014 BrainCookie. All rights reserved. // -#import -#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 = @"\n\n\n\n \n\n The HTML5 Herald\n \n \n\n \n\n \n\n\n\n \n\n"; - - 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