Skip to content

Commit 3d88c18

Browse files
[3.13] gh-126332: Add tests for _pyrepl.utils (GH-129325) (#130414)
gh-126332: Add tests for _pyrepl.utils (GH-129325) (cherry picked from commit 0c4248f) Co-authored-by: Pieter Eendebak <[email protected]>
1 parent 8db3eee commit 3d88c18

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Lib/test/test_pyrepl/test_utils.py

Lines changed: 27 additions & 0 deletions
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)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add unit tests for pyrepl.

0 commit comments

Comments
 (0)