// // HTMLKitTests.m // HTMLKitTests // // Created by Iska on 15/09/14. // Copyright (c) 2014 BrainCookie. All rights reserved. // #import #import "HTMLTokenizer.h" @interface HTMLKitTests : XCTestCase @end @implementation HTMLKitTests - (void)setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class. } - (void)tearDown { // Put teardown code here. This method is called after the invocation of each test method in the class. [super tearDown]; } - (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]; } NSLog(@"%@", string); } @end