Commit 0e90db9e authored by Guido van Rossum's avatar Guido van Rossum

Add test for handle_comment().

Remove confusing comment about entity replacement.
parent 2c3d7e65
...@@ -44,6 +44,9 @@ class EventCollector(HTMLParser.HTMLParser): ...@@ -44,6 +44,9 @@ class EventCollector(HTMLParser.HTMLParser):
# all other markup # all other markup
def handle_comment(self, data):
self.append(("comment", data))
def handle_charref(self, data): def handle_charref(self, data):
self.append(("charref", data)) self.append(("charref", data))
...@@ -97,8 +100,12 @@ class HTMLParserTestCase(unittest.TestCase): ...@@ -97,8 +100,12 @@ class HTMLParserTestCase(unittest.TestCase):
self._run_check(""" self._run_check("""
<!DOCTYPE html PUBLIC 'foo'> <!DOCTYPE html PUBLIC 'foo'>
<html>&entity;&#32; <html>&entity;&#32;
<!--comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1b-->
<img src='bar' ismap>sample <img src='bar' ismap>sample
text text
<!--comment2a-- --comment2b-->
</html> </html>
""", [ """, [
("data", "\n"), ("data", "\n"),
...@@ -108,8 +115,12 @@ text ...@@ -108,8 +115,12 @@ text
("entityref", "entity"), ("entityref", "entity"),
("charref", "32"), ("charref", "32"),
("data", "\n"), ("data", "\n"),
("comment", "comment1a\n-></foo><bar>&lt;<?pi?></foo<bar\ncomment1b"),
("data", "\n"),
("starttag", "img", [("src", "bar"), ("ismap", "ismap")]), ("starttag", "img", [("src", "bar"), ("ismap", "ismap")]),
("data", "sample\ntext\n"), ("data", "sample\ntext\n"),
("comment", "comment2a-- --comment2b"),
("data", "\n"),
("endtag", "html"), ("endtag", "html"),
("data", "\n"), ("data", "\n"),
]) ])
...@@ -142,7 +153,6 @@ text ...@@ -142,7 +153,6 @@ text
]) ])
def check_attr_entity_replacement(self): def check_attr_entity_replacement(self):
# we expect entities *not* to be replaced by HTLMParser!
self._run_check("""<a b='&amp;&gt;&lt;&quot;&apos;'>""", [ self._run_check("""<a b='&amp;&gt;&lt;&quot;&apos;'>""", [
("starttag", "a", [("b", "&><\"'")]), ("starttag", "a", [("b", "&><\"'")]),
]) ])
......
...@@ -44,6 +44,9 @@ class EventCollector(HTMLParser.HTMLParser): ...@@ -44,6 +44,9 @@ class EventCollector(HTMLParser.HTMLParser):
# all other markup # all other markup
def handle_comment(self, data):
self.append(("comment", data))
def handle_charref(self, data): def handle_charref(self, data):
self.append(("charref", data)) self.append(("charref", data))
...@@ -97,8 +100,12 @@ class HTMLParserTestCase(unittest.TestCase): ...@@ -97,8 +100,12 @@ class HTMLParserTestCase(unittest.TestCase):
self._run_check(""" self._run_check("""
<!DOCTYPE html PUBLIC 'foo'> <!DOCTYPE html PUBLIC 'foo'>
<html>&entity;&#32; <html>&entity;&#32;
<!--comment1a
-></foo><bar>&lt;<?pi?></foo<bar
comment1b-->
<img src='bar' ismap>sample <img src='bar' ismap>sample
text text
<!--comment2a-- --comment2b-->
</html> </html>
""", [ """, [
("data", "\n"), ("data", "\n"),
...@@ -108,8 +115,12 @@ text ...@@ -108,8 +115,12 @@ text
("entityref", "entity"), ("entityref", "entity"),
("charref", "32"), ("charref", "32"),
("data", "\n"), ("data", "\n"),
("comment", "comment1a\n-></foo><bar>&lt;<?pi?></foo<bar\ncomment1b"),
("data", "\n"),
("starttag", "img", [("src", "bar"), ("ismap", "ismap")]), ("starttag", "img", [("src", "bar"), ("ismap", "ismap")]),
("data", "sample\ntext\n"), ("data", "sample\ntext\n"),
("comment", "comment2a-- --comment2b"),
("data", "\n"),
("endtag", "html"), ("endtag", "html"),
("data", "\n"), ("data", "\n"),
]) ])
...@@ -142,7 +153,6 @@ text ...@@ -142,7 +153,6 @@ text
]) ])
def check_attr_entity_replacement(self): def check_attr_entity_replacement(self):
# we expect entities *not* to be replaced by HTLMParser!
self._run_check("""<a b='&amp;&gt;&lt;&quot;&apos;'>""", [ self._run_check("""<a b='&amp;&gt;&lt;&quot;&apos;'>""", [
("starttag", "a", [("b", "&><\"'")]), ("starttag", "a", [("b", "&><\"'")]),
]) ])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment