@@ -681,6 +681,42 @@ def test_replace_overflow(self):
681
681
self .checkraises (OverflowError , A2_16 , "replace" , "A" , A2_16 )
682
682
self .checkraises (OverflowError , A2_16 , "replace" , "AA" , A2_16 + A2_16 )
683
683
684
+ def test_removeprefix (self ):
685
+ self .checkequal ('am' , 'spam' , 'removeprefix' , 'sp' )
686
+ self .checkequal ('spamspam' , 'spamspamspam' , 'removeprefix' , 'spam' )
687
+ self .checkequal ('spam' , 'spam' , 'removeprefix' , 'python' )
688
+ self .checkequal ('spam' , 'spam' , 'removeprefix' , 'spider' )
689
+ self .checkequal ('spam' , 'spam' , 'removeprefix' , 'spam and eggs' )
690
+
691
+ self .checkequal ('' , '' , 'removeprefix' , '' )
692
+ self .checkequal ('' , '' , 'removeprefix' , 'abcde' )
693
+ self .checkequal ('abcde' , 'abcde' , 'removeprefix' , '' )
694
+ self .checkequal ('' , 'abcde' , 'removeprefix' , 'abcde' )
695
+
696
+ self .checkraises (TypeError , 'hello' , 'removeprefix' )
697
+ self .checkraises (TypeError , 'hello' , 'removeprefix' , 42 )
698
+ self .checkraises (TypeError , 'hello' , 'removeprefix' , 42 , 'h' )
699
+ self .checkraises (TypeError , 'hello' , 'removeprefix' , 'h' , 42 )
700
+ self .checkraises (TypeError , 'hello' , 'removeprefix' , ("he" , "l" ))
701
+
702
+ def test_removesuffix (self ):
703
+ self .checkequal ('sp' , 'spam' , 'removesuffix' , 'am' )
704
+ self .checkequal ('spamspam' , 'spamspamspam' , 'removesuffix' , 'spam' )
705
+ self .checkequal ('spam' , 'spam' , 'removesuffix' , 'python' )
706
+ self .checkequal ('spam' , 'spam' , 'removesuffix' , 'blam' )
707
+ self .checkequal ('spam' , 'spam' , 'removesuffix' , 'eggs and spam' )
708
+
709
+ self .checkequal ('' , '' , 'removesuffix' , '' )
710
+ self .checkequal ('' , '' , 'removesuffix' , 'abcde' )
711
+ self .checkequal ('abcde' , 'abcde' , 'removesuffix' , '' )
712
+ self .checkequal ('' , 'abcde' , 'removesuffix' , 'abcde' )
713
+
714
+ self .checkraises (TypeError , 'hello' , 'removesuffix' )
715
+ self .checkraises (TypeError , 'hello' , 'removesuffix' , 42 )
716
+ self .checkraises (TypeError , 'hello' , 'removesuffix' , 42 , 'h' )
717
+ self .checkraises (TypeError , 'hello' , 'removesuffix' , 'h' , 42 )
718
+ self .checkraises (TypeError , 'hello' , 'removesuffix' , ("lo" , "l" ))
719
+
684
720
def test_capitalize (self ):
685
721
self .checkequal (' hello ' , ' hello ' , 'capitalize' )
686
722
self .checkequal ('Hello ' , 'Hello ' ,'capitalize' )
0 commit comments