@@ -1903,6 +1903,39 @@ def test_recover_error(self):
1903
1903
1904
1904
self .assertEqual (writer .finish (), 'Hello World.' )
1905
1905
1906
+ def test_unicode_equal (self ):
1907
+ unicode_equal = _testlimitedcapi .unicode_equal
1908
+
1909
+ def copy (text ):
1910
+ return text .encode ().decode ()
1911
+
1912
+ self .assertTrue (unicode_equal ("" , "" ))
1913
+ self .assertTrue (unicode_equal ("abc" , "abc" ))
1914
+ self .assertTrue (unicode_equal ("abc" , copy ("abc" )))
1915
+ self .assertTrue (unicode_equal ("\u20ac " , copy ("\u20ac " )))
1916
+ self .assertTrue (unicode_equal ("\U0010ffff " , copy ("\U0010ffff " )))
1917
+
1918
+ self .assertFalse (unicode_equal ("abc" , "abcd" ))
1919
+ self .assertFalse (unicode_equal ("\u20ac " , "\u20ad " ))
1920
+ self .assertFalse (unicode_equal ("\U0010ffff " , "\U0010fffe " ))
1921
+
1922
+ # str subclass
1923
+ self .assertTrue (unicode_equal ("abc" , Str ("abc" )))
1924
+ self .assertTrue (unicode_equal (Str ("abc" ), "abc" ))
1925
+ self .assertFalse (unicode_equal ("abc" , Str ("abcd" )))
1926
+ self .assertFalse (unicode_equal (Str ("abc" ), "abcd" ))
1927
+
1928
+ # invalid type
1929
+ for invalid_type in (b'bytes' , 123 , ("tuple" ,)):
1930
+ with self .subTest (invalid_type = invalid_type ):
1931
+ with self .assertRaises (TypeError ):
1932
+ unicode_equal ("abc" , invalid_type )
1933
+ with self .assertRaises (TypeError ):
1934
+ unicode_equal (invalid_type , "abc" )
1935
+
1936
+ # CRASHES unicode_equal("abc", NULL)
1937
+ # CRASHES unicode_equal(NULL, "abc")
1938
+
1906
1939
1907
1940
if __name__ == "__main__" :
1908
1941
unittest .main ()
0 commit comments