Repository navigation
Expand file tree
/
Copy pathbasic_3.py
More file actions
121 lines (92 loc) · 2.48 KB
/
Copy pathbasic_3.py
File metadata and controls
121 lines (92 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
import unittest
import sys
from unidecode import unidecode
class TestUnidecode(unittest.TestCase):
def test_ascii(self):
for n in range(0,128):
t = chr(n)
self.failUnlessEqual(unidecode(t), t)
def test_bmp(self):
for n in range(0,0x10000):
# Just check that it doesn't throw an exception
t = chr(n)
unidecode(t)
def test_circled_latin(self):
# 1 sequence of a-z
for n in range(0, 26):
a = chr(ord('a') + n)
b = unidecode(chr(0x24d0 + n))
self.failUnlessEqual(b, a)
@unittest.skipIf(sys.maxunicode < 0x10000, "narrow build")
def test_mathematical_latin(self):
# 13 consecutive sequences of A-Z, a-z with some codepoints
# undefined. We just count the undefined ones and don't check
# positions.
empty = 0
for n in range(0x1d400, 0x1d6a4):
if n % 52 < 26:
a = chr(ord('A') + n % 26)
else:
a = chr(ord('a') + n % 26)
b = unidecode(chr(n))
if not b:
empty += 1
else:
self.failUnlessEqual(b, a)
self.failUnlessEqual(empty, 24)
@unittest.skipIf(sys.maxunicode < 0x10000, "narrow build")
def test_mathematical_digits(self):
# 5 consecutive sequences of 0-9
for n in range(0x1d7ce, 0x1d800):
a = chr(ord('0') + (n-0x1d7ce) % 10)
b = unidecode(chr(n))
self.failUnlessEqual(b, a)
def test_specific(self):
TESTS = [
("Hello, World!",
"Hello, World!"),
("'\"\r\n",
"'\"\r\n"),
("ČŽŠčžš",
"CZSczs"),
("ア",
"a"),
("α",
"a"),
("а",
"a"),
('ch\xe2teau',
"chateau"),
('vi\xf1edos',
"vinedos"),
("\u5317\u4EB0",
"Bei Jing "),
("Efficient",
"Efficient"),
# https://github.com/iki/unidecode/commit/4a1d4e0a7b5a11796dc701099556876e7a520065
('příliš žluťoučký kůň pěl ďábelské ódy',
'prilis zlutoucky kun pel dabelske ody'),
('PŘÍLIŠ ŽLUŤOUČKÝ KŮŇ PĚL ĎÁBELSKÉ ÓDY',
'PRILIS ZLUTOUCKY KUN PEL DABELSKE ODY'),
# Table that doesn't exist
('\ua500',
''),
# Table that has less than 256 entriees
('\u1eff',
''),
]
for instr, output in TESTS:
self.failUnlessEqual(unidecode(instr), output)
@unittest.skipIf(sys.maxunicode < 0x10000, "narrow build")
def test_specific_wide(self):
TESTS = [
# Non-BMP character
('\U0001d5a0',
'A'),
# Mathematical
('\U0001d5c4\U0001d5c6/\U0001d5c1',
'km/h'),
]
for instr, output in TESTS:
self.failUnlessEqual(unidecode(instr), output)