comparison markup/tests/input.py @ 209:fc6b2fb66518 trunk

* Fix bug in handling of undefined entities. Thanks to Arnar for reporting the issue on IRC. * Enable the `XMLParser` to handle HTML entities without requiring the declaration of a HTML document type.
author cmlenz
date Tue, 29 Aug 2006 16:34:40 +0000
parents 28bfc6aafab7
children
comparison
equal deleted inserted replaced
208:bc146e63c159 209:fc6b2fb66518
15 from StringIO import StringIO 15 from StringIO import StringIO
16 import sys 16 import sys
17 import unittest 17 import unittest
18 18
19 from markup.core import Stream 19 from markup.core import Stream
20 from markup.input import XMLParser, HTMLParser 20 from markup.input import XMLParser, HTMLParser, ParseError
21 21
22 22
23 class XMLParserTestCase(unittest.TestCase): 23 class XMLParserTestCase(unittest.TestCase):
24 24
25 def test_text_node_pos_single_line(self): 25 def test_text_node_pos_single_line(self):
57 events = list(XMLParser(StringIO(text))) 57 events = list(XMLParser(StringIO(text)))
58 kind, data, pos = events[1] 58 kind, data, pos = events[1]
59 self.assertEqual(Stream.TEXT, kind) 59 self.assertEqual(Stream.TEXT, kind)
60 self.assertEqual(u'\u2013', data) 60 self.assertEqual(u'\u2013', data)
61 61
62 def test_html_entity_with_dtd(self):
63 text = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
64 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
65 <html>&nbsp;</html>
66 """
67 events = list(XMLParser(StringIO(text)))
68 kind, data, pos = events[2]
69 self.assertEqual(Stream.TEXT, kind)
70 self.assertEqual(u'\xa0', data)
71
72 def test_html_entity_without_dtd(self):
73 text = '<html>&nbsp;</html>'
74 events = list(XMLParser(StringIO(text)))
75 kind, data, pos = events[1]
76 self.assertEqual(Stream.TEXT, kind)
77 self.assertEqual(u'\xa0', data)
78
79 def test_undefined_entity_with_dtd(self):
80 text = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
81 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
82 <html>&junk;</html>
83 """
84 events = XMLParser(StringIO(text))
85 self.assertRaises(ParseError, list, events)
86
87 def test_undefined_entity_without_dtd(self):
88 text = '<html>&junk;</html>'
89 events = XMLParser(StringIO(text))
90 self.assertRaises(ParseError, list, events)
91
62 92
63 class HTMLParserTestCase(unittest.TestCase): 93 class HTMLParserTestCase(unittest.TestCase):
64 94
65 def test_text_node_pos_single_line(self): 95 def test_text_node_pos_single_line(self):
66 text = '<elem>foo bar</elem>' 96 text = '<elem>foo bar</elem>'
Copyright (C) 2012-2017 Edgewall Software