Mercurial > hg
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-encoding-func.py Sun Apr 23 12:59:42 2017 +0900 @@ -0,0 +1,33 @@ +from __future__ import absolute_import + +import unittest + +from mercurial import ( + encoding, +) + +class IsasciistrTest(unittest.TestCase): + asciistrs = [ + b'a', + b'ab', + b'abc', + b'abcd', + b'abcde', + b'abcdefghi', + b'abcd\0fghi', + ] + + def testascii(self): + for s in self.asciistrs: + self.assertTrue(encoding.isasciistr(s)) + + def testnonasciichar(self): + for s in self.asciistrs: + for i in range(len(s)): + t = bytearray(s) + t[i] |= 0x80 + self.assertFalse(encoding.isasciistr(bytes(t))) + +if __name__ == '__main__': + import silenttestrunner + silenttestrunner.main(__name__)