@@ -39,163 +39,158 @@ def testformat(formatstr, args, output=None):
3939 if verbose :
4040 print ('yes' )
4141
42- def testboth (formatstr , * args ):
43- testformat (str8 (formatstr ), * args )
44- testformat (formatstr , * args )
42+ testformat ("%.1d" , (1 ,), "1" )
43+ testformat ("%.*d" , (sys .maxint ,1 )) # expect overflow
44+ testformat ("%.100d" , (1 ,), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001' )
45+ testformat ("%#.117x" , (1 ,), '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001' )
46+ testformat ("%#.118x" , (1 ,), '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001' )
4547
46-
47- testboth ("%.1d" , (1 ,), "1" )
48- testboth ("%.*d" , (sys .maxint ,1 )) # expect overflow
49- testboth ("%.100d" , (1 ,), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001' )
50- testboth ("%#.117x" , (1 ,), '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001' )
51- testboth ("%#.118x" , (1 ,), '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001' )
52-
53- testboth ("%f" , (1.0 ,), "1.000000" )
48+ testformat ("%f" , (1.0 ,), "1.000000" )
5449# these are trying to test the limits of the internal magic-number-length
5550# formatting buffer, if that number changes then these tests are less
5651# effective
57- testboth ("%#.*g" , (109 , - 1.e+49 / 3. ))
58- testboth ("%#.*g" , (110 , - 1.e+49 / 3. ))
59- testboth ("%#.*g" , (110 , - 1.e+100 / 3. ))
52+ testformat ("%#.*g" , (109 , - 1.e+49 / 3. ))
53+ testformat ("%#.*g" , (110 , - 1.e+49 / 3. ))
54+ testformat ("%#.*g" , (110 , - 1.e+100 / 3. ))
6055
6156# test some ridiculously large precision, expect overflow
62- testboth ('%12.*f' , (123456 , 1.0 ))
57+ testformat ('%12.*f' , (123456 , 1.0 ))
6358
6459# check for internal overflow validation on length of precision
6560overflowrequired = 1
66- testboth ("%#.*g" , (110 , - 1.e+100 / 3. ))
67- testboth ("%#.*G" , (110 , - 1.e+100 / 3. ))
68- testboth ("%#.*f" , (110 , - 1.e+100 / 3. ))
69- testboth ("%#.*F" , (110 , - 1.e+100 / 3. ))
61+ testformat ("%#.*g" , (110 , - 1.e+100 / 3. ))
62+ testformat ("%#.*G" , (110 , - 1.e+100 / 3. ))
63+ testformat ("%#.*f" , (110 , - 1.e+100 / 3. ))
64+ testformat ("%#.*F" , (110 , - 1.e+100 / 3. ))
7065overflowrequired = 0
7166
7267# Formatting of long integers. Overflow is not ok
7368overflowok = 0
74- testboth ("%x" , 10 , "a" )
75- testboth ("%x" , 100000000000 , "174876e800" )
76- testboth ("%o" , 10 , "12" )
77- testboth ("%o" , 100000000000 , "1351035564000" )
78- testboth ("%d" , 10 , "10" )
79- testboth ("%d" , 100000000000 , "100000000000" )
69+ testformat ("%x" , 10 , "a" )
70+ testformat ("%x" , 100000000000 , "174876e800" )
71+ testformat ("%o" , 10 , "12" )
72+ testformat ("%o" , 100000000000 , "1351035564000" )
73+ testformat ("%d" , 10 , "10" )
74+ testformat ("%d" , 100000000000 , "100000000000" )
8075
8176big = 123456789012345678901234567890
82- testboth ("%d" , big , "123456789012345678901234567890" )
83- testboth ("%d" , - big , "-123456789012345678901234567890" )
84- testboth ("%5d" , - big , "-123456789012345678901234567890" )
85- testboth ("%31d" , - big , "-123456789012345678901234567890" )
86- testboth ("%32d" , - big , " -123456789012345678901234567890" )
87- testboth ("%-32d" , - big , "-123456789012345678901234567890 " )
88- testboth ("%032d" , - big , "-0123456789012345678901234567890" )
89- testboth ("%-032d" , - big , "-123456789012345678901234567890 " )
90- testboth ("%034d" , - big , "-000123456789012345678901234567890" )
91- testboth ("%034d" , big , "0000123456789012345678901234567890" )
92- testboth ("%0+34d" , big , "+000123456789012345678901234567890" )
93- testboth ("%+34d" , big , " +123456789012345678901234567890" )
94- testboth ("%34d" , big , " 123456789012345678901234567890" )
95- testboth ("%.2d" , big , "123456789012345678901234567890" )
96- testboth ("%.30d" , big , "123456789012345678901234567890" )
97- testboth ("%.31d" , big , "0123456789012345678901234567890" )
98- testboth ("%32.31d" , big , " 0123456789012345678901234567890" )
77+ testformat ("%d" , big , "123456789012345678901234567890" )
78+ testformat ("%d" , - big , "-123456789012345678901234567890" )
79+ testformat ("%5d" , - big , "-123456789012345678901234567890" )
80+ testformat ("%31d" , - big , "-123456789012345678901234567890" )
81+ testformat ("%32d" , - big , " -123456789012345678901234567890" )
82+ testformat ("%-32d" , - big , "-123456789012345678901234567890 " )
83+ testformat ("%032d" , - big , "-0123456789012345678901234567890" )
84+ testformat ("%-032d" , - big , "-123456789012345678901234567890 " )
85+ testformat ("%034d" , - big , "-000123456789012345678901234567890" )
86+ testformat ("%034d" , big , "0000123456789012345678901234567890" )
87+ testformat ("%0+34d" , big , "+000123456789012345678901234567890" )
88+ testformat ("%+34d" , big , " +123456789012345678901234567890" )
89+ testformat ("%34d" , big , " 123456789012345678901234567890" )
90+ testformat ("%.2d" , big , "123456789012345678901234567890" )
91+ testformat ("%.30d" , big , "123456789012345678901234567890" )
92+ testformat ("%.31d" , big , "0123456789012345678901234567890" )
93+ testformat ("%32.31d" , big , " 0123456789012345678901234567890" )
9994
10095big = 0x1234567890abcdef12345 # 21 hex digits
101- testboth ("%x" , big , "1234567890abcdef12345" )
102- testboth ("%x" , - big , "-1234567890abcdef12345" )
103- testboth ("%5x" , - big , "-1234567890abcdef12345" )
104- testboth ("%22x" , - big , "-1234567890abcdef12345" )
105- testboth ("%23x" , - big , " -1234567890abcdef12345" )
106- testboth ("%-23x" , - big , "-1234567890abcdef12345 " )
107- testboth ("%023x" , - big , "-01234567890abcdef12345" )
108- testboth ("%-023x" , - big , "-1234567890abcdef12345 " )
109- testboth ("%025x" , - big , "-0001234567890abcdef12345" )
110- testboth ("%025x" , big , "00001234567890abcdef12345" )
111- testboth ("%0+25x" , big , "+0001234567890abcdef12345" )
112- testboth ("%+25x" , big , " +1234567890abcdef12345" )
113- testboth ("%25x" , big , " 1234567890abcdef12345" )
114- testboth ("%.2x" , big , "1234567890abcdef12345" )
115- testboth ("%.21x" , big , "1234567890abcdef12345" )
116- testboth ("%.22x" , big , "01234567890abcdef12345" )
117- testboth ("%23.22x" , big , " 01234567890abcdef12345" )
118- testboth ("%-23.22x" , big , "01234567890abcdef12345 " )
119- testboth ("%X" , big , "1234567890ABCDEF12345" )
120- testboth ("%#X" , big , "0X1234567890ABCDEF12345" )
121- testboth ("%#x" , big , "0x1234567890abcdef12345" )
122- testboth ("%#x" , - big , "-0x1234567890abcdef12345" )
123- testboth ("%#.23x" , - big , "-0x001234567890abcdef12345" )
124- testboth ("%#+.23x" , big , "+0x001234567890abcdef12345" )
125- testboth ("%# .23x" , big , " 0x001234567890abcdef12345" )
126- testboth ("%#+.23X" , big , "+0X001234567890ABCDEF12345" )
127- testboth ("%#-+.23X" , big , "+0X001234567890ABCDEF12345" )
128- testboth ("%#-+26.23X" , big , "+0X001234567890ABCDEF12345" )
129- testboth ("%#-+27.23X" , big , "+0X001234567890ABCDEF12345 " )
130- testboth ("%#+27.23X" , big , " +0X001234567890ABCDEF12345" )
96+ testformat ("%x" , big , "1234567890abcdef12345" )
97+ testformat ("%x" , - big , "-1234567890abcdef12345" )
98+ testformat ("%5x" , - big , "-1234567890abcdef12345" )
99+ testformat ("%22x" , - big , "-1234567890abcdef12345" )
100+ testformat ("%23x" , - big , " -1234567890abcdef12345" )
101+ testformat ("%-23x" , - big , "-1234567890abcdef12345 " )
102+ testformat ("%023x" , - big , "-01234567890abcdef12345" )
103+ testformat ("%-023x" , - big , "-1234567890abcdef12345 " )
104+ testformat ("%025x" , - big , "-0001234567890abcdef12345" )
105+ testformat ("%025x" , big , "00001234567890abcdef12345" )
106+ testformat ("%0+25x" , big , "+0001234567890abcdef12345" )
107+ testformat ("%+25x" , big , " +1234567890abcdef12345" )
108+ testformat ("%25x" , big , " 1234567890abcdef12345" )
109+ testformat ("%.2x" , big , "1234567890abcdef12345" )
110+ testformat ("%.21x" , big , "1234567890abcdef12345" )
111+ testformat ("%.22x" , big , "01234567890abcdef12345" )
112+ testformat ("%23.22x" , big , " 01234567890abcdef12345" )
113+ testformat ("%-23.22x" , big , "01234567890abcdef12345 " )
114+ testformat ("%X" , big , "1234567890ABCDEF12345" )
115+ testformat ("%#X" , big , "0X1234567890ABCDEF12345" )
116+ testformat ("%#x" , big , "0x1234567890abcdef12345" )
117+ testformat ("%#x" , - big , "-0x1234567890abcdef12345" )
118+ testformat ("%#.23x" , - big , "-0x001234567890abcdef12345" )
119+ testformat ("%#+.23x" , big , "+0x001234567890abcdef12345" )
120+ testformat ("%# .23x" , big , " 0x001234567890abcdef12345" )
121+ testformat ("%#+.23X" , big , "+0X001234567890ABCDEF12345" )
122+ testformat ("%#-+.23X" , big , "+0X001234567890ABCDEF12345" )
123+ testformat ("%#-+26.23X" , big , "+0X001234567890ABCDEF12345" )
124+ testformat ("%#-+27.23X" , big , "+0X001234567890ABCDEF12345 " )
125+ testformat ("%#+27.23X" , big , " +0X001234567890ABCDEF12345" )
131126# next one gets two leading zeroes from precision, and another from the
132127# 0 flag and the width
133- testboth ("%#+027.23X" , big , "+0X0001234567890ABCDEF12345" )
128+ testformat ("%#+027.23X" , big , "+0X0001234567890ABCDEF12345" )
134129# same, except no 0 flag
135- testboth ("%#+27.23X" , big , " +0X001234567890ABCDEF12345" )
130+ testformat ("%#+27.23X" , big , " +0X001234567890ABCDEF12345" )
136131
137132big = 0o12345670123456701234567012345670 # 32 octal digits
138- testboth ("%o" , big , "12345670123456701234567012345670" )
139- testboth ("%o" , - big , "-12345670123456701234567012345670" )
140- testboth ("%5o" , - big , "-12345670123456701234567012345670" )
141- testboth ("%33o" , - big , "-12345670123456701234567012345670" )
142- testboth ("%34o" , - big , " -12345670123456701234567012345670" )
143- testboth ("%-34o" , - big , "-12345670123456701234567012345670 " )
144- testboth ("%034o" , - big , "-012345670123456701234567012345670" )
145- testboth ("%-034o" , - big , "-12345670123456701234567012345670 " )
146- testboth ("%036o" , - big , "-00012345670123456701234567012345670" )
147- testboth ("%036o" , big , "000012345670123456701234567012345670" )
148- testboth ("%0+36o" , big , "+00012345670123456701234567012345670" )
149- testboth ("%+36o" , big , " +12345670123456701234567012345670" )
150- testboth ("%36o" , big , " 12345670123456701234567012345670" )
151- testboth ("%.2o" , big , "12345670123456701234567012345670" )
152- testboth ("%.32o" , big , "12345670123456701234567012345670" )
153- testboth ("%.33o" , big , "012345670123456701234567012345670" )
154- testboth ("%34.33o" , big , " 012345670123456701234567012345670" )
155- testboth ("%-34.33o" , big , "012345670123456701234567012345670 " )
156- testboth ("%o" , big , "12345670123456701234567012345670" )
157- testboth ("%#o" , big , "0o12345670123456701234567012345670" )
158- testboth ("%#o" , - big , "-0o12345670123456701234567012345670" )
159- testboth ("%#.34o" , - big , "-0o0012345670123456701234567012345670" )
160- testboth ("%#+.34o" , big , "+0o0012345670123456701234567012345670" )
161- testboth ("%# .34o" , big , " 0o0012345670123456701234567012345670" )
162- testboth ("%#-+.34o" , big , "+0o0012345670123456701234567012345670" )
163- testboth ("%#-+39.34o" , big , "+0o0012345670123456701234567012345670 " )
164- testboth ("%#+39.34o" , big , " +0o0012345670123456701234567012345670" )
133+ testformat ("%o" , big , "12345670123456701234567012345670" )
134+ testformat ("%o" , - big , "-12345670123456701234567012345670" )
135+ testformat ("%5o" , - big , "-12345670123456701234567012345670" )
136+ testformat ("%33o" , - big , "-12345670123456701234567012345670" )
137+ testformat ("%34o" , - big , " -12345670123456701234567012345670" )
138+ testformat ("%-34o" , - big , "-12345670123456701234567012345670 " )
139+ testformat ("%034o" , - big , "-012345670123456701234567012345670" )
140+ testformat ("%-034o" , - big , "-12345670123456701234567012345670 " )
141+ testformat ("%036o" , - big , "-00012345670123456701234567012345670" )
142+ testformat ("%036o" , big , "000012345670123456701234567012345670" )
143+ testformat ("%0+36o" , big , "+00012345670123456701234567012345670" )
144+ testformat ("%+36o" , big , " +12345670123456701234567012345670" )
145+ testformat ("%36o" , big , " 12345670123456701234567012345670" )
146+ testformat ("%.2o" , big , "12345670123456701234567012345670" )
147+ testformat ("%.32o" , big , "12345670123456701234567012345670" )
148+ testformat ("%.33o" , big , "012345670123456701234567012345670" )
149+ testformat ("%34.33o" , big , " 012345670123456701234567012345670" )
150+ testformat ("%-34.33o" , big , "012345670123456701234567012345670 " )
151+ testformat ("%o" , big , "12345670123456701234567012345670" )
152+ testformat ("%#o" , big , "0o12345670123456701234567012345670" )
153+ testformat ("%#o" , - big , "-0o12345670123456701234567012345670" )
154+ testformat ("%#.34o" , - big , "-0o0012345670123456701234567012345670" )
155+ testformat ("%#+.34o" , big , "+0o0012345670123456701234567012345670" )
156+ testformat ("%# .34o" , big , " 0o0012345670123456701234567012345670" )
157+ testformat ("%#-+.34o" , big , "+0o0012345670123456701234567012345670" )
158+ testformat ("%#-+39.34o" , big , "+0o0012345670123456701234567012345670 " )
159+ testformat ("%#+39.34o" , big , " +0o0012345670123456701234567012345670" )
165160# next one gets one leading zero from precision
166- testboth ("%.33o" , big , "012345670123456701234567012345670" )
161+ testformat ("%.33o" , big , "012345670123456701234567012345670" )
167162# one leading zero from precision
168- testboth ("%#.33o" , big , "0o012345670123456701234567012345670" )
163+ testformat ("%#.33o" , big , "0o012345670123456701234567012345670" )
169164# leading zero vanishes
170- testboth ("%#.32o" , big , "0o12345670123456701234567012345670" )
165+ testformat ("%#.32o" , big , "0o12345670123456701234567012345670" )
171166# one leading zero from precision, and another from '0' flag & width
172- testboth ("%034.33o" , big , "0012345670123456701234567012345670" )
167+ testformat ("%034.33o" , big , "0012345670123456701234567012345670" )
173168# max width includes base marker; padding zeroes come after marker
174- testboth ("%0#38.33o" , big , "0o000012345670123456701234567012345670" )
169+ testformat ("%0#38.33o" , big , "0o000012345670123456701234567012345670" )
175170# padding spaces come before marker
176- testboth ("%#36.33o" , big , " 0o012345670123456701234567012345670" )
171+ testformat ("%#36.33o" , big , " 0o012345670123456701234567012345670" )
177172
178173# Some small ints, in both Python int and long flavors).
179- testboth ("%d" , 42 , "42" )
180- testboth ("%d" , - 42 , "-42" )
181- testboth ("%#x" , 1 , "0x1" )
182- testboth ("%#X" , 1 , "0X1" )
183- testboth ("%#o" , 1 , "0o1" )
184- testboth ("%#o" , 1 , "0o1" )
185- testboth ("%#o" , 0 , "0o0" )
186- testboth ("%#o" , 0 , "0o0" )
187- testboth ("%o" , 0 , "0" )
188- testboth ("%d" , 0 , "0" )
189- testboth ("%#x" , 0 , "0x0" )
190- testboth ("%#X" , 0 , "0X0" )
191-
192- testboth ("%x" , 0x42 , "42" )
193- testboth ("%x" , - 0x42 , "-42" )
194-
195- testboth ("%o" , 0o42 , "42" )
196- testboth ("%o" , - 0o42 , "-42" )
197- testboth ("%o" , 0o42 , "42" )
198- testboth ("%o" , - 0o42 , "-42" )
174+ testformat ("%d" , 42 , "42" )
175+ testformat ("%d" , - 42 , "-42" )
176+ testformat ("%#x" , 1 , "0x1" )
177+ testformat ("%#X" , 1 , "0X1" )
178+ testformat ("%#o" , 1 , "0o1" )
179+ testformat ("%#o" , 1 , "0o1" )
180+ testformat ("%#o" , 0 , "0o0" )
181+ testformat ("%#o" , 0 , "0o0" )
182+ testformat ("%o" , 0 , "0" )
183+ testformat ("%d" , 0 , "0" )
184+ testformat ("%#x" , 0 , "0x0" )
185+ testformat ("%#X" , 0 , "0X0" )
186+
187+ testformat ("%x" , 0x42 , "42" )
188+ testformat ("%x" , - 0x42 , "-42" )
189+
190+ testformat ("%o" , 0o42 , "42" )
191+ testformat ("%o" , - 0o42 , "-42" )
192+ testformat ("%o" , 0o42 , "42" )
193+ testformat ("%o" , - 0o42 , "-42" )
199194
200195# Test exception for unknown format characters
201196if verbose :
0 commit comments