tests/test-encoding-func.py
changeset 43076 2372284d9457
parent 37947 3ea3c96ada54
child 48875 6000f5b25c9b
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
     1 from __future__ import absolute_import
     1 from __future__ import absolute_import
     2 
     2 
     3 import unittest
     3 import unittest
     4 
     4 
     5 from mercurial import (
     5 from mercurial import encoding
     6     encoding,
     6 
     7 )
       
     8 
     7 
     9 class IsasciistrTest(unittest.TestCase):
     8 class IsasciistrTest(unittest.TestCase):
    10     asciistrs = [
     9     asciistrs = [
    11         b'a',
    10         b'a',
    12         b'ab',
    11         b'ab',
    26             for i in range(len(s)):
    25             for i in range(len(s)):
    27                 t = bytearray(s)
    26                 t = bytearray(s)
    28                 t[i] |= 0x80
    27                 t[i] |= 0x80
    29                 self.assertFalse(encoding.isasciistr(bytes(t)))
    28                 self.assertFalse(encoding.isasciistr(bytes(t)))
    30 
    29 
       
    30 
    31 class LocalEncodingTest(unittest.TestCase):
    31 class LocalEncodingTest(unittest.TestCase):
    32     def testasciifastpath(self):
    32     def testasciifastpath(self):
    33         s = b'\0' * 100
    33         s = b'\0' * 100
    34         self.assertTrue(s is encoding.tolocal(s))
    34         self.assertTrue(s is encoding.tolocal(s))
    35         self.assertTrue(s is encoding.fromlocal(s))
    35         self.assertTrue(s is encoding.fromlocal(s))
       
    36 
    36 
    37 
    37 class Utf8bEncodingTest(unittest.TestCase):
    38 class Utf8bEncodingTest(unittest.TestCase):
    38     def setUp(self):
    39     def setUp(self):
    39         self.origencoding = encoding.encoding
    40         self.origencoding = encoding.encoding
    40 
    41 
    73         s = u'\ud1bc'.encode('utf-8')
    74         s = u'\ud1bc'.encode('utf-8')
    74         l = encoding.tolocal(s)
    75         l = encoding.tolocal(s)
    75         self.assertEqual(l, b'\xc5\xed')  # lossless
    76         self.assertEqual(l, b'\xc5\xed')  # lossless
    76         self.assertEqual(s, encoding.toutf8b(l))  # convert back to utf-8
    77         self.assertEqual(s, encoding.toutf8b(l))  # convert back to utf-8
    77 
    78 
       
    79 
    78 if __name__ == '__main__':
    80 if __name__ == '__main__':
    79     import silenttestrunner
    81     import silenttestrunner
       
    82 
    80     silenttestrunner.main(__name__)
    83     silenttestrunner.main(__name__)