comparison tests/test-encoding-func.py @ 33926:f4433f2713d0

encoding: add function to test if a str consists of ASCII characters Most strings are ASCII. Let's optimize for it. Using uint64_t is slightly faster than uint32_t on 64bit system, but there isn't huge difference.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 23 Apr 2017 12:59:42 +0900
parents
children 853574db5b12
comparison
equal deleted inserted replaced
33925:2c37f9dabc32 33926:f4433f2713d0
1 from __future__ import absolute_import
2
3 import unittest
4
5 from mercurial import (
6 encoding,
7 )
8
9 class IsasciistrTest(unittest.TestCase):
10 asciistrs = [
11 b'a',
12 b'ab',
13 b'abc',
14 b'abcd',
15 b'abcde',
16 b'abcdefghi',
17 b'abcd\0fghi',
18 ]
19
20 def testascii(self):
21 for s in self.asciistrs:
22 self.assertTrue(encoding.isasciistr(s))
23
24 def testnonasciichar(self):
25 for s in self.asciistrs:
26 for i in range(len(s)):
27 t = bytearray(s)
28 t[i] |= 0x80
29 self.assertFalse(encoding.isasciistr(bytes(t)))
30
31 if __name__ == '__main__':
32 import silenttestrunner
33 silenttestrunner.main(__name__)