@@ -16,115 +16,115 @@ fn test_format_int() {
1616 // Formatting integers should select the right implementation based off
1717 // the type of the argument. Also, hex/octal/binary should be defined
1818 // for integers, but they shouldn't emit the negative sign.
19- assert ! ( format!( "{}" , 1 i ) == "1" ) ;
19+ assert ! ( format!( "{}" , 1 is ) == "1" ) ;
2020 assert ! ( format!( "{}" , 1i8 ) == "1" ) ;
2121 assert ! ( format!( "{}" , 1i16 ) == "1" ) ;
2222 assert ! ( format!( "{}" , 1i32 ) == "1" ) ;
2323 assert ! ( format!( "{}" , 1i64 ) == "1" ) ;
24- assert ! ( format!( "{}" , -1 i ) == "-1" ) ;
24+ assert ! ( format!( "{}" , -1 is ) == "-1" ) ;
2525 assert ! ( format!( "{}" , -1i8 ) == "-1" ) ;
2626 assert ! ( format!( "{}" , -1i16 ) == "-1" ) ;
2727 assert ! ( format!( "{}" , -1i32 ) == "-1" ) ;
2828 assert ! ( format!( "{}" , -1i64 ) == "-1" ) ;
29- assert ! ( format!( "{:?}" , 1 i ) == "1" ) ;
29+ assert ! ( format!( "{:?}" , 1 is ) == "1" ) ;
3030 assert ! ( format!( "{:?}" , 1i8 ) == "1" ) ;
3131 assert ! ( format!( "{:?}" , 1i16 ) == "1" ) ;
3232 assert ! ( format!( "{:?}" , 1i32 ) == "1" ) ;
3333 assert ! ( format!( "{:?}" , 1i64 ) == "1" ) ;
34- assert ! ( format!( "{:b}" , 1 i ) == "1" ) ;
34+ assert ! ( format!( "{:b}" , 1 is ) == "1" ) ;
3535 assert ! ( format!( "{:b}" , 1i8 ) == "1" ) ;
3636 assert ! ( format!( "{:b}" , 1i16 ) == "1" ) ;
3737 assert ! ( format!( "{:b}" , 1i32 ) == "1" ) ;
3838 assert ! ( format!( "{:b}" , 1i64 ) == "1" ) ;
39- assert ! ( format!( "{:x}" , 1 i ) == "1" ) ;
39+ assert ! ( format!( "{:x}" , 1 is ) == "1" ) ;
4040 assert ! ( format!( "{:x}" , 1i8 ) == "1" ) ;
4141 assert ! ( format!( "{:x}" , 1i16 ) == "1" ) ;
4242 assert ! ( format!( "{:x}" , 1i32 ) == "1" ) ;
4343 assert ! ( format!( "{:x}" , 1i64 ) == "1" ) ;
44- assert ! ( format!( "{:X}" , 1 i ) == "1" ) ;
44+ assert ! ( format!( "{:X}" , 1 is ) == "1" ) ;
4545 assert ! ( format!( "{:X}" , 1i8 ) == "1" ) ;
4646 assert ! ( format!( "{:X}" , 1i16 ) == "1" ) ;
4747 assert ! ( format!( "{:X}" , 1i32 ) == "1" ) ;
4848 assert ! ( format!( "{:X}" , 1i64 ) == "1" ) ;
49- assert ! ( format!( "{:o}" , 1 i ) == "1" ) ;
49+ assert ! ( format!( "{:o}" , 1 is ) == "1" ) ;
5050 assert ! ( format!( "{:o}" , 1i8 ) == "1" ) ;
5151 assert ! ( format!( "{:o}" , 1i16 ) == "1" ) ;
5252 assert ! ( format!( "{:o}" , 1i32 ) == "1" ) ;
5353 assert ! ( format!( "{:o}" , 1i64 ) == "1" ) ;
5454
55- assert ! ( format!( "{}" , 1 u ) == "1" ) ;
55+ assert ! ( format!( "{}" , 1 us ) == "1" ) ;
5656 assert ! ( format!( "{}" , 1u8 ) == "1" ) ;
5757 assert ! ( format!( "{}" , 1u16 ) == "1" ) ;
5858 assert ! ( format!( "{}" , 1u32 ) == "1" ) ;
5959 assert ! ( format!( "{}" , 1u64 ) == "1" ) ;
60- assert ! ( format!( "{:?}" , 1 u ) == "1" ) ;
60+ assert ! ( format!( "{:?}" , 1 us ) == "1" ) ;
6161 assert ! ( format!( "{:?}" , 1u8 ) == "1" ) ;
6262 assert ! ( format!( "{:?}" , 1u16 ) == "1" ) ;
6363 assert ! ( format!( "{:?}" , 1u32 ) == "1" ) ;
6464 assert ! ( format!( "{:?}" , 1u64 ) == "1" ) ;
65- assert ! ( format!( "{:b}" , 1 u ) == "1" ) ;
65+ assert ! ( format!( "{:b}" , 1 us ) == "1" ) ;
6666 assert ! ( format!( "{:b}" , 1u8 ) == "1" ) ;
6767 assert ! ( format!( "{:b}" , 1u16 ) == "1" ) ;
6868 assert ! ( format!( "{:b}" , 1u32 ) == "1" ) ;
6969 assert ! ( format!( "{:b}" , 1u64 ) == "1" ) ;
70- assert ! ( format!( "{:x}" , 1 u ) == "1" ) ;
70+ assert ! ( format!( "{:x}" , 1 us ) == "1" ) ;
7171 assert ! ( format!( "{:x}" , 1u8 ) == "1" ) ;
7272 assert ! ( format!( "{:x}" , 1u16 ) == "1" ) ;
7373 assert ! ( format!( "{:x}" , 1u32 ) == "1" ) ;
7474 assert ! ( format!( "{:x}" , 1u64 ) == "1" ) ;
75- assert ! ( format!( "{:X}" , 1 u ) == "1" ) ;
75+ assert ! ( format!( "{:X}" , 1 us ) == "1" ) ;
7676 assert ! ( format!( "{:X}" , 1u8 ) == "1" ) ;
7777 assert ! ( format!( "{:X}" , 1u16 ) == "1" ) ;
7878 assert ! ( format!( "{:X}" , 1u32 ) == "1" ) ;
7979 assert ! ( format!( "{:X}" , 1u64 ) == "1" ) ;
80- assert ! ( format!( "{:o}" , 1 u ) == "1" ) ;
80+ assert ! ( format!( "{:o}" , 1 us ) == "1" ) ;
8181 assert ! ( format!( "{:o}" , 1u8 ) == "1" ) ;
8282 assert ! ( format!( "{:o}" , 1u16 ) == "1" ) ;
8383 assert ! ( format!( "{:o}" , 1u32 ) == "1" ) ;
8484 assert ! ( format!( "{:o}" , 1u64 ) == "1" ) ;
8585
8686 // Test a larger number
87- assert ! ( format!( "{:b}" , 55 i ) == "110111" ) ;
88- assert ! ( format!( "{:o}" , 55 i ) == "67" ) ;
89- assert ! ( format!( "{}" , 55 i ) == "55" ) ;
90- assert ! ( format!( "{:x}" , 55 i ) == "37" ) ;
91- assert ! ( format!( "{:X}" , 55 i ) == "37" ) ;
87+ assert ! ( format!( "{:b}" , 55 ) == "110111" ) ;
88+ assert ! ( format!( "{:o}" , 55 ) == "67" ) ;
89+ assert ! ( format!( "{}" , 55 ) == "55" ) ;
90+ assert ! ( format!( "{:x}" , 55 ) == "37" ) ;
91+ assert ! ( format!( "{:X}" , 55 ) == "37" ) ;
9292}
9393
9494#[ test]
9595fn test_format_int_zero ( ) {
96- assert ! ( format!( "{}" , 0 i ) == "0" ) ;
97- assert ! ( format!( "{:?}" , 0 i ) == "0" ) ;
98- assert ! ( format!( "{:b}" , 0 i ) == "0" ) ;
99- assert ! ( format!( "{:o}" , 0 i ) == "0" ) ;
100- assert ! ( format!( "{:x}" , 0 i ) == "0" ) ;
101- assert ! ( format!( "{:X}" , 0 i ) == "0" ) ;
102-
103- assert ! ( format!( "{}" , 0 u ) == "0" ) ;
104- assert ! ( format!( "{:?}" , 0 u ) == "0" ) ;
105- assert ! ( format!( "{:b}" , 0 u ) == "0" ) ;
106- assert ! ( format!( "{:o}" , 0 u ) == "0" ) ;
107- assert ! ( format!( "{:x}" , 0 u ) == "0" ) ;
108- assert ! ( format!( "{:X}" , 0 u ) == "0" ) ;
96+ assert ! ( format!( "{}" , 0 ) == "0" ) ;
97+ assert ! ( format!( "{:?}" , 0 ) == "0" ) ;
98+ assert ! ( format!( "{:b}" , 0 ) == "0" ) ;
99+ assert ! ( format!( "{:o}" , 0 ) == "0" ) ;
100+ assert ! ( format!( "{:x}" , 0 ) == "0" ) ;
101+ assert ! ( format!( "{:X}" , 0 ) == "0" ) ;
102+
103+ assert ! ( format!( "{}" , 0u32 ) == "0" ) ;
104+ assert ! ( format!( "{:?}" , 0u32 ) == "0" ) ;
105+ assert ! ( format!( "{:b}" , 0u32 ) == "0" ) ;
106+ assert ! ( format!( "{:o}" , 0u32 ) == "0" ) ;
107+ assert ! ( format!( "{:x}" , 0u32 ) == "0" ) ;
108+ assert ! ( format!( "{:X}" , 0u32 ) == "0" ) ;
109109}
110110
111111#[ test]
112112fn test_format_int_flags ( ) {
113- assert ! ( format!( "{:3}" , 1 i ) == " 1" ) ;
114- assert ! ( format!( "{:>3}" , 1 i ) == " 1" ) ;
115- assert ! ( format!( "{:>+3}" , 1 i ) == " +1" ) ;
116- assert ! ( format!( "{:<3}" , 1 i ) == "1 " ) ;
117- assert ! ( format!( "{:#}" , 1 i ) == "1" ) ;
118- assert ! ( format!( "{:#x}" , 10 i ) == "0xa" ) ;
119- assert ! ( format!( "{:#X}" , 10 i ) == "0xA" ) ;
120- assert ! ( format!( "{:#5x}" , 10 i ) == " 0xa" ) ;
121- assert ! ( format!( "{:#o}" , 10 i ) == "0o12" ) ;
122- assert ! ( format!( "{:08x}" , 10 i ) == "0000000a" ) ;
123- assert ! ( format!( "{:8x}" , 10 i ) == " a" ) ;
124- assert ! ( format!( "{:<8x}" , 10 i ) == "a " ) ;
125- assert ! ( format!( "{:>8x}" , 10 i ) == " a" ) ;
126- assert ! ( format!( "{:#08x}" , 10 i ) == "0x00000a" ) ;
127- assert ! ( format!( "{:08}" , -10 i ) == "-0000010" ) ;
113+ assert ! ( format!( "{:3}" , 1 ) == " 1" ) ;
114+ assert ! ( format!( "{:>3}" , 1 ) == " 1" ) ;
115+ assert ! ( format!( "{:>+3}" , 1 ) == " +1" ) ;
116+ assert ! ( format!( "{:<3}" , 1 ) == "1 " ) ;
117+ assert ! ( format!( "{:#}" , 1 ) == "1" ) ;
118+ assert ! ( format!( "{:#x}" , 10 ) == "0xa" ) ;
119+ assert ! ( format!( "{:#X}" , 10 ) == "0xA" ) ;
120+ assert ! ( format!( "{:#5x}" , 10 ) == " 0xa" ) ;
121+ assert ! ( format!( "{:#o}" , 10 ) == "0o12" ) ;
122+ assert ! ( format!( "{:08x}" , 10 ) == "0000000a" ) ;
123+ assert ! ( format!( "{:8x}" , 10 ) == " a" ) ;
124+ assert ! ( format!( "{:<8x}" , 10 ) == "a " ) ;
125+ assert ! ( format!( "{:>8x}" , 10 ) == " a" ) ;
126+ assert ! ( format!( "{:#08x}" , 10 ) == "0x00000a" ) ;
127+ assert ! ( format!( "{:08}" , -10 ) == "-0000010" ) ;
128128 assert ! ( format!( "{:x}" , -1u8 ) == "ff" ) ;
129129 assert ! ( format!( "{:X}" , -1u8 ) == "FF" ) ;
130130 assert ! ( format!( "{:b}" , -1u8 ) == "11111111" ) ;
@@ -137,12 +137,12 @@ fn test_format_int_flags() {
137137
138138#[ test]
139139fn test_format_int_sign_padding ( ) {
140- assert ! ( format!( "{:+5}" , 1 i ) == " +1" ) ;
141- assert ! ( format!( "{:+5}" , -1 i ) == " -1" ) ;
142- assert ! ( format!( "{:05}" , 1 i ) == "00001" ) ;
143- assert ! ( format!( "{:05}" , -1 i ) == "-0001" ) ;
144- assert ! ( format!( "{:+05}" , 1 i ) == "+0001" ) ;
145- assert ! ( format!( "{:+05}" , -1 i ) == "-0001" ) ;
140+ assert ! ( format!( "{:+5}" , 1 ) == " +1" ) ;
141+ assert ! ( format!( "{:+5}" , -1 ) == " -1" ) ;
142+ assert ! ( format!( "{:05}" , 1 ) == "00001" ) ;
143+ assert ! ( format!( "{:05}" , -1 ) == "-0001" ) ;
144+ assert ! ( format!( "{:+05}" , 1 ) == "+0001" ) ;
145+ assert ! ( format!( "{:+05}" , -1 ) == "-0001" ) ;
146146}
147147
148148#[ test]
@@ -156,96 +156,98 @@ fn test_format_int_twos_complement() {
156156
157157#[ test]
158158fn test_format_radix ( ) {
159- assert ! ( format!( "{:04}" , radix( 3 i , 2 ) ) == "0011" ) ;
160- assert ! ( format!( "{}" , radix( 55 i , 36 ) ) == "1j" ) ;
159+ assert ! ( format!( "{:04}" , radix( 3 , 2 ) ) == "0011" ) ;
160+ assert ! ( format!( "{}" , radix( 55 , 36 ) ) == "1j" ) ;
161161}
162162
163163#[ test]
164164#[ should_fail]
165165fn test_radix_base_too_large ( ) {
166- let _ = radix ( 55 i , 37 ) ;
166+ let _ = radix ( 55 , 37 ) ;
167167}
168168
169- mod uint {
169+ mod u32 {
170170 use test:: Bencher ;
171171 use core:: fmt:: radix;
172172 use std:: rand:: { weak_rng, Rng } ;
173+ use std:: io:: util:: NullWriter ;
173174
174175 #[ bench]
175176 fn format_bin ( b : & mut Bencher ) {
176177 let mut rng = weak_rng ( ) ;
177- b. iter ( || { format ! ( "{:b}" , rng. gen :: <uint >( ) ) ; } )
178+ b. iter ( || { write ! ( & mut NullWriter , "{:b}" , rng. gen :: <u32 >( ) ) } )
178179 }
179180
180181 #[ bench]
181182 fn format_oct ( b : & mut Bencher ) {
182183 let mut rng = weak_rng ( ) ;
183- b. iter ( || { format ! ( "{:o}" , rng. gen :: <uint >( ) ) ; } )
184+ b. iter ( || { write ! ( & mut NullWriter , "{:o}" , rng. gen :: <u32 >( ) ) } )
184185 }
185186
186187 #[ bench]
187188 fn format_dec ( b : & mut Bencher ) {
188189 let mut rng = weak_rng ( ) ;
189- b. iter ( || { format ! ( "{}" , rng. gen :: <uint >( ) ) ; } )
190+ b. iter ( || { write ! ( & mut NullWriter , "{}" , rng. gen :: <u32 >( ) ) } )
190191 }
191192
192193 #[ bench]
193194 fn format_hex ( b : & mut Bencher ) {
194195 let mut rng = weak_rng ( ) ;
195- b. iter ( || { format ! ( "{:x}" , rng. gen :: <uint >( ) ) ; } )
196+ b. iter ( || { write ! ( & mut NullWriter , "{:x}" , rng. gen :: <u32 >( ) ) } )
196197 }
197198
198199 #[ bench]
199200 fn format_show ( b : & mut Bencher ) {
200201 let mut rng = weak_rng ( ) ;
201- b. iter ( || { format ! ( "{:?}" , rng. gen :: <uint >( ) ) ; } )
202+ b. iter ( || { write ! ( & mut NullWriter , "{:?}" , rng. gen :: <u32 >( ) ) } )
202203 }
203204
204205 #[ bench]
205206 fn format_base_36 ( b : & mut Bencher ) {
206207 let mut rng = weak_rng ( ) ;
207- b. iter ( || { format ! ( "{}" , radix( rng. gen :: <uint >( ) , 36 ) ) ; } )
208+ b. iter ( || { write ! ( & mut NullWriter , "{}" , radix( rng. gen :: <u32 >( ) , 36 ) ) } )
208209 }
209210}
210211
211- mod int {
212+ mod i32 {
212213 use test:: Bencher ;
213214 use core:: fmt:: radix;
214215 use std:: rand:: { weak_rng, Rng } ;
216+ use std:: io:: util:: NullWriter ;
215217
216218 #[ bench]
217219 fn format_bin ( b : & mut Bencher ) {
218220 let mut rng = weak_rng ( ) ;
219- b. iter ( || { format ! ( "{:b}" , rng. gen :: <int >( ) ) ; } )
221+ b. iter ( || { write ! ( & mut NullWriter , "{:b}" , rng. gen :: <i32 >( ) ) } )
220222 }
221223
222224 #[ bench]
223225 fn format_oct ( b : & mut Bencher ) {
224226 let mut rng = weak_rng ( ) ;
225- b. iter ( || { format ! ( "{:o}" , rng. gen :: <int >( ) ) ; } )
227+ b. iter ( || { write ! ( & mut NullWriter , "{:o}" , rng. gen :: <i32 >( ) ) } )
226228 }
227229
228230 #[ bench]
229231 fn format_dec ( b : & mut Bencher ) {
230232 let mut rng = weak_rng ( ) ;
231- b. iter ( || { format ! ( "{}" , rng. gen :: <int >( ) ) ; } )
233+ b. iter ( || { write ! ( & mut NullWriter , "{}" , rng. gen :: <i32 >( ) ) } )
232234 }
233235
234236 #[ bench]
235237 fn format_hex ( b : & mut Bencher ) {
236238 let mut rng = weak_rng ( ) ;
237- b. iter ( || { format ! ( "{:x}" , rng. gen :: <int >( ) ) ; } )
239+ b. iter ( || { write ! ( & mut NullWriter , "{:x}" , rng. gen :: <i32 >( ) ) } )
238240 }
239241
240242 #[ bench]
241243 fn format_show ( b : & mut Bencher ) {
242244 let mut rng = weak_rng ( ) ;
243- b. iter ( || { format ! ( "{:?}" , rng. gen :: <int >( ) ) ; } )
245+ b. iter ( || { write ! ( & mut NullWriter , "{:?}" , rng. gen :: <i32 >( ) ) } )
244246 }
245247
246248 #[ bench]
247249 fn format_base_36 ( b : & mut Bencher ) {
248250 let mut rng = weak_rng ( ) ;
249- b. iter ( || { format ! ( "{}" , radix( rng. gen :: <int >( ) , 36 ) ) ; } )
251+ b. iter ( || { write ! ( & mut NullWriter , "{}" , radix( rng. gen :: <i32 >( ) , 36 ) ) } )
250252 }
251253}
0 commit comments