1010
1111
1212def test_ljust ():
13- assert ljust ('hi' , 5 ) == 'hi '
14- assert ljust ('' , 5 ) == ' '
15- assert ljust ('hello' , 3 ) == 'hello'
16- assert ljust ('hello' , 5 ) == 'hello'
13+ # our ljust() matches standard python ljust() for ascii
14+ assert ljust ('hi' , 5 ) == 'hi ' == str .ljust ('hi' , 5 )
15+ assert ljust ('' , 5 ) == ' ' == str .ljust ('' , 5 )
16+ assert ljust ('hello' , 3 ) == 'hello' == str .ljust ('hello' , 3 )
17+ assert ljust ('hello' , 5 ) == 'hello' == str .ljust ('hello' , 5 )
18+ assert ljust ('hi' , 5 , fillchar = '-' ) == 'hi---' == str .ljust ('hi' , 5 , '-' )
19+ # advanced capabilities
1720 assert ljust ('\x1b [31mhi\x1b [0m' , 5 ) == '\x1b [31mhi\x1b [0m '
1821 assert ljust ('\u4e2d ' , 4 ) == '\u4e2d '
19- assert ljust ('hi' , 5 , fillchar = '-' ) == 'hi---'
2022 assert ljust ('hi' , 5 , fillchar = '\u00b7 ' ) == 'hi\u00b7 \u00b7 \u00b7 '
2123 assert ljust (CJK_WORD , 8 ) == CJK_WORD + ' '
2224 assert width (ljust (CJK_WORD , 8 )) == 8
@@ -27,30 +29,35 @@ def test_ljust():
2729
2830
2931def test_rjust ():
30- assert rjust ('hi' , 5 ) == ' hi'
31- assert rjust ('' , 5 ) == ' '
32- assert rjust ('hello' , 3 ) == 'hello'
33- assert rjust ('hello' , 5 ) == 'hello'
32+ # our rjust() matches standard python rjust() for ascii
33+ assert rjust ('hi' , 5 ) == ' hi' == str .rjust ('hi' , 5 )
34+ assert rjust ('' , 5 ) == ' ' == str .rjust ('' , 5 )
35+ assert rjust ('hello' , 3 ) == 'hello' == str .rjust ('hello' , 3 )
36+ assert rjust ('hello' , 5 ) == 'hello' == str .rjust ('hello' , 5 )
37+ assert rjust ('hi' , 5 , fillchar = '-' ) == '---hi' == str .rjust ('hi' , 5 , '-' )
38+ # advanced capabilities
3439 assert rjust ('\x1b [31mhi\x1b [0m' , 5 ) == ' \x1b [31mhi\x1b [0m'
3540 assert rjust ('\u4e2d ' , 4 ) == ' \u4e2d '
36- assert rjust ('hi' , 5 , fillchar = '-' ) == '---hi'
3741 assert rjust ('hi' , 5 , fillchar = '\u00b7 ' ) == '\u00b7 \u00b7 \u00b7 hi'
3842 assert rjust (CJK_WORD , 8 ) == ' ' + CJK_WORD
3943 assert width (rjust (CAFE_COMBINING , 8 )) == 8
4044 assert width (rjust (EMOJI_FAMILY , 6 )) == 6
4145
4246
4347def test_center ():
44- assert center ('hi' , 6 ) == ' hi '
45- assert center ('hi' , 5 ) == ' hi '
46- assert center ('' , 4 ) == ' '
47- assert center ('hello' , 3 ) == 'hello'
48- assert center ('hello' , 5 ) == 'hello'
48+ # our center() matches standard python center() for ascii
49+ assert center ('hi' , 6 ) == ' hi ' == str .center ('hi' , 6 )
50+ assert center ('hi' , 5 ) == ' hi ' == str .center ('hi' , 5 )
51+ assert center ('ab' , 7 ) == ' ab ' == str .center ('ab' , 7 )
52+ assert center ('' , 4 ) == ' ' == str .center ('' , 4 )
53+ assert center ('hello' , 3 ) == 'hello' == str .center ('hello' , 3 )
54+ assert center ('hello' , 5 ) == 'hello' == str .center ('hello' , 5 )
55+ assert center ('hi' , 6 , fillchar = '-' ) == '--hi--' == str .center ('hi' , 6 , '-' )
56+ assert center ('x' , 4 ) == ' x ' == str .center ('x' , 4 )
57+ # advanced capabilities
4958 assert center ('\x1b [31mhi\x1b [0m' , 6 ) == ' \x1b [31mhi\x1b [0m '
5059 assert center ('\u4e2d ' , 6 ) == ' \u4e2d '
51- assert center ('hi' , 6 , fillchar = '-' ) == '--hi--'
5260 assert center ('hi' , 6 , fillchar = '\u00b7 ' ) == '\u00b7 \u00b7 hi\u00b7 \u00b7 '
53- assert center ('x' , 4 ) == ' x '
5461 assert width (center (CJK_WORD , 8 )) == 8
5562 assert width (center (CAFE_COMBINING , 8 )) == 8
5663 assert width (center (EMOJI_FAMILY , 6 )) == 6
0 commit comments