Skip to content

Commit c576b07

Browse files
committed
add test case from pull request #387 - test_wrap_color_line_longword_zerowidth
1 parent 877c020 commit c576b07

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

test/test_textwrapper.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,44 @@ def test_wrap_color_line_longword():
174174
assert_equal(expected, result)
175175

176176

177+
def test_wrap_color_line_longword_zerowidth():
178+
"""Lines with zero-width symbols (accents) must include those symbols with the prior symbol.
179+
Let's exercise the calculation where the available symbols never satisfy the available width,
180+
and ensure chunk calculation succeeds and ANSI colors are maintained.
181+
182+
Most combining marks combine with the preceding character (even in right-to-left alphabets):
183+
- "e\u0301" → "é" (e + combining acute accent)
184+
- "a\u0308" → "ä" (a + combining diaeresis)
185+
- "n\u0303" → "ñ" (n + combining tilde)
186+
Enclosing Marks: Some combining marks enclose the base character:
187+
- "A\u20dd" → Ⓐ Combining enclosing circle
188+
Multiple Combining Marks: You can stack multiple combining marks on a single base character:
189+
- "e\u0301\u0308" → e with both acute accent and diaeresis
190+
Zero width space → "ab" with a :
191+
- "a\u200bb"
192+
193+
"""
194+
try:
195+
import wcwidth # noqa
196+
except ImportError:
197+
skip("test_wrap_wide_char is skipped")
198+
199+
# Exactly filled, with a green zero-width segment at the end.
200+
data = (
201+
"This_is_A\u20dd_\033[31mte\u0301st_string_\u200b"
202+
"to_te\u0301\u0308st_a\u0308ccent\033[32m\u200b\033[0m"
203+
)
204+
205+
expected = [
206+
"This_is_A\u20dd_\033[31mte\u0301\033[0m",
207+
"\033[31mst_string_\u200bto\033[0m",
208+
"\033[31m_te\u0301\u0308st_a\u0308ccent\033[32m\u200b\033[0m",
209+
]
210+
wrapper = CTW(width=12)
211+
result = wrapper.wrap(data)
212+
assert_equal(expected, result)
213+
214+
177215
def test_wrap_color_line_multiple_escapes():
178216
data = "012345(\x1b[32ma\x1b[0mbc\x1b[32mdefghij\x1b[0m)"
179217
expected = [

0 commit comments

Comments
 (0)