a102f5cd7d
Building and testing the project via Xcode copies the resources into the testing bundle, which is not the case for SwiftPM. Hence the helper method, that tries loading the resource from the bundle first. If it is nil then the resource is loaded from the test module path directly.
61 lines
1.8 KiB
Objective-C
61 lines
1.8 KiB
Objective-C
//
|
|
// CSSSelectorTest.m
|
|
// HTMLKit
|
|
//
|
|
// Created by Iska on 22/11/15.
|
|
// Copyright © 2015 BrainCookie. All rights reserved.
|
|
//
|
|
|
|
#import "CSSSelectorTest.h"
|
|
#import "HTMLParser.h"
|
|
#import "HTMLDocument.h"
|
|
#import "HTMLElement.h"
|
|
#import "CSSSelectors.h"
|
|
#import "HTMLKitTestUtil.h"
|
|
|
|
static NSString * const CSSTests = @"css-tests";
|
|
|
|
@implementation CSSSelectorTest
|
|
|
|
+ (NSArray *)loadCSSSelectorTests
|
|
{
|
|
NSString *path = [HTMLKitTestUtil pathForFixture:CSSTests ofType:nil inDirectory:nil];
|
|
|
|
NSMutableArray *tests = [NSMutableArray array];
|
|
NSArray *testFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
|
|
|
|
for (NSString *testFile in testFiles) {
|
|
if (![testFile.pathExtension isEqualToString:@"html"]) {
|
|
continue;
|
|
}
|
|
|
|
NSString *testFilePath = [path stringByAppendingPathComponent:testFile];
|
|
CSSSelectorTest *test = [CSSSelectorTest testWithFileAtPath:testFilePath];
|
|
[tests addObject:test];
|
|
}
|
|
|
|
return tests;
|
|
}
|
|
|
|
+ (instancetype)testWithFileAtPath:(NSString *)filePath
|
|
{
|
|
NSString *testName = filePath.lastPathComponent.stringByDeletingPathExtension;
|
|
|
|
NSString *html = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
|
|
|
|
HTMLDocument *document = [HTMLDocument documentWithString:html];
|
|
|
|
HTMLElement *domElement = [document firstElementMatchingSelector:idSelector(@"testDOM")];
|
|
HTMLElement *scriptElement = [document firstElementMatchingSelector:idSelector(@"selectors")];
|
|
NSData *data = [scriptElement.textContent dataUsingEncoding:NSUTF8StringEncoding];
|
|
NSArray *selectors = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
|
|
|
|
CSSSelectorTest *instance = [CSSSelectorTest new];
|
|
instance.testName = testName;
|
|
instance.selectors = selectors;
|
|
instance.testDOM = domElement;
|
|
return instance;
|
|
}
|
|
|
|
@end
|