Add Node methods to prepend nodes
This commit is contained in:
@@ -44,6 +44,73 @@
|
||||
XCTAssertNil(node.lastChildNode);
|
||||
}
|
||||
|
||||
- (void)testAppendNode
|
||||
{
|
||||
HTMLElement *element = [[HTMLElement alloc] initWithTagName:@"div"];
|
||||
HTMLComment *comment = [HTMLComment new];
|
||||
[element appendNode:comment];
|
||||
|
||||
XCTAssertEqual(element.childNodesCount, 1);
|
||||
XCTAssertEqual(element.firstChiledNode, comment);
|
||||
|
||||
HTMLElement *firstElement = [HTMLElement new];
|
||||
HTMLElement *secondElement = [HTMLElement new];
|
||||
NSArray *nodes = @[firstElement, secondElement];
|
||||
|
||||
[element appendNodes:nodes];
|
||||
|
||||
XCTAssertEqual(element.childNodesCount, 3);
|
||||
XCTAssertEqual(element.firstChiledNode, comment);
|
||||
XCTAssertEqual(element.lastChildNode, secondElement);
|
||||
}
|
||||
|
||||
- (void)testPrependNode
|
||||
{
|
||||
HTMLElement *element = [[HTMLElement alloc] initWithTagName:@"div"];
|
||||
HTMLText *text = [HTMLText new];
|
||||
[element appendNode:text];
|
||||
|
||||
HTMLComment *comment = [HTMLComment new];
|
||||
[element prependNode:comment];
|
||||
|
||||
XCTAssertEqual(element.childNodesCount, 2);
|
||||
XCTAssertEqual(element.firstChiledNode, comment);
|
||||
|
||||
HTMLElement *firstElement = [HTMLElement new];
|
||||
HTMLElement *secondElement = [HTMLElement new];
|
||||
NSArray *nodes = @[firstElement, secondElement];
|
||||
|
||||
[element prependNodes:nodes];
|
||||
|
||||
XCTAssertEqual(element.childNodesCount, 4);
|
||||
XCTAssertEqual(element.firstChiledNode, firstElement);
|
||||
XCTAssertEqual(element.lastChildNode, text);
|
||||
}
|
||||
|
||||
- (void)testAppendDocumentFragment
|
||||
{
|
||||
HTMLElement *element = [[HTMLElement alloc] initWithTagName:@"div"];
|
||||
HTMLComment *comment = [HTMLComment new];
|
||||
[element appendNode:comment];
|
||||
|
||||
HTMLDocumentFragment *fragment = [HTMLDocumentFragment new];
|
||||
HTMLElement *firstChild = [HTMLElement new];
|
||||
HTMLElement *secondChild = [HTMLElement new];
|
||||
[fragment appendNode:firstChild];
|
||||
[fragment appendNode:secondChild];
|
||||
|
||||
[element appendNode:fragment];
|
||||
XCTAssertEqual(element.childNodesCount, 3);
|
||||
XCTAssertEqual(fragment.childNodesCount, 0);
|
||||
|
||||
XCTAssertEqualObjects(firstChild.parentNode, element);
|
||||
XCTAssertEqualObjects(secondChild.parentNode, element);
|
||||
XCTAssertEqualObjects(element.firstChiledNode, comment);
|
||||
XCTAssertEqualObjects(element.firstChiledNode.nextSibling, firstChild);
|
||||
XCTAssertEqualObjects(element.lastChildNode.previousSibling, firstChild);
|
||||
XCTAssertEqualObjects(element.lastChildNode, secondChild);
|
||||
}
|
||||
|
||||
- (void)testParentNode
|
||||
{
|
||||
HTMLNode *node = [[HTMLNode alloc] initWithName:@"name" type:HTMLNodeElement];
|
||||
|
||||
Reference in New Issue
Block a user