@@ -2809,6 +2809,25 @@ def check_format(expected, format, *args):
2809
2809
check_format ('repr=abc' ,
2810
2810
b'repr=%V' , 'abc' , b'xyz' )
2811
2811
2812
+ # test %p
2813
+ # We cannot test the exact result,
2814
+ # because it returns a hex representation of a C pointer,
2815
+ # which is going to be different each time. But, we can test the format.
2816
+ p_format_regex = r'^0x[a-zA-Z0-9]{3,}$'
2817
+ p_format1 = PyUnicode_FromFormat (b'%p' , 'abc' )
2818
+ self .assertIsInstance (p_format1 , str )
2819
+ self .assertRegex (p_format1 , p_format_regex )
2820
+
2821
+ p_format2 = PyUnicode_FromFormat (b'%p %p' , '123456' , b'xyz' )
2822
+ self .assertIsInstance (p_format2 , str )
2823
+ self .assertRegex (p_format2 ,
2824
+ r'0x[a-zA-Z0-9]{3,} 0x[a-zA-Z0-9]{3,}' )
2825
+
2826
+ # Extra args are ignored:
2827
+ p_format3 = PyUnicode_FromFormat (b'%p' , '123456' , None , b'xyz' )
2828
+ self .assertIsInstance (p_format3 , str )
2829
+ self .assertRegex (p_format3 , p_format_regex )
2830
+
2812
2831
# Test string decode from parameter of %s using utf-8.
2813
2832
# b'\xe4\xba\xba\xe6\xb0\x91' is utf-8 encoded byte sequence of
2814
2833
# '\u4eba\u6c11'
0 commit comments