Commit b173d902 authored by Guido van Rossum's avatar Guido van Rossum

Add tests for improperly closed start and end tag (< instead of >).

Add test for get_starttag_text().
parent 5b1a07ab
...@@ -60,10 +60,16 @@ class EventCollector(HTMLParser.HTMLParser): ...@@ -60,10 +60,16 @@ class EventCollector(HTMLParser.HTMLParser):
self.append(("pi", data)) self.append(("pi", data))
class EventCollectorExtra(EventCollector):
def handle_starttag(self, tag, attrs):
EventCollector.handle_starttag(self, tag, attrs)
self.append(("starttag_text", self.get_starttag_text()))
class HTMLParserTestCase(unittest.TestCase): class HTMLParserTestCase(unittest.TestCase):
def _run_check(self, source, events): def _run_check(self, source, events, collector=EventCollector):
parser = EventCollector() parser = collector()
if isinstance(source, type([])): if isinstance(source, type([])):
for s in source: for s in source:
parser.feed(s) parser.feed(s)
...@@ -72,6 +78,9 @@ class HTMLParserTestCase(unittest.TestCase): ...@@ -72,6 +78,9 @@ class HTMLParserTestCase(unittest.TestCase):
parser.close() parser.close()
self.assert_(parser.get_events() == events, parser.get_events()) self.assert_(parser.get_events() == events, parser.get_events())
def _run_check_extra(self, source, events):
self._run_check(source, events, EventCollectorExtra)
def _parse_error(self, source): def _parse_error(self, source):
def parse(source=source): def parse(source=source):
parser = HTMLParser.HTMLParser() parser = HTMLParser.HTMLParser()
...@@ -171,7 +180,8 @@ text ...@@ -171,7 +180,8 @@ text
self._parse_error("</") self._parse_error("</")
self._parse_error("</a") self._parse_error("</a")
self._parse_error("</a") self._parse_error("</a")
## self._parse_error("</a<a>") self._parse_error("<a<a>")
self._parse_error("</a<a>")
self._parse_error("<$") self._parse_error("<$")
self._parse_error("<$>") self._parse_error("<$>")
self._parse_error("<!") self._parse_error("<!")
...@@ -199,6 +209,12 @@ text ...@@ -199,6 +209,12 @@ text
("endtag", "p"), ("endtag", "p"),
]) ])
def check_get_starttag_text(self):
s = """<foo:bar \n one="1"\ttwo=2 >"""
self._run_check_extra(s, [
("starttag", "foo:bar", [("one", "1"), ("two", "2")]),
("starttag_text", s)])
# Support for the Zope regression test framework: # Support for the Zope regression test framework:
def test_suite(): def test_suite():
......
...@@ -60,10 +60,16 @@ class EventCollector(HTMLParser.HTMLParser): ...@@ -60,10 +60,16 @@ class EventCollector(HTMLParser.HTMLParser):
self.append(("pi", data)) self.append(("pi", data))
class EventCollectorExtra(EventCollector):
def handle_starttag(self, tag, attrs):
EventCollector.handle_starttag(self, tag, attrs)
self.append(("starttag_text", self.get_starttag_text()))
class HTMLParserTestCase(unittest.TestCase): class HTMLParserTestCase(unittest.TestCase):
def _run_check(self, source, events): def _run_check(self, source, events, collector=EventCollector):
parser = EventCollector() parser = collector()
if isinstance(source, type([])): if isinstance(source, type([])):
for s in source: for s in source:
parser.feed(s) parser.feed(s)
...@@ -72,6 +78,9 @@ class HTMLParserTestCase(unittest.TestCase): ...@@ -72,6 +78,9 @@ class HTMLParserTestCase(unittest.TestCase):
parser.close() parser.close()
self.assert_(parser.get_events() == events, parser.get_events()) self.assert_(parser.get_events() == events, parser.get_events())
def _run_check_extra(self, source, events):
self._run_check(source, events, EventCollectorExtra)
def _parse_error(self, source): def _parse_error(self, source):
def parse(source=source): def parse(source=source):
parser = HTMLParser.HTMLParser() parser = HTMLParser.HTMLParser()
...@@ -171,7 +180,8 @@ text ...@@ -171,7 +180,8 @@ text
self._parse_error("</") self._parse_error("</")
self._parse_error("</a") self._parse_error("</a")
self._parse_error("</a") self._parse_error("</a")
## self._parse_error("</a<a>") self._parse_error("<a<a>")
self._parse_error("</a<a>")
self._parse_error("<$") self._parse_error("<$")
self._parse_error("<$>") self._parse_error("<$>")
self._parse_error("<!") self._parse_error("<!")
...@@ -199,6 +209,12 @@ text ...@@ -199,6 +209,12 @@ text
("endtag", "p"), ("endtag", "p"),
]) ])
def check_get_starttag_text(self):
s = """<foo:bar \n one="1"\ttwo=2 >"""
self._run_check_extra(s, [
("starttag", "foo:bar", [("one", "1"), ("two", "2")]),
("starttag_text", s)])
# Support for the Zope regression test framework: # Support for the Zope regression test framework:
def test_suite(): def test_suite():
......
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