Skip to content

Commit 1e3781b

Browse files
Rosuavpfalcon
authored andcommitted
tests: Add unicode test.
1 parent 9a1a4be commit 1e3781b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/unicode/unicode.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test a UTF-8 encoded literal
2+
s = "asdf©qwer"
3+
for i in range(len(s)):
4+
print("s[%d]: %s %X"%(i, s[i], ord(s[i])))
5+
6+
# Test all three forms of Unicode escape, and
7+
# all blocks of UTF-8 byte patterns
8+
s = "a\xA9\xFF\u0123\u0800\uFFEE\U0001F44C"
9+
for i in range(-len(s), len(s)):
10+
print("s[%d]: %s %X"%(i, s[i], ord(s[i])))
11+
print("s[:%d]: %d chars, '%s'"%(i, len(s[:i]), s[:i]))
12+
for j in range(i, len(s)):
13+
print("s[%d:%d]: %d chars, '%s'"%(i, j, len(s[i:j]), s[i:j]))
14+
print("s[%d:]: %d chars, '%s'"%(i, len(s[i:]), s[i:]))
15+
16+
# Test UTF-8 encode and decode
17+
enc = s.encode()
18+
print(enc, enc.decode() == s)

0 commit comments

Comments
 (0)