[ZPT] CVS: Packages/TAL - test_htmlparser.py:1.2
fred@digicool.com
fred@digicool.com
Mon, 19 Mar 2001 22:25:26 -0500 (EST)
Update of /cvs-repository/Packages/TAL/test
In directory korak:/tmp/cvs-serv4597
Modified Files:
test_htmlparser.py
Log Message:
Add tests for some boundary conditions, including buffering artefacts.
._run_check(): Add support for passing the data in as a list of strings,
to support simulating buffer boundaries.
--- Updated File test_htmlparser.py in package Packages/TAL --
--- test_htmlparser.py 2001/03/19 18:04:52 1.1
+++ test_htmlparser.py 2001/03/20 03:25:26 1.2
@@ -1,3 +1,4 @@
+#! /usr/bin/env python1.5
"""Test suite for nsgmllib.py."""
import sys
@@ -58,7 +59,11 @@
class HTMLParserTestCase(unittest.TestCase):
def _run_check(self, source, events):
parser = EventCollector()
- parser.feed(source)
+ if isinstance(source, type([])):
+ for s in source:
+ parser.feed(s)
+ else:
+ parser.feed(source)
parser.close()
assert parser.get_events() == events, parser.get_events()
@@ -126,6 +131,36 @@
("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")]),
])
+ def check_starttag_end_boundary(self):
+ self._run_check("""<a b='<'>""", [("starttag", "a", [("b", "<")])])
+ self._run_check("""<a b='>'>""", [("starttag", "a", [("b", ">")])])
+
+ def check_buffer_artefacts(self):
+ output = [("starttag", "a", [("b", "<")])]
+ self._run_check(["<a b='<'>"], output)
+ self._run_check(["<a ", "b='<'>"], output)
+ self._run_check(["<a b", "='<'>"], output)
+ self._run_check(["<a b=", "'<'>"], output)
+ self._run_check(["<a b='<", "'>"], output)
+ self._run_check(["<a b='<'", ">"], output)
+
+ output = [("starttag", "a", [("b", ">")])]
+ self._run_check(["<a b='>'>"], output)
+ self._run_check(["<a ", "b='>'>"], output)
+ self._run_check(["<a b", "='>'>"], output)
+ self._run_check(["<a b=", "'>'>"], output)
+ self._run_check(["<a b='>", "'>"], output)
+ self._run_check(["<a b='>'", ">"], output)
+
+ def check_starttag_junk_chars(self):
+ self._parse_error("<a $>")
+
+ def _parse_error(self, source):
+ def parse(source=source):
+ parser = HTMLParser.HTMLParser()
+ parser.feed(source)
+ parser.close()
+ self.assertRaises(HTMLParser.HTMLParseError, parse)
# Support for the Zope regression test framework: