blob: 29a721cf45140d0f96d1a6b271ca7a332b5a8cc1 [file] [log] [blame]
Fred Drakebd3090d2001-05-18 15:32:59 +00001"""Tests for HTMLParser.py."""
2
Georg Brandlbcdafa42008-05-20 07:58:42 +00003import HTMLParser
Fred Drake029acfb2001-08-20 21:24:19 +00004import pprint
Fred Drakebd3090d2001-05-18 15:32:59 +00005import unittest
Barry Warsaw04f357c2002-07-23 19:04:11 +00006from test import test_support
Fred Drakebd3090d2001-05-18 15:32:59 +00007
8
Georg Brandlbcdafa42008-05-20 07:58:42 +00009class EventCollector(HTMLParser.HTMLParser):
Fred Drakebd3090d2001-05-18 15:32:59 +000010
11 def __init__(self):
12 self.events = []
13 self.append = self.events.append
Georg Brandlbcdafa42008-05-20 07:58:42 +000014 HTMLParser.HTMLParser.__init__(self)
Fred Drakebd3090d2001-05-18 15:32:59 +000015
16 def get_events(self):
17 # Normalize the list of events so that buffer artefacts don't
18 # separate runs of contiguous characters.
19 L = []
20 prevtype = None
21 for event in self.events:
22 type = event[0]
23 if type == prevtype == "data":
24 L[-1] = ("data", L[-1][1] + event[1])
25 else:
26 L.append(event)
27 prevtype = type
28 self.events = L
29 return L
30
31 # structure markup
32
33 def handle_starttag(self, tag, attrs):
34 self.append(("starttag", tag, attrs))
35
36 def handle_startendtag(self, tag, attrs):
37 self.append(("startendtag", tag, attrs))
38
39 def handle_endtag(self, tag):
40 self.append(("endtag", tag))
41
42 # all other markup
43
44 def handle_comment(self, data):
45 self.append(("comment", data))
46
47 def handle_charref(self, data):
48 self.append(("charref", data))
49
50 def handle_data(self, data):
51 self.append(("data", data))
52
53 def handle_decl(self, data):
54 self.append(("decl", data))
55
56 def handle_entityref(self, data):
57 self.append(("entityref", data))
58
59 def handle_pi(self, data):
60 self.append(("pi", data))
61
Fred Drakec20a6982001-09-04 15:13:04 +000062 def unknown_decl(self, decl):
63 self.append(("unknown decl", decl))
64
Fred Drakebd3090d2001-05-18 15:32:59 +000065
66class EventCollectorExtra(EventCollector):
67
68 def handle_starttag(self, tag, attrs):
69 EventCollector.handle_starttag(self, tag, attrs)
70 self.append(("starttag_text", self.get_starttag_text()))
71
72
73class TestCaseBase(unittest.TestCase):
74
Fred Drakec20a6982001-09-04 15:13:04 +000075 def _run_check(self, source, expected_events, collector=EventCollector):
Fred Drakebd3090d2001-05-18 15:32:59 +000076 parser = collector()
Fred Drakebd3090d2001-05-18 15:32:59 +000077 for s in source:
78 parser.feed(s)
Fred Drakebd3090d2001-05-18 15:32:59 +000079 parser.close()
Fred Drake029acfb2001-08-20 21:24:19 +000080 events = parser.get_events()
Fred Drakec20a6982001-09-04 15:13:04 +000081 if events != expected_events:
82 self.fail("received events did not match expected events\n"
83 "Expected:\n" + pprint.pformat(expected_events) +
84 "\nReceived:\n" + pprint.pformat(events))
Fred Drakebd3090d2001-05-18 15:32:59 +000085
86 def _run_check_extra(self, source, events):
87 self._run_check(source, events, EventCollectorExtra)
88
89 def _parse_error(self, source):
90 def parse(source=source):
Georg Brandlbcdafa42008-05-20 07:58:42 +000091 parser = HTMLParser.HTMLParser()
Fred Drakebd3090d2001-05-18 15:32:59 +000092 parser.feed(source)
93 parser.close()
Georg Brandlbcdafa42008-05-20 07:58:42 +000094 self.assertRaises(HTMLParser.HTMLParseError, parse)
Fred Drakebd3090d2001-05-18 15:32:59 +000095
96
97class HTMLParserTestCase(TestCaseBase):
98
Fred Drake84bb9d82001-08-03 19:53:01 +000099 def test_processing_instruction_only(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000100 self._run_check("<?processing instruction>", [
101 ("pi", "processing instruction"),
102 ])
Fred Drakefafd56f2003-04-17 22:19:26 +0000103 self._run_check("<?processing instruction ?>", [
104 ("pi", "processing instruction ?"),
105 ])
Fred Drakebd3090d2001-05-18 15:32:59 +0000106
Fred Drake84bb9d82001-08-03 19:53:01 +0000107 def test_simple_html(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000108 self._run_check("""
109<!DOCTYPE html PUBLIC 'foo'>
110<HTML>&entity;&#32;
111<!--comment1a
112-></foo><bar>&lt;<?pi?></foo<bar
113comment1b-->
114<Img sRc='Bar' isMAP>sample
115text
Fred Drake84bb9d82001-08-03 19:53:01 +0000116&#x201C;
Ezio Melotti4b92cc32012-02-13 16:10:44 +0200117<!--comment2a-- --comment2b-->
Fred Drakebd3090d2001-05-18 15:32:59 +0000118</Html>
119""", [
120 ("data", "\n"),
121 ("decl", "DOCTYPE html PUBLIC 'foo'"),
122 ("data", "\n"),
123 ("starttag", "html", []),
124 ("entityref", "entity"),
125 ("charref", "32"),
126 ("data", "\n"),
127 ("comment", "comment1a\n-></foo><bar>&lt;<?pi?></foo<bar\ncomment1b"),
128 ("data", "\n"),
129 ("starttag", "img", [("src", "Bar"), ("ismap", None)]),
130 ("data", "sample\ntext\n"),
Fred Drake84bb9d82001-08-03 19:53:01 +0000131 ("charref", "x201C"),
132 ("data", "\n"),
Fred Drakebd3090d2001-05-18 15:32:59 +0000133 ("comment", "comment2a-- --comment2b"),
134 ("data", "\n"),
135 ("endtag", "html"),
136 ("data", "\n"),
137 ])
138
Fred Drake073148c2001-12-03 16:44:09 +0000139 def test_unclosed_entityref(self):
140 self._run_check("&entityref foo", [
141 ("entityref", "entityref"),
142 ("data", " foo"),
143 ])
144
Fred Drake84bb9d82001-08-03 19:53:01 +0000145 def test_bad_nesting(self):
146 # Strangely, this *is* supposed to test that overlapping
147 # elements are allowed. HTMLParser is more geared toward
148 # lexing the input that parsing the structure.
Fred Drakebd3090d2001-05-18 15:32:59 +0000149 self._run_check("<a><b></a></b>", [
150 ("starttag", "a", []),
151 ("starttag", "b", []),
152 ("endtag", "a"),
153 ("endtag", "b"),
154 ])
155
Fred Drake029acfb2001-08-20 21:24:19 +0000156 def test_bare_ampersands(self):
157 self._run_check("this text & contains & ampersands &", [
158 ("data", "this text & contains & ampersands &"),
159 ])
160
161 def test_bare_pointy_brackets(self):
162 self._run_check("this < text > contains < bare>pointy< brackets", [
163 ("data", "this < text > contains < bare>pointy< brackets"),
164 ])
165
Fred Drakec20a6982001-09-04 15:13:04 +0000166 def test_illegal_declarations(self):
Ezio Melotti4b92cc32012-02-13 16:10:44 +0200167 self._run_check('<!spacer type="block" height="25">',
168 [('comment', 'spacer type="block" height="25"')])
Fred Drakec20a6982001-09-04 15:13:04 +0000169
Fred Drake84bb9d82001-08-03 19:53:01 +0000170 def test_starttag_end_boundary(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000171 self._run_check("""<a b='<'>""", [("starttag", "a", [("b", "<")])])
172 self._run_check("""<a b='>'>""", [("starttag", "a", [("b", ">")])])
173
Fred Drake84bb9d82001-08-03 19:53:01 +0000174 def test_buffer_artefacts(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000175 output = [("starttag", "a", [("b", "<")])]
176 self._run_check(["<a b='<'>"], output)
177 self._run_check(["<a ", "b='<'>"], output)
178 self._run_check(["<a b", "='<'>"], output)
179 self._run_check(["<a b=", "'<'>"], output)
180 self._run_check(["<a b='<", "'>"], output)
181 self._run_check(["<a b='<'", ">"], output)
182
183 output = [("starttag", "a", [("b", ">")])]
184 self._run_check(["<a b='>'>"], output)
185 self._run_check(["<a ", "b='>'>"], output)
186 self._run_check(["<a b", "='>'>"], output)
187 self._run_check(["<a b=", "'>'>"], output)
188 self._run_check(["<a b='>", "'>"], output)
189 self._run_check(["<a b='>'", ">"], output)
190
Fred Drake75d9a622004-09-08 22:57:01 +0000191 output = [("comment", "abc")]
192 self._run_check(["", "<!--abc-->"], output)
193 self._run_check(["<", "!--abc-->"], output)
194 self._run_check(["<!", "--abc-->"], output)
195 self._run_check(["<!-", "-abc-->"], output)
196 self._run_check(["<!--", "abc-->"], output)
197 self._run_check(["<!--a", "bc-->"], output)
198 self._run_check(["<!--ab", "c-->"], output)
199 self._run_check(["<!--abc", "-->"], output)
200 self._run_check(["<!--abc-", "->"], output)
201 self._run_check(["<!--abc--", ">"], output)
202 self._run_check(["<!--abc-->", ""], output)
203
Fred Drake84bb9d82001-08-03 19:53:01 +0000204 def test_starttag_junk_chars(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000205 self._parse_error("</>")
206 self._parse_error("</$>")
207 self._parse_error("</")
208 self._parse_error("</a")
Fred Drakebd3090d2001-05-18 15:32:59 +0000209 self._parse_error("<a<a>")
210 self._parse_error("</a<a>")
Fred Drakebd3090d2001-05-18 15:32:59 +0000211 self._parse_error("<!")
Fred Drakebd3090d2001-05-18 15:32:59 +0000212 self._parse_error("<a")
213 self._parse_error("<a foo='bar'")
214 self._parse_error("<a foo='bar")
215 self._parse_error("<a foo='>'")
216 self._parse_error("<a foo='>")
Fred Drakebd3090d2001-05-18 15:32:59 +0000217
Fred Drake84bb9d82001-08-03 19:53:01 +0000218 def test_declaration_junk_chars(self):
Ezio Melotti4b92cc32012-02-13 16:10:44 +0200219 self._run_check("<!DOCTYPE foo $ >", [('decl', 'DOCTYPE foo $ ')])
Fred Drakebd3090d2001-05-18 15:32:59 +0000220
Fred Drake84bb9d82001-08-03 19:53:01 +0000221 def test_startendtag(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000222 self._run_check("<p/>", [
223 ("startendtag", "p", []),
224 ])
225 self._run_check("<p></p>", [
226 ("starttag", "p", []),
227 ("endtag", "p"),
228 ])
229 self._run_check("<p><img src='foo' /></p>", [
230 ("starttag", "p", []),
231 ("startendtag", "img", [("src", "foo")]),
232 ("endtag", "p"),
233 ])
234
Fred Drake84bb9d82001-08-03 19:53:01 +0000235 def test_get_starttag_text(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000236 s = """<foo:bar \n one="1"\ttwo=2 >"""
237 self._run_check_extra(s, [
238 ("starttag", "foo:bar", [("one", "1"), ("two", "2")]),
239 ("starttag_text", s)])
240
Fred Drake84bb9d82001-08-03 19:53:01 +0000241 def test_cdata_content(self):
Ezio Melotti7e82b272011-11-01 14:09:56 +0200242 contents = [
243 '<!-- not a comment --> &not-an-entity-ref;',
244 "<not a='start tag'>",
245 '<a href="" /> <p> <span></span>',
246 'foo = "</scr" + "ipt>";',
247 'foo = "</SCRIPT" + ">";',
248 'foo = <\n/script> ',
249 '<!-- document.write("</scr" + "ipt>"); -->',
250 ('\n//<![CDATA[\n'
251 'document.write(\'<s\'+\'cript type="text/javascript" '
252 'src="http://www.example.org/r=\'+new '
253 'Date().getTime()+\'"><\\/s\'+\'cript>\');\n//]]>'),
254 '\n<!-- //\nvar foo = 3.14;\n// -->\n',
255 'foo = "</sty" + "le>";',
256 u'<!-- \u2603 -->',
257 # these two should be invalid according to the HTML 5 spec,
258 # section 8.1.2.2
259 #'foo = </\nscript>',
260 #'foo = </ script>',
261 ]
262 elements = ['script', 'style', 'SCRIPT', 'STYLE', 'Script', 'Style']
263 for content in contents:
264 for element in elements:
265 element_lower = element.lower()
266 s = u'<{element}>{content}</{element}>'.format(element=element,
267 content=content)
268 self._run_check(s, [("starttag", element_lower, []),
269 ("data", content),
270 ("endtag", element_lower)])
271
Ezio Melotti00dc60b2011-11-18 18:00:40 +0200272 def test_cdata_with_closing_tags(self):
273 # see issue #13358
274 # make sure that HTMLParser calls handle_data only once for each CDATA.
275 # The normal event collector normalizes the events in get_events,
276 # so we override it to return the original list of events.
277 class Collector(EventCollector):
278 def get_events(self):
279 return self.events
280
281 content = """<!-- not a comment --> &not-an-entity-ref;
282 <a href="" /> </p><p> &amp; <span></span></style>
283 '</script' + '>' </html> </head> </scripter>!"""
284 for element in [' script', 'script ', ' script ',
285 '\nscript', 'script\n', '\nscript\n']:
286 s = u'<script>{content}</{element}>'.format(element=element,
287 content=content)
288 self._run_check(s, [("starttag", "script", []),
289 ("data", content),
290 ("endtag", "script")],
291 collector=Collector)
292
Victor Stinner554a3b82010-05-24 21:33:24 +0000293 def test_malformatted_charref(self):
294 self._run_check("<p>&#bad;</p>", [
295 ("starttag", "p", []),
296 ("data", "&#bad;"),
297 ("endtag", "p"),
298 ])
299
Senthil Kumaran3f60f092010-12-28 16:05:07 +0000300 def test_unescape_function(self):
301 parser = HTMLParser.HTMLParser()
302 self.assertEqual(parser.unescape('&#bad;'),'&#bad;')
303 self.assertEqual(parser.unescape('&#0038;'),'&')
304
Fred Drakebd3090d2001-05-18 15:32:59 +0000305
Ezio Melotti74592912011-11-08 02:07:18 +0200306
307class AttributesTestCase(TestCaseBase):
308
309 def test_attr_syntax(self):
310 output = [
311 ("starttag", "a", [("b", "v"), ("c", "v"), ("d", "v"), ("e", None)])
312 ]
313 self._run_check("""<a b='v' c="v" d=v e>""", output)
314 self._run_check("""<a b = 'v' c = "v" d = v e>""", output)
315 self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output)
316 self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output)
317
318 def test_attr_values(self):
319 self._run_check("""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""",
320 [("starttag", "a", [("b", "xxx\n\txxx"),
321 ("c", "yyy\t\nyyy"),
322 ("d", "\txyz\n")])])
323 self._run_check("""<a b='' c="">""",
324 [("starttag", "a", [("b", ""), ("c", "")])])
325 # Regression test for SF patch #669683.
326 self._run_check("<e a=rgb(1,2,3)>",
327 [("starttag", "e", [("a", "rgb(1,2,3)")])])
328 # Regression test for SF bug #921657.
329 self._run_check(
330 "<a href=mailto:xyz@example.com>",
331 [("starttag", "a", [("href", "mailto:xyz@example.com")])])
332
333 def test_attr_nonascii(self):
334 # see issue 7311
335 self._run_check(
336 u"<img src=/foo/bar.png alt=\u4e2d\u6587>",
337 [("starttag", "img", [("src", "/foo/bar.png"),
338 ("alt", u"\u4e2d\u6587")])])
339 self._run_check(
340 u"<a title='\u30c6\u30b9\u30c8' href='\u30c6\u30b9\u30c8.html'>",
341 [("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"),
342 ("href", u"\u30c6\u30b9\u30c8.html")])])
343 self._run_check(
344 u'<a title="\u30c6\u30b9\u30c8" href="\u30c6\u30b9\u30c8.html">',
345 [("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"),
346 ("href", u"\u30c6\u30b9\u30c8.html")])])
347
348 def test_attr_entity_replacement(self):
349 self._run_check(
350 "<a b='&amp;&gt;&lt;&quot;&apos;'>",
351 [("starttag", "a", [("b", "&><\"'")])])
352
353 def test_attr_funky_names(self):
354 self._run_check(
355 "<a a.b='v' c:d=v e-f=v>",
356 [("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")])])
Ezio Melotti0f1571c2011-11-14 18:04:05 +0200357 self._run_check(
358 "<a $><b $=%><c \=/>",
359 [("starttag", "a", [("$", None)]),
360 ("starttag", "b", [("$", "%")]),
361 ("starttag", "c", [("\\", "/")])])
Ezio Melotti74592912011-11-08 02:07:18 +0200362
363 def test_entityrefs_in_attributes(self):
364 self._run_check(
365 "<html foo='&euro;&amp;&#97;&#x61;&unsupported;'>",
366 [("starttag", "html", [("foo", u"\u20AC&aa&unsupported;")])])
367
Ezio Melotti0f1571c2011-11-14 18:04:05 +0200368 def test_entities_in_attribute_value(self):
369 # see #1200313
370 for entity in ['&', '&amp;', '&#38;', '&#x26;']:
371 self._run_check('<a href="%s">' % entity,
372 [("starttag", "a", [("href", "&")])])
373 self._run_check("<a href='%s'>" % entity,
374 [("starttag", "a", [("href", "&")])])
375 self._run_check("<a href=%s>" % entity,
376 [("starttag", "a", [("href", "&")])])
377
378 def test_malformed_attributes(self):
379 # see #13357
380 html = (
381 "<a href=test'style='color:red;bad1'>test - bad1</a>"
382 "<a href=test'+style='color:red;ba2'>test - bad2</a>"
383 "<a href=test'&nbsp;style='color:red;bad3'>test - bad3</a>"
384 "<a href = test'&nbsp;style='color:red;bad4' >test - bad4</a>"
385 )
386 expected = [
387 ('starttag', 'a', [('href', "test'style='color:red;bad1'")]),
388 ('data', 'test - bad1'), ('endtag', 'a'),
389 ('starttag', 'a', [('href', "test'+style='color:red;ba2'")]),
390 ('data', 'test - bad2'), ('endtag', 'a'),
391 ('starttag', 'a', [('href', u"test'\xa0style='color:red;bad3'")]),
392 ('data', 'test - bad3'), ('endtag', 'a'),
393 ('starttag', 'a', [('href', u"test'\xa0style='color:red;bad4'")]),
394 ('data', 'test - bad4'), ('endtag', 'a')
395 ]
396 self._run_check(html, expected)
397
398 def test_malformed_adjacent_attributes(self):
399 # see #12629
400 self._run_check('<x><y z=""o"" /></x>',
401 [('starttag', 'x', []),
402 ('startendtag', 'y', [('z', ''), ('o""', None)]),
403 ('endtag', 'x')])
404 self._run_check('<x><y z="""" /></x>',
405 [('starttag', 'x', []),
406 ('startendtag', 'y', [('z', ''), ('""', None)]),
407 ('endtag', 'x')])
408
409 # see #755670 for the following 3 tests
410 def test_adjacent_attributes(self):
411 self._run_check('<a width="100%"cellspacing=0>',
412 [("starttag", "a",
413 [("width", "100%"), ("cellspacing","0")])])
414
415 self._run_check('<a id="foo"class="bar">',
416 [("starttag", "a",
417 [("id", "foo"), ("class","bar")])])
418
419 def test_missing_attribute_value(self):
420 self._run_check('<a v=>',
421 [("starttag", "a", [("v", "")])])
422
423 def test_javascript_attribute_value(self):
424 self._run_check("<a href=javascript:popup('/popup/help.html')>",
425 [("starttag", "a",
426 [("href", "javascript:popup('/popup/help.html')")])])
427
428 def test_end_tag_in_attribute_value(self):
429 # see #1745761
430 self._run_check("<a href='http://www.example.org/\">;'>spam</a>",
431 [("starttag", "a",
432 [("href", "http://www.example.org/\">;")]),
433 ("data", "spam"), ("endtag", "a")])
434
Ezio Melotti4b92cc32012-02-13 16:10:44 +0200435 def test_comments(self):
436 html = ("<!-- I'm a valid comment -->"
437 '<!--me too!-->'
438 '<!------>'
439 '<!---->'
440 '<!----I have many hyphens---->'
441 '<!-- I have a > in the middle -->'
442 '<!-- and I have -- in the middle! -->')
443 expected = [('comment', " I'm a valid comment "),
444 ('comment', 'me too!'),
445 ('comment', '--'),
446 ('comment', ''),
447 ('comment', '--I have many hyphens--'),
448 ('comment', ' I have a > in the middle '),
449 ('comment', ' and I have -- in the middle! ')]
450 self._run_check(html, expected)
451
452 def test_broken_comments(self):
453 html = ('<! not really a comment >'
454 '<! not a comment either -->'
455 '<! -- close enough -->'
456 '<!><!<-- this was an empty comment>'
457 '<!!! another bogus comment !!!>')
458 expected = [
459 ('comment', ' not really a comment '),
460 ('comment', ' not a comment either --'),
461 ('comment', ' -- close enough --'),
462 ('comment', ''),
463 ('comment', '<-- this was an empty comment'),
464 ('comment', '!! another bogus comment !!!'),
465 ]
466 self._run_check(html, expected)
467
Ezio Melotti6b7003a2011-12-19 07:28:08 +0200468 def test_condcoms(self):
469 html = ('<!--[if IE & !(lte IE 8)]>aren\'t<![endif]-->'
470 '<!--[if IE 8]>condcoms<![endif]-->'
471 '<!--[if lte IE 7]>pretty?<![endif]-->')
472 expected = [('comment', "[if IE & !(lte IE 8)]>aren't<![endif]"),
473 ('comment', '[if IE 8]>condcoms<![endif]'),
474 ('comment', '[if lte IE 7]>pretty?<![endif]')]
475 self._run_check(html, expected)
476
477 def test_broken_condcoms(self):
478 # these condcoms are missing the '--' after '<!' and before the '>'
479 html = ('<![if !(IE)]>broken condcom<![endif]>'
480 '<![if ! IE]><link href="favicon.tiff"/><![endif]>'
481 '<![if !IE 6]><img src="firefox.png" /><![endif]>'
482 '<![if !ie 6]><b>foo</b><![endif]>'
483 '<![if (!IE)|(lt IE 9)]><img src="mammoth.bmp" /><![endif]>')
484 # According to the HTML5 specs sections "8.2.4.44 Bogus comment state"
485 # and "8.2.4.45 Markup declaration open state", comment tokens should
486 # be emitted instead of 'unknown decl', but calling unknown_decl
487 # provides more flexibility.
488 # See also Lib/_markupbase.py:parse_declaration
489 expected = [
490 ('unknown decl', 'if !(IE)'),
491 ('data', 'broken condcom'),
492 ('unknown decl', 'endif'),
493 ('unknown decl', 'if ! IE'),
494 ('startendtag', 'link', [('href', 'favicon.tiff')]),
495 ('unknown decl', 'endif'),
496 ('unknown decl', 'if !IE 6'),
497 ('startendtag', 'img', [('src', 'firefox.png')]),
498 ('unknown decl', 'endif'),
499 ('unknown decl', 'if !ie 6'),
500 ('starttag', 'b', []),
501 ('data', 'foo'),
502 ('endtag', 'b'),
503 ('unknown decl', 'endif'),
504 ('unknown decl', 'if (!IE)|(lt IE 9)'),
505 ('startendtag', 'img', [('src', 'mammoth.bmp')]),
506 ('unknown decl', 'endif')
507 ]
508 self._run_check(html, expected)
509
Ezio Melotti0f1571c2011-11-14 18:04:05 +0200510
Fred Drakee8220492001-09-24 20:19:08 +0000511def test_main():
Ezio Melotti74592912011-11-08 02:07:18 +0200512 test_support.run_unittest(HTMLParserTestCase, AttributesTestCase)
Fred Drakee8220492001-09-24 20:19:08 +0000513
514
515if __name__ == "__main__":
516 test_main()