File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5757assert s .lstrip ('^*' ) == 'RustPython*^'
5858assert s .rstrip ('^*' ) == '^*RustPython'
5959
60+ s = 'RustPython'
61+ assert s .ljust (8 ) == 'RustPython'
62+ assert s .rjust (8 ) == 'RustPython'
63+ assert s .ljust (12 ) == 'RustPython '
64+ assert s .rjust (12 ) == ' RustPython'
65+ assert s .ljust (12 , '_' ) == 'RustPython__'
66+ assert s .rjust (12 , '_' ) == '__RustPython'
67+ # The fill character must be exactly one character long
68+ assert_raises (TypeError , lambda : s .ljust (12 , '__' ))
69+ assert_raises (TypeError , lambda : s .rjust (12 , '__' ))
70+
6071c = 'hallo'
6172assert c .capitalize () == 'Hallo'
6273assert c .center (11 , '-' ) == '---hallo---'
Original file line number Diff line number Diff line change @@ -740,7 +740,11 @@ impl PyString {
740740 ) -> PyResult < String > {
741741 let value = & self . value ;
742742 let rep_char = Self :: get_fill_char ( & rep, vm) ?;
743- Ok ( format ! ( "{}{}" , value, rep_char. repeat( len) ) )
743+ if len <= value. len ( ) {
744+ Ok ( value. to_string ( ) )
745+ } else {
746+ Ok ( format ! ( "{}{}" , value, rep_char. repeat( len - value. len( ) ) ) )
747+ }
744748 }
745749
746750 #[ pymethod]
@@ -752,7 +756,11 @@ impl PyString {
752756 ) -> PyResult < String > {
753757 let value = & self . value ;
754758 let rep_char = Self :: get_fill_char ( & rep, vm) ?;
755- Ok ( format ! ( "{}{}" , rep_char. repeat( len) , value) )
759+ if len <= value. len ( ) {
760+ Ok ( value. to_string ( ) )
761+ } else {
762+ Ok ( format ! ( "{}{}" , rep_char. repeat( len - value. len( ) ) , value) )
763+ }
756764 }
757765
758766 #[ pymethod]
You can’t perform that action at this time.
0 commit comments