File tree 2 files changed +21
-2
lines changed 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 57
57
assert s .lstrip ('^*' ) == 'RustPython*^'
58
58
assert s .rstrip ('^*' ) == '^*RustPython'
59
59
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
+
60
71
c = 'hallo'
61
72
assert c .capitalize () == 'Hallo'
62
73
assert c .center (11 , '-' ) == '---hallo---'
Original file line number Diff line number Diff line change @@ -740,7 +740,11 @@ impl PyString {
740
740
) -> PyResult < String > {
741
741
let value = & self . value ;
742
742
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
+ }
744
748
}
745
749
746
750
#[ pymethod]
@@ -752,7 +756,11 @@ impl PyString {
752
756
) -> PyResult < String > {
753
757
let value = & self . value ;
754
758
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
+ }
756
764
}
757
765
758
766
#[ pymethod]
You can’t perform that action at this time.
0 commit comments