@@ -76,6 +76,51 @@ def test_textBeforeAndAfterRoot(self):
7676 assert strippedHTML .startswith ('Hello' ) , 'Expected text before root tag to be retained, got "%s"' % (strippedHTML ,)
7777 assert strippedHTML .endswith ('World' ) , 'Expected text after root tag to be retained, got "%s"' % (strippedHTML ,)
7878
79+ def test_commentRetained (self ):
80+ html = """<html>
81+ <!-- CommentX -->
82+ <body><span>Hello</span></body></html>"""
83+
84+ parser = AdvancedHTMLParser ()
85+ parser .parseStr (html )
86+
87+ retHTML = parser .getHTML ()
88+
89+ assert 'CommentX' in retHTML , 'Expected to find comment, "CommentX" in returned HTML: "%s"' % (retHTML ,)
90+
91+ def test_commentRetainedPriorRoot (self ):
92+ html = """<!-- CommentX --><html>
93+ <body><span>Hello</span></body></html>"""
94+
95+ parser = AdvancedHTMLParser ()
96+ parser .parseStr (html )
97+
98+ retHTML = parser .getHTML ()
99+
100+ assert 'CommentX' in retHTML , 'Expected to find comment, "CommentX" in returned HTML: "%s"' % (retHTML ,)
101+
102+ def test_commentRetainedAfterRoot (self ):
103+ html = """<html>
104+ <body><span>Hello</span></body></html><!-- CommentX -->"""
105+
106+ parser = AdvancedHTMLParser ()
107+ parser .parseStr (html )
108+
109+ retHTML = parser .getHTML ()
110+
111+ assert 'CommentX' in retHTML , 'Expected to find comment, "CommentX" in returned HTML: "%s"' % (retHTML ,)
112+
113+ def test_commentRetainedBeforeAndAfterRoot (self ):
114+ html = """<!-- CommentX --><html>
115+ <body><span>Hello</span></body></html><!-- CommentY -->"""
116+
117+ parser = AdvancedHTMLParser ()
118+ parser .parseStr (html )
119+
120+ retHTML = parser .getHTML ()
121+
122+ assert 'CommentX' in retHTML , 'Expected to find comment, "CommentX" in returned HTML: "%s"' % (retHTML ,)
123+ assert 'CommentY' in retHTML , 'Expected to find comment, "CommentY" in returned HTML: "%s"' % (retHTML ,)
79124
80125
81126
0 commit comments