[xmlReader_test] test newlines gets normalised by expat parser, unless escaped
This commit is contained in:
parent
5102353afb
commit
9f846d3687
@ -46,6 +46,36 @@ class TestXMLReader(unittest.TestCase):
|
||||
content = strjoin(reader.contents[0]).strip()
|
||||
self.assertEqual(expected, content)
|
||||
|
||||
def test_normalise_newlines(self):
|
||||
|
||||
class DebugXMLReader(XMLReader):
|
||||
|
||||
def __init__(self, fileName, ttFont, progress=None, quiet=False):
|
||||
super(DebugXMLReader, self).__init__(
|
||||
fileName, ttFont, progress, quiet)
|
||||
self.newlines = []
|
||||
|
||||
def _characterDataHandler(self, data):
|
||||
self.newlines.extend([c for c in data if c in ('\r', '\n')])
|
||||
|
||||
# notice how when CR is escaped, it is not normalised by the XML parser
|
||||
data = (
|
||||
'<ttFont>\r' # \r -> \n
|
||||
' <test>\r\n' # \r\n -> \n
|
||||
' a line of text\n' # \n
|
||||
' escaped CR and unix newline \n' # \n -> \r\n
|
||||
' escaped CR and macintosh newline \r' # \r -> \r\n
|
||||
' escaped CR and windows newline \r\n' # \r\n -> \r\n
|
||||
' </test>\n' # \n
|
||||
'</ttFont>')
|
||||
with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
||||
tmp.write(data.encode('utf-8'))
|
||||
reader = DebugXMLReader(tmp.name, TTFont(), quiet=True)
|
||||
reader.read()
|
||||
os.remove(tmp.name)
|
||||
expected = ['\n'] * 3 + ['\r', '\n'] * 3 + ['\n']
|
||||
self.assertEqual(expected, reader.newlines)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user