Skip to content

Commit 0c4248f

Browse files
authored
gh-126332: Add tests for _pyrepl.utils (#129325)
1 parent 1cf9b6d commit 0c4248f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Lib/test/test_pyrepl/test_utils.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from unittest import TestCase
2+
3+
from _pyrepl.utils import str_width, wlen
4+
5+
6+
class TestUtils(TestCase):
7+
def test_str_width(self):
8+
characters = ['a', '1', '_', '!', '\x1a', '\u263A', '\uffb9']
9+
for c in characters:
10+
self.assertEqual(str_width(c), 1)
11+
12+
characters = [chr(99989), chr(99999)]
13+
for c in characters:
14+
self.assertEqual(str_width(c), 2)
15+
16+
def test_wlen(self):
17+
for c in ['a', 'b', '1', '!', '_']:
18+
self.assertEqual(wlen(c), 1)
19+
self.assertEqual(wlen('\x1a'), 2)
20+
21+
char_east_asian_width_N = chr(3800)
22+
self.assertEqual(wlen(char_east_asian_width_N), 1)
23+
char_east_asian_width_W = chr(4352)
24+
self.assertEqual(wlen(char_east_asian_width_W), 2)
25+
26+
self.assertEqual(wlen('hello'), 5)
27+
self.assertEqual(wlen('hello' + '\x1a'), 7)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add unit tests for pyrepl.

0 commit comments

Comments
 (0)