//
// HTMLSerializationTests.m
// HTMLKit
//
// Created by Iska on 06.11.17.
// Copyright © 2017 BrainCookie. All rights reserved.
//
#import
#import "HTMLDOM.h"
#import "HTMLKitTestUtil.h"
#define Assert(input, expected) \
do { \
HTMLDocument *document = [HTMLDocument documentWithString:input]; \
XCTAssertEqualObjects(document.body.innerHTML, expected); \
} while(0)
#define AssertH(input, expected) \
do { \
HTMLDocument *document = [HTMLDocument documentWithString:input]; \
XCTAssertEqualObjects(document.head.innerHTML, expected); \
} while(0)
@interface HTMLSerializationTests : XCTestCase
@end
@implementation HTMLSerializationTests
- (void)testSerializer
{
Assert(@"", @"");
Assert(@"Hello!
, World!", @"Hello!
, World!");
Assert(@"Hello, World!
", @"Hello, World!
");
AssertH(@"\">", @"\">");
AssertH(@"", @"");
AssertH(@"", @"");
AssertH(@"", @"");
AssertH(@"", @"");
Assert(@"", @"");
Assert(@"\"'\"
", @"\"'\"
");
Assert(@"&
", @"&
");
Assert(@"&
", @"&
");
Assert(@"<
", @"<
");
Assert(@">
", @">
");
Assert(@">
", @">
");
AssertH(@"", @"");
AssertH(@"", @"");
Assert(@"(x & 1) < 2; y > \"foo\" + 'bar'", @"(x & 1) < 2; y > \"foo\" + 'bar'");
Assert(@"", @"");
Assert(@"(x & 1) < 2; y > \"foo\" + 'bar'", @"(x & 1) < 2; y > \"foo\" + 'bar'");
AssertH(@"(x & 1) < 2; y > \"foo\" + 'bar'", @"(x & 1) < 2; y > \"foo\" + 'bar'");
Assert(@"foo bar
", @"foo bar
");
Assert(@"\nfoo bar
", @"foo bar
");
Assert(@"\n\nfoo bar
", @"\nfoo bar
");
Assert(@"", @"");
Assert(@"", @"");
Assert(@"", @"");
Assert(@"foo bar", @"foo bar");
Assert(@"\nfoo bar", @"foo bar");
Assert(@"\n\nfoo bar", @"\nfoo bar");
Assert(@"hi
", @"hi
");
Assert(@"hi
", @"hi
");
Assert(@"hi
", @"hi
");
Assert(@"hi
", @"hi
");
Assert(@"", @"");
Assert(@"", @"");
Assert(@"", @"");
Assert(@"", @"");
}
#pragma mark - Bug Fixes
- (void)testBugFix_Issue_16
{
NSString *html = @"<test>
";
HTMLDocument *document = [HTMLDocument documentWithString:html];
XCTAssertEqualObjects(document.body.outerHTML, html);
}
- (void)testBugFix_Issue_17
{
NSString *html = @"";
HTMLDocument *document = [HTMLDocument documentWithString:html];
XCTAssertEqualObjects(document.body.outerHTML, @"");
}
- (void)testBugFix_Issue_33
{
NSString *path = [HTMLKitTestUtil pathForFixture:@"bug33" ofType:@"html" inDirectory:@"Fixtures"];
NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
HTMLDocument *document = [HTMLDocument documentWithString:html];
XCTestExpectation *expectation = [self expectationWithDescription:@"HTML serializes despite limited recursion depth"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[document.rootElement outerHTML];
[expectation fulfill];
});
[self waitForExpectationsWithTimeout:500 handler:nil];
}
@end