Add support for inserting a Document Fragment

Previous implementation would just insert the fragment as a child node, whereas it should insert its
child nodes.
This commit is contained in:
iska
2015-05-02 20:47:40 +02:00
parent 40baea8ece
commit bf061d6367
2 changed files with 66 additions and 25 deletions
@@ -8,6 +8,9 @@
#import <XCTest/XCTest.h>
#import "HTMLNodes.h"
#import "NSString+HTMLKit.h"
extern uint64_t dispatch_benchmark(size_t count, void (^block)(void));
@interface HTMLKitMutationAlgorithmsTests : XCTestCase
@@ -15,6 +18,30 @@
@implementation HTMLKitMutationAlgorithmsTests
- (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)testValidParentNodeWhenAppending
{
HTMLElement *element = [[HTMLElement alloc] initWithTagName:@"div"];