aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/wcwidth/py3/tests/test_core.py
diff options
context:
space:
mode:
authornkozlovskiy <nmk@ydb.tech>2023-09-29 12:24:06 +0300
committernkozlovskiy <nmk@ydb.tech>2023-09-29 12:41:34 +0300
commite0e3e1717e3d33762ce61950504f9637a6e669ed (patch)
treebca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/wcwidth/py3/tests/test_core.py
parent38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff)
downloadydb-e0e3e1717e3d33762ce61950504f9637a6e669ed.tar.gz
add ydb deps
Diffstat (limited to 'contrib/python/wcwidth/py3/tests/test_core.py')
-rw-r--r--contrib/python/wcwidth/py3/tests/test_core.py158
1 files changed, 158 insertions, 0 deletions
diff --git a/contrib/python/wcwidth/py3/tests/test_core.py b/contrib/python/wcwidth/py3/tests/test_core.py
new file mode 100644
index 0000000000..c8f791c016
--- /dev/null
+++ b/contrib/python/wcwidth/py3/tests/test_core.py
@@ -0,0 +1,158 @@
+# coding: utf-8
+"""Core tests for wcwidth module. isort:skip_file"""
+try:
+ # std import
+ import importlib.metadata as importmeta
+except ImportError:
+ # 3rd party for python3.7 and earlier
+ import importlib_metadata as importmeta
+
+# local
+import wcwidth
+
+
+def test_package_version():
+ """wcwidth.__version__ is expected value."""
+ # given,
+ expected = importmeta.version('wcwidth')
+
+ # exercise,
+ result = wcwidth.__version__
+
+ # verify.
+ assert result == expected
+
+
+def test_hello_jp():
+ u"""
+ Width of Japanese phrase: コンニチハ, セカイ!
+
+ Given a phrase of 5 and 3 Katakana ideographs, joined with
+ 3 English-ASCII punctuation characters, totaling 11, this
+ phrase consumes 19 cells of a terminal emulator.
+ """
+ # given,
+ phrase = u'コンニチハ, セカイ!'
+ expect_length_each = (2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 1)
+ expect_length_phrase = sum(expect_length_each)
+
+ # exercise,
+ length_each = tuple(map(wcwidth.wcwidth, phrase))
+ length_phrase = wcwidth.wcswidth(phrase)
+
+ # verify.
+ assert length_each == expect_length_each
+ assert length_phrase == expect_length_phrase
+
+
+def test_wcswidth_substr():
+ """
+ Test wcswidth() optional 2nd parameter, ``n``.
+
+ ``n`` determines at which position of the string
+ to stop counting length.
+ """
+ # given,
+ phrase = u'コンニチハ, セカイ!'
+ end = 7
+ expect_length_each = (2, 2, 2, 2, 2, 1, 1,)
+ expect_length_phrase = sum(expect_length_each)
+
+ # exercise,
+ length_phrase = wcwidth.wcswidth(phrase, end)
+
+ # verify.
+ assert length_phrase == expect_length_phrase
+
+
+def test_null_width_0():
+ """NULL (0) reports width 0."""
+ # given,
+ phrase = u'abc\x00def'
+ expect_length_each = (1, 1, 1, 0, 1, 1, 1)
+ expect_length_phrase = sum(expect_length_each)
+
+ # exercise,
+ length_each = tuple(map(wcwidth.wcwidth, phrase))
+ length_phrase = wcwidth.wcswidth(phrase, len(phrase))
+
+ # verify.
+ assert length_each == expect_length_each
+ assert length_phrase == expect_length_phrase
+
+
+def test_control_c0_width_negative_1():
+ """CSI (Control sequence initiate) reports width -1 for ESC."""
+ # given,
+ phrase = u'\x1b[0m'
+ expect_length_each = (-1, 1, 1, 1)
+ expect_length_phrase = -1
+
+ # exercise,
+ length_each = tuple(map(wcwidth.wcwidth, phrase))
+ length_phrase = wcwidth.wcswidth(phrase, len(phrase))
+
+ # verify.
+ assert length_each == expect_length_each
+ assert length_phrase == expect_length_phrase
+
+
+def test_combining_width():
+ """Simple test combining reports total width of 4."""
+ # given,
+ phrase = u'--\u05bf--'
+ expect_length_each = (1, 1, 0, 1, 1)
+ expect_length_phrase = 4
+
+ # exercise,
+ length_each = tuple(map(wcwidth.wcwidth, phrase))
+ length_phrase = wcwidth.wcswidth(phrase, len(phrase))
+
+ # verify.
+ assert length_each == expect_length_each
+ assert length_phrase == expect_length_phrase
+
+
+def test_combining_cafe():
+ u"""Phrase cafe + COMBINING ACUTE ACCENT is café of length 4."""
+ phrase = u"cafe\u0301"
+ expect_length_each = (1, 1, 1, 1, 0)
+ expect_length_phrase = 4
+
+ # exercise,
+ length_each = tuple(map(wcwidth.wcwidth, phrase))
+ length_phrase = wcwidth.wcswidth(phrase, len(phrase))
+
+ # verify.
+ assert length_each == expect_length_each
+ assert length_phrase == expect_length_phrase
+
+
+def test_combining_enclosing():
+ u"""CYRILLIC CAPITAL LETTER A + COMBINING CYRILLIC HUNDRED THOUSANDS SIGN is А҈ of length 1."""
+ phrase = u"\u0410\u0488"
+ expect_length_each = (1, 0)
+ expect_length_phrase = 1
+
+ # exercise,
+ length_each = tuple(map(wcwidth.wcwidth, phrase))
+ length_phrase = wcwidth.wcswidth(phrase, len(phrase))
+
+ # verify.
+ assert length_each == expect_length_each
+ assert length_phrase == expect_length_phrase
+
+
+def test_combining_spacing():
+ u"""Balinese kapal (ship) is ᬓᬨᬮ᭄ of length 4."""
+ phrase = u"\u1B13\u1B28\u1B2E\u1B44"
+ expect_length_each = (1, 1, 1, 1)
+ expect_length_phrase = 4
+
+ # exercise,
+ length_each = tuple(map(wcwidth.wcwidth, phrase))
+ length_phrase = wcwidth.wcswidth(phrase, len(phrase))
+
+ # verify.
+ assert length_each == expect_length_each
+ assert length_phrase == expect_length_phrase