509
509
TestCase.setUp(self)
510
510
# Keep the cache clear before and after the test
511
bzrlib.xml8._ensure_utf8_re()
512
bzrlib.xml8._clear_cache()
513
self.addCleanup(bzrlib.xml8._clear_cache)
511
bzrlib.xml_serializer._clear_cache()
512
self.addCleanup(bzrlib.xml_serializer._clear_cache)
515
514
def test_simple_ascii(self):
516
515
# _encode_and_escape always appends a final ", because these parameters
517
516
# are being used in xml attributes, and by returning it now, we have to
518
517
# do fewer string operations later.
519
val = bzrlib.xml8._encode_and_escape('foo bar')
518
val = bzrlib.xml_serializer.encode_and_escape('foo bar')
520
519
self.assertEqual('foo bar"', val)
521
520
# The second time should be cached
522
val2 = bzrlib.xml8._encode_and_escape('foo bar')
521
val2 = bzrlib.xml_serializer.encode_and_escape('foo bar')
523
522
self.assertIs(val2, val)
525
524
def test_ascii_with_xml(self):
526
525
self.assertEqual('&'"<>"',
527
bzrlib.xml8._encode_and_escape('&\'"<>'))
526
bzrlib.xml_serializer.encode_and_escape('&\'"<>'))
529
528
def test_utf8_with_xml(self):
530
529
# u'\xb5\xe5&\u062c'
531
530
utf8_str = '\xc2\xb5\xc3\xa5&\xd8\xac'
532
531
self.assertEqual('µå&ج"',
533
bzrlib.xml8._encode_and_escape(utf8_str))
532
bzrlib.xml_serializer.encode_and_escape(utf8_str))
535
534
def test_unicode(self):
536
535
uni_str = u'\xb5\xe5&\u062c'
537
536
self.assertEqual('µå&ج"',
538
bzrlib.xml8._encode_and_escape(uni_str))
537
bzrlib.xml_serializer.encode_and_escape(uni_str))
541
540
class TestMisc(TestCase):