@@ -681,6 +681,45 @@ 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
+
685
+ # Python 3.9
686
+ def test_removeprefix (self ):
687
+ self .checkequal ('am' , 'spam' , 'removeprefix' , 'sp' )
688
+ self .checkequal ('spamspam' , 'spamspamspam' , 'removeprefix' , 'spam' )
689
+ self .checkequal ('spam' , 'spam' , 'removeprefix' , 'python' )
690
+ self .checkequal ('spam' , 'spam' , 'removeprefix' , 'spider' )
691
+ self .checkequal ('spam' , 'spam' , 'removeprefix' , 'spam and eggs' )
692
+
693
+ self .checkequal ('' , '' , 'removeprefix' , '' )
694
+ self .checkequal ('' , '' , 'removeprefix' , 'abcde' )
695
+ self .checkequal ('abcde' , 'abcde' , 'removeprefix' , '' )
696
+ self .checkequal ('' , 'abcde' , 'removeprefix' , 'abcde' )
697
+
698
+ self .checkraises (TypeError , 'hello' , 'removeprefix' )
699
+ self .checkraises (TypeError , 'hello' , 'removeprefix' , 42 )
700
+ self .checkraises (TypeError , 'hello' , 'removeprefix' , 42 , 'h' )
701
+ self .checkraises (TypeError , 'hello' , 'removeprefix' , 'h' , 42 )
702
+ self .checkraises (TypeError , 'hello' , 'removeprefix' , ("he" , "l" ))
703
+
704
+ # Python 3.9
705
+ def test_removesuffix (self ):
706
+ self .checkequal ('sp' , 'spam' , 'removesuffix' , 'am' )
707
+ self .checkequal ('spamspam' , 'spamspamspam' , 'removesuffix' , 'spam' )
708
+ self .checkequal ('spam' , 'spam' , 'removesuffix' , 'python' )
709
+ self .checkequal ('spam' , 'spam' , 'removesuffix' , 'blam' )
710
+ self .checkequal ('spam' , 'spam' , 'removesuffix' , 'eggs and spam' )
711
+
712
+ self .checkequal ('' , '' , 'removesuffix' , '' )
713
+ self .checkequal ('' , '' , 'removesuffix' , 'abcde' )
714
+ self .checkequal ('abcde' , 'abcde' , 'removesuffix' , '' )
715
+ self .checkequal ('' , 'abcde' , 'removesuffix' , 'abcde' )
716
+
717
+ self .checkraises (TypeError , 'hello' , 'removesuffix' )
718
+ self .checkraises (TypeError , 'hello' , 'removesuffix' , 42 )
719
+ self .checkraises (TypeError , 'hello' , 'removesuffix' , 42 , 'h' )
720
+ self .checkraises (TypeError , 'hello' , 'removesuffix' , 'h' , 42 )
721
+ self .checkraises (TypeError , 'hello' , 'removesuffix' , ("lo" , "l" ))
722
+
684
723
def test_capitalize (self ):
685
724
self .checkequal (' hello ' , ' hello ' , 'capitalize' )
686
725
self .checkequal ('Hello ' , 'Hello ' ,'capitalize' )
0 commit comments