274
274
if ie.revision is None:
276
276
self.assertIsInstance(ie.revision, str)
279
class TestEncodeAndEscape(TestCase):
280
"""Whitebox testing of the _encode_and_escape function."""
283
# Keep the cache clear before and after the test
284
bzrlib.xml5._ensure_utf8_re()
285
bzrlib.xml5._clear_cache()
286
self.addCleanup(bzrlib.xml5._clear_cache)
288
def test_simple_ascii(self):
289
# _encode_and_escape always appends a final ", because these parameters
290
# are being used in xml attributes, and by returning it now, we have to
291
# do fewer string operations later.
292
val = bzrlib.xml5._encode_and_escape('foo bar')
293
self.assertEqual('foo bar"', val)
294
# The second time should be cached
295
val2 = bzrlib.xml5._encode_and_escape('foo bar')
296
self.assertIs(val2, val)
298
def test_ascii_with_xml(self):
299
self.assertEqual('&'"<>"',
300
bzrlib.xml5._encode_and_escape('&\'"<>'))
302
def test_utf8_with_xml(self):
304
utf8_str = '\xc2\xb5\xc3\xa5&\xd8\xac'
305
self.assertEqual('µå&ج"',
306
bzrlib.xml5._encode_and_escape(utf8_str))
308
def test_unicode(self):
309
uni_str = u'\xb5\xe5&\u062c'
310
self.assertEqual('µå&ج"',
311
bzrlib.xml5._encode_and_escape(uni_str))