Skip to content

Commit 4c3cd73

Browse files
committed
Added more unit tests for text alignment
1 parent 6c52256 commit 4c3cd73

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

tests/test_utils.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,21 @@ def test_left_text_multiline():
369369
assert aligned == ('foo----\n'
370370
'shoes--')
371371

372-
def test_left_text_asian_fill():
373-
"""Test fill_char with display width greater than 1"""
372+
def test_left_wide_display_text():
373+
text = '苹'
374+
fill_char = '-'
375+
width = 4
376+
aligned = cu.ljustify_text(text, fill_char=fill_char, width=width)
377+
assert aligned == text + fill_char + fill_char
378+
379+
def test_left_text_wide_display_fill():
374380
text = 'foo'
375381
fill_char = '苹'
376382
width = 5
377383
aligned = cu.ljustify_text(text, fill_char=fill_char, width=width)
378384
assert aligned == text + fill_char
379385

380-
def test_left_text_asian_fill_needs_padding():
386+
def test_left_text_wide_display_fill_needs_padding():
381387
"""Test when fill_char's display width does not divide evenly into gap"""
382388
text = 'foo'
383389
fill_char = '苹'
@@ -400,23 +406,29 @@ def test_center_text_multiline():
400406
assert aligned == ('--foo--\n'
401407
'-shoes-')
402408

403-
def test_center_text_asian_fill():
404-
"""Test fill_char with display width greater than 1"""
409+
def test_center_wide_display_text():
410+
text = '苹'
411+
fill_char = '-'
412+
width = 4
413+
aligned = cu.center_text(text, fill_char=fill_char, width=width)
414+
assert aligned == fill_char + text + fill_char
415+
416+
def test_center_text_wide_display_fill():
405417
text = 'foo'
406418
fill_char = '苹'
407419
width = 7
408420
aligned = cu.center_text(text, fill_char=fill_char, width=width)
409421
assert aligned == fill_char + text + fill_char
410422

411-
def test_center_text_asian_fill_needs_right_padding():
423+
def test_center_text_wide_display_fill_needs_right_padding():
412424
"""Test when fill_char's display width does not divide evenly into right gap"""
413425
text = 'foo'
414426
fill_char = '苹'
415427
width = 8
416428
aligned = cu.center_text(text, fill_char=fill_char, width=width)
417429
assert aligned == fill_char + text + fill_char + ' '
418430

419-
def test_center_text_asian_fill_needs_left_and_right_padding():
431+
def test_center_text_wide_display_fill_needs_left_and_right_padding():
420432
"""Test when fill_char's display width does not divide evenly into either gap"""
421433
text = 'foo'
422434
fill_char = '苹'
@@ -439,15 +451,21 @@ def test_right_text_multiline():
439451
assert aligned == ('----foo\n'
440452
'--shoes')
441453

442-
def test_right_text_asian_fill():
443-
"""Test fill_char with display width greater than 1"""
454+
def test_right_wide_display_text():
455+
text = '苹'
456+
fill_char = '-'
457+
width = 4
458+
aligned = cu.rjustify_text(text, fill_char=fill_char, width=width)
459+
assert aligned == fill_char + fill_char + text
460+
461+
def test_right_text_wide_display_fill():
444462
text = 'foo'
445463
fill_char = '苹'
446464
width = 5
447465
aligned = cu.rjustify_text(text, fill_char=fill_char, width=width)
448466
assert aligned == fill_char + text
449467

450-
def test_right_text_asian_fill_needs_padding():
468+
def test_right_text_wide_display_fill_needs_padding():
451469
"""Test when fill_char's display width does not divide evenly into gap"""
452470
text = 'foo'
453471
fill_char = '苹'

0 commit comments

Comments
 (0)