Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from siuying/HTML
Add HTML parser supports
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
// | |||
// HTMLTests.m | |||
// RaptureXML | |||
// | |||
// Created by Francis Chong on 22/3/13. | |||
// Copyright (c) 2013 Rapture In Venice. All rights reserved. | |||
// | |||
|
|||
#import "RXMLElement.h" | |||
|
|||
@interface HTMLTests : SenTestCase { | |||
NSString *simpleHTML_; | |||
} | |||
@end | |||
|
|||
@implementation HTMLTests | |||
|
|||
- (void)setUp { | |||
simpleHTML_ = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\ | |||
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\ | |||
\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\ | |||
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" >\ | |||
<head>\ | |||
<title>Minimal XHTML 1.1 Document</title>\ | |||
</head>\ | |||
<body>\ | |||
<p>This is a minimal <a href=\"http://www.w3.org/TR/xhtml11\">XHTML 1.1</a> document.</p>\ | |||
</body>\ | |||
</html>"; | |||
} | |||
|
|||
- (void)testBasicXHTML { | |||
RXMLElement *html = [RXMLElement elementFromHTMLString:simpleHTML_ encoding:NSUTF8StringEncoding]; | |||
NSArray *atts = [html attributeNames]; | |||
STAssertEquals(atts.count, 2U, nil); | |||
|
|||
NSArray* children = [html childrenWithRootXPath:@"//html/body/p"]; | |||
STAssertTrue([children count] > 0, nil); | |||
|
|||
RXMLElement* child = [children objectAtIndex:0]; | |||
NSLog(@"content: %@", [child text]); | |||
STAssertEqualObjects([child text], @"This is a minimal XHTML 1.1 document.", nil); | |||
} | |||
|
|||
-(void) testHtmlEntity { | |||
RXMLElement* html = [RXMLElement elementFromHTMLString:@"<p>Don't say "lazy"</p>" encoding:NSUTF8StringEncoding]; | |||
STAssertEqualObjects([html text], @"Don't say \"lazy\"", nil); | |||
} | |||
|
|||
-(void) testFixBrokenHtml { | |||
RXMLElement* html = [RXMLElement elementFromHTMLString:@"<p><b>Test</p> Broken HTML</b>" encoding:NSUTF8StringEncoding]; | |||
STAssertEqualObjects([html text], @"Test Broken HTML", nil); | |||
STAssertEqualObjects([html xml], @"<html><body><p><b>Test</b></p> Broken HTML</body></html>", nil); | |||
} | |||
|
|||
@end |