@@ -293,13 +293,50 @@ def test_context_flag_exit_err(context_flag):
293293 context_flag .__exit__ ()
294294
295295
296+ def test_truncate_string ():
297+ text = 'long'
298+ max_width = 3
299+ truncated = cu .truncate_string (text , max_width )
300+ assert truncated == 'lo\N{HORIZONTAL ELLIPSIS} '
301+
302+ def test_truncate_string_newline_in_text ():
303+ text = 'fo\n o'
304+ max_width = 2
305+ with pytest .raises (ValueError ):
306+ cu .truncate_string (text , max_width )
307+
308+ def test_truncate_string_width_is_too_small ():
309+ text = 'foo'
310+ max_width = 0
311+ with pytest .raises (ValueError ):
312+ cu .truncate_string (text , max_width )
313+
314+ def test_truncate_string_wide_text ():
315+ text = '苹苹other'
316+ max_width = 6
317+ truncated = cu .truncate_string (text , max_width )
318+ assert truncated == '苹苹o\N{HORIZONTAL ELLIPSIS} '
319+
320+ def test_truncate_string_tabs ():
321+ text = 'has\t tab'
322+ max_width = 9
323+ truncated = cu .truncate_string (text , max_width )
324+ assert truncated == 'has t\N{HORIZONTAL ELLIPSIS} '
325+
296326def test_align_text_fill_char_is_tab ():
297327 text = 'foo'
298328 fill_char = '\t '
299329 width = 5
300330 aligned = cu .align_text (text , cu .TextAlignment .LEFT , fill_char = fill_char , width = width )
301331 assert aligned == text + ' '
302332
333+ def test_align_text_width_is_too_small ():
334+ text = 'foo'
335+ fill_char = '-'
336+ width = 0
337+ with pytest .raises (ValueError ):
338+ cu .align_text (text , cu .TextAlignment .LEFT , fill_char = fill_char , width = width )
339+
303340def test_align_text_fill_char_is_too_long ():
304341 text = 'foo'
305342 fill_char = 'fill'
@@ -340,7 +377,7 @@ def test_align_text_wider_than_width_truncate():
340377 fill_char = '-'
341378 width = 8
342379 aligned = cu .align_text (text , cu .TextAlignment .LEFT , fill_char = fill_char , width = width , truncate = True )
343- assert aligned == 'long te' + " \N{HORIZONTAL ELLIPSIS} "
380+ assert aligned == 'long te\N{HORIZONTAL ELLIPSIS} '
344381
345382def test_align_text_has_unprintable ():
346383 text = 'foo\x02 '
0 commit comments