From 3333274cfb9d214f39a315cf93d7b35fde57455e Mon Sep 17 00:00:00 2001 From: Iskandar Abudiab Date: Thu, 29 Apr 2021 18:14:15 +0200 Subject: [PATCH] Use HTMLElement's designated initialiser in tests Fixes #43 --- HTMLKit.xcodeproj/project.pbxproj | 4 +- Tests/HTMLKitTests/HTMLKitTestObserver.m | 2 +- .../HTMLMutationAlgorithmsTests.m | 48 +++++++++---------- Tests/HTMLKitTests/HTMLNodesTests.m | 16 +++---- Tests/HTMLKitTests/HTMLRangeTests.m | 2 +- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/HTMLKit.xcodeproj/project.pbxproj b/HTMLKit.xcodeproj/project.pbxproj index da3b3b6..b0bf820 100644 --- a/HTMLKit.xcodeproj/project.pbxproj +++ b/HTMLKit.xcodeproj/project.pbxproj @@ -2217,7 +2217,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.15; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; }; @@ -2265,7 +2265,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.15; SDKROOT = macosx; }; name = Release; diff --git a/Tests/HTMLKitTests/HTMLKitTestObserver.m b/Tests/HTMLKitTests/HTMLKitTestObserver.m index e5bb78c..5ed12f9 100644 --- a/Tests/HTMLKitTests/HTMLKitTestObserver.m +++ b/Tests/HTMLKitTests/HTMLKitTestObserver.m @@ -51,7 +51,7 @@ [_cases addObject:_currentCase]; } -- (void)testCase:(XCTestCase *)testCase didFailWithDescription:(NSString *)description inFile:(NSString *)filePath atLine:(NSUInteger)lineNumber +- (void)testCase:(XCTestCase *)testCase didRecordIssue:(XCTIssue *)issue { _currentCase[@"status"] = @"Failed"; } diff --git a/Tests/HTMLKitTests/HTMLMutationAlgorithmsTests.m b/Tests/HTMLKitTests/HTMLMutationAlgorithmsTests.m index 127e7f4..3521435 100644 --- a/Tests/HTMLKitTests/HTMLMutationAlgorithmsTests.m +++ b/Tests/HTMLKitTests/HTMLMutationAlgorithmsTests.m @@ -28,7 +28,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); parent = [HTMLDocumentFragment new]; XCTAssertNoThrow([parent appendNode:element]); - parent = [HTMLElement new]; + parent = [[HTMLElement alloc] initWithTagName:@"div"]; XCTAssertNoThrow([parent appendNode:element]); parent = [HTMLTemplate new]; @@ -54,7 +54,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); parent = [HTMLDocumentFragment new]; XCTAssertNoThrow([parent insertNode:element beforeChildNode:nil]); - parent = [HTMLElement new]; + parent = [[HTMLElement alloc] initWithTagName:@"div"]; XCTAssertNoThrow([parent insertNode:element beforeChildNode:nil]); parent = [HTMLTemplate new]; @@ -115,9 +115,9 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); XCTAssertNoThrow([document appendNode:[HTMLDocumentFragment new]]); XCTAssertNoThrow([document appendNode:[HTMLDocumentType new]]); - XCTAssertNoThrow([document appendNode:[HTMLElement new]]); + XCTAssertNoThrow([document appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]); - HTMLElement *element = [HTMLElement new]; + HTMLElement *element = [[HTMLElement alloc] initWithTagName:@"div"]; XCTAssertNoThrow([element appendNode:[HTMLTemplate new]]); XCTAssertNoThrow([element appendNode:[HTMLComment new]]); @@ -132,7 +132,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); XCTAssertThrows([[HTMLDocumentFragment new] appendNode:doctype]); XCTAssertThrows([[HTMLDocumentType new] appendNode:doctype]); - XCTAssertThrows([[HTMLElement new] appendNode:doctype]); + XCTAssertThrows([[[HTMLElement alloc] initWithTagName:@"div"] appendNode:doctype]); XCTAssertThrows([[HTMLTemplate new] appendNode:doctype]); XCTAssertThrows([[HTMLComment new] appendNode:doctype]); XCTAssertThrows([[HTMLText new] appendNode:doctype]); @@ -148,7 +148,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); XCTAssertThrows([[HTMLText new] appendNode:text]); XCTAssertNoThrow([[HTMLDocumentFragment new] appendNode:text]); - XCTAssertNoThrow([[HTMLElement new] appendNode:text]); + XCTAssertNoThrow([[[HTMLElement alloc] initWithTagName:@"div"] appendNode:text]); XCTAssertNoThrow([[HTMLTemplate new] appendNode:text]); } @@ -172,8 +172,8 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); * Fragment has more than one Element child */ reset(); - [fragment appendNode:[HTMLElement new]]; - [fragment appendNode:[HTMLElement new]]; + [fragment appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; + [fragment appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; XCTAssertThrows([document appendNode:fragment]); @@ -182,8 +182,8 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); * Document has an Element child */ reset(); - [fragment appendNode:[HTMLElement new]]; - [document appendNode:[HTMLElement new]]; + [fragment appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; + [document appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; XCTAssertThrows([document appendNode:fragment]); /** @@ -192,7 +192,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); */ reset(); HTMLDocumentType *doctype = [HTMLDocumentType new]; - [fragment appendNode:[HTMLElement new]]; + [fragment appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; [document appendNode:doctype]; XCTAssertThrows([document insertNode:fragment beforeChildNode:doctype]); @@ -202,7 +202,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); */ reset(); HTMLComment *doctypePreviousSibling = [HTMLComment new]; - [fragment appendNode:[HTMLElement new]]; + [fragment appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; [document appendNode:doctypePreviousSibling]; [document appendNode:doctype]; XCTAssertThrows([document insertNode:fragment beforeChildNode:doctypePreviousSibling]); @@ -211,7 +211,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); - (void)testValidElementInsertionIntoDocument { HTMLDocument *document = [HTMLDocument new]; - HTMLElement *element = [HTMLElement new]; + HTMLElement *element = [[HTMLElement alloc] initWithTagName:@"div"]; void (^ reset)(void) = ^ { [element removeAllChildNodes]; @@ -221,7 +221,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); /** * Document has an Element child */ - [document appendNode:[HTMLElement new]]; + [document appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; XCTAssertThrows([document appendNode:element]); /** @@ -262,7 +262,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); */ reset(); HTMLComment *secondChild = [HTMLComment new]; - [document appendNode:[HTMLElement new]]; + [document appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; [document appendNode:secondChild]; XCTAssertThrows([document insertNode:doctype beforeChildNode:secondChild]); @@ -270,7 +270,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); * Document has an Element child */ reset(); - [document appendNode:[HTMLElement new]]; + [document appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; XCTAssertThrows([document appendNode:doctype]); } @@ -296,8 +296,8 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); * Replacement Fragment has more than one Element child */ reset(); - [replacement appendNode:[HTMLElement new]]; - [replacement appendNode:[HTMLElement new]]; + [replacement appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; + [replacement appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; XCTAssertThrows([document replaceChildNode:child withNode:replacement]); /** @@ -305,8 +305,8 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); * Document has an Element child that is not the Replacement */ reset(); - [replacement appendNode:[HTMLElement new]]; - [document appendNode:[HTMLElement new]]; + [replacement appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; + [document appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; XCTAssertThrows([document replaceChildNode:child withNode:replacement]); /** @@ -315,7 +315,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); */ reset(); HTMLDocumentType *doctype = [HTMLDocumentType new]; - [replacement appendNode:[HTMLElement new]]; + [replacement appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; [document appendNode:doctype]; XCTAssertThrows([document replaceChildNode:child withNode:replacement]); } @@ -324,7 +324,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); { HTMLDocument *document = [HTMLDocument new]; HTMLComment *child = [HTMLComment new]; - HTMLElement *replacement = [HTMLElement new]; + HTMLElement *replacement = [[HTMLElement alloc] initWithTagName:@"div"]; void (^ reset)(void) = ^ { [replacement removeAllChildNodes]; @@ -335,7 +335,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); /** * Docment has an Element child that is not replacement */ - [document appendNode:[HTMLElement new]]; + [document appendNode:[[HTMLElement alloc] initWithTagName:@"div"]]; XCTAssertThrows([document replaceChildNode:child withNode:replacement]); /** @@ -369,7 +369,7 @@ extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); * An Element is preceding the child node */ reset(); - [document insertNode:[HTMLElement new] beforeChildNode:child]; + [document insertNode:[[HTMLElement alloc] initWithTagName:@"div"] beforeChildNode:child]; XCTAssertThrows([document replaceChildNode:child withNode:replacement]); } diff --git a/Tests/HTMLKitTests/HTMLNodesTests.m b/Tests/HTMLKitTests/HTMLNodesTests.m index 1c2b5f7..7a88ec7 100644 --- a/Tests/HTMLKitTests/HTMLNodesTests.m +++ b/Tests/HTMLKitTests/HTMLNodesTests.m @@ -53,8 +53,8 @@ XCTAssertEqual(element.childNodesCount, 1); XCTAssertEqual(element.firstChild, comment); - HTMLElement *firstElement = [HTMLElement new]; - HTMLElement *secondElement = [HTMLElement new]; + HTMLElement *firstElement = [[HTMLElement alloc] initWithTagName:@"div"]; + HTMLElement *secondElement = [[HTMLElement alloc] initWithTagName:@"div"]; NSArray *nodes = @[firstElement, secondElement]; [element appendNodes:nodes]; @@ -76,8 +76,8 @@ XCTAssertEqual(element.childNodesCount, 2); XCTAssertEqual(element.firstChild, comment); - HTMLElement *firstElement = [HTMLElement new]; - HTMLElement *secondElement = [HTMLElement new]; + HTMLElement *firstElement = [[HTMLElement alloc] initWithTagName:@"div"]; + HTMLElement *secondElement = [[HTMLElement alloc] initWithTagName:@"div"]; NSArray *nodes = @[firstElement, secondElement]; [element prependNodes:nodes]; @@ -94,8 +94,8 @@ [element appendNode:comment]; HTMLDocumentFragment *fragment = [HTMLDocumentFragment new]; - HTMLElement *firstChild = [HTMLElement new]; - HTMLElement *secondChild = [HTMLElement new]; + HTMLElement *firstChild = [[HTMLElement alloc] initWithTagName:@"div"]; + HTMLElement *secondChild = [[HTMLElement alloc] initWithTagName:@"div"]; [fragment appendNode:firstChild]; [fragment appendNode:secondChild]; @@ -494,7 +494,7 @@ XCTAssertTrue([paragraph compareDocumentPositionWithNode:paragraph] == HTMLDocumentPositionEquivalent); - HTMLElement *element = [HTMLElement new]; + HTMLElement *element = [[HTMLElement alloc] initWithTagName:@"div"]; XCTAssertTrue([paragraph compareDocumentPositionWithNode:element] == HTMLDocumentPositionPreceding); XCTAssertTrue([paragraph compareDocumentPositionWithNode:image] == HTMLDocumentPositionPreceding); @@ -556,7 +556,7 @@ #pragma mark - Bug Fixes - (void)testBugFix_Issue_20 { - HTMLElement *element = [HTMLElement new]; + HTMLElement *element = [[HTMLElement alloc] initWithTagName:@"div"]; element.elementId = @"originalId"; HTMLElement *clone = [element cloneNodeDeep:YES]; diff --git a/Tests/HTMLKitTests/HTMLRangeTests.m b/Tests/HTMLKitTests/HTMLRangeTests.m index 3a62ae5..04c7585 100644 --- a/Tests/HTMLKitTests/HTMLRangeTests.m +++ b/Tests/HTMLKitTests/HTMLRangeTests.m @@ -103,7 +103,7 @@ { HTMLRange *range = [[HTMLRange alloc] initWithDocument:_document]; - XCTAssertThrows([range setStartNode:[HTMLElement new] startOffset:0], @"Cannot set boundary to a node outside of the range's document"); + XCTAssertThrows([range setStartNode:[[HTMLElement alloc] initWithTagName:@"div"] startOffset:0], @"Cannot set boundary to a node outside of the range's document"); XCTAssertThrows([range setStartNode:[HTMLDocumentType new] startOffset:0], @"DOCTYPE as range boundary is invalid"); XCTAssertThrows([range setStartNode:_firstText startOffset:_firstText.length + 1], @"Offset is outside the boundary node");