diff options
author | Chris Angelico <rosuav@gmail.com> | 2014-06-04 05:28:12 +1000 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-27 00:04:17 +0300 |
commit | 1e3781bc3527f72053fdc4aad4f4887c567c457c (patch) | |
tree | 59b52e831f3bff3cf70694328fb419972ddd45cc | |
parent | 9a1a4beb563f8e2ae111ff062a64989774f29058 (diff) | |
download | micropython-1e3781bc3527f72053fdc4aad4f4887c567c457c.tar.gz micropython-1e3781bc3527f72053fdc4aad4f4887c567c457c.zip |
tests: Add unicode test.
-rw-r--r-- | tests/unicode/unicode.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/unicode/unicode.py b/tests/unicode/unicode.py new file mode 100644 index 0000000000..c7e523f06a --- /dev/null +++ b/tests/unicode/unicode.py @@ -0,0 +1,18 @@ +# Test a UTF-8 encoded literal +s = "asdf©qwer" +for i in range(len(s)): + print("s[%d]: %s %X"%(i, s[i], ord(s[i]))) + +# Test all three forms of Unicode escape, and +# all blocks of UTF-8 byte patterns +s = "a\xA9\xFF\u0123\u0800\uFFEE\U0001F44C" +for i in range(-len(s), len(s)): + print("s[%d]: %s %X"%(i, s[i], ord(s[i]))) + print("s[:%d]: %d chars, '%s'"%(i, len(s[:i]), s[:i])) + for j in range(i, len(s)): + print("s[%d:%d]: %d chars, '%s'"%(i, j, len(s[i:j]), s[i:j])) + print("s[%d:]: %d chars, '%s'"%(i, len(s[i:]), s[i:])) + +# Test UTF-8 encode and decode +enc = s.encode() +print(enc, enc.decode() == s) |