@@ -16,115 +16,115 @@ fn test_format_int() {
16
16
// Formatting integers should select the right implementation based off
17
17
// the type of the argument. Also, hex/octal/binary should be defined
18
18
// for integers, but they shouldn't emit the negative sign.
19
- assert ! ( format!( "{}" , 1 i ) == "1" ) ;
19
+ assert ! ( format!( "{}" , 1 is ) == "1" ) ;
20
20
assert ! ( format!( "{}" , 1i8 ) == "1" ) ;
21
21
assert ! ( format!( "{}" , 1i16 ) == "1" ) ;
22
22
assert ! ( format!( "{}" , 1i32 ) == "1" ) ;
23
23
assert ! ( format!( "{}" , 1i64 ) == "1" ) ;
24
- assert ! ( format!( "{}" , -1 i ) == "-1" ) ;
24
+ assert ! ( format!( "{}" , -1 is ) == "-1" ) ;
25
25
assert ! ( format!( "{}" , -1i8 ) == "-1" ) ;
26
26
assert ! ( format!( "{}" , -1i16 ) == "-1" ) ;
27
27
assert ! ( format!( "{}" , -1i32 ) == "-1" ) ;
28
28
assert ! ( format!( "{}" , -1i64 ) == "-1" ) ;
29
- assert ! ( format!( "{:?}" , 1 i ) == "1" ) ;
29
+ assert ! ( format!( "{:?}" , 1 is ) == "1" ) ;
30
30
assert ! ( format!( "{:?}" , 1i8 ) == "1" ) ;
31
31
assert ! ( format!( "{:?}" , 1i16 ) == "1" ) ;
32
32
assert ! ( format!( "{:?}" , 1i32 ) == "1" ) ;
33
33
assert ! ( format!( "{:?}" , 1i64 ) == "1" ) ;
34
- assert ! ( format!( "{:b}" , 1 i ) == "1" ) ;
34
+ assert ! ( format!( "{:b}" , 1 is ) == "1" ) ;
35
35
assert ! ( format!( "{:b}" , 1i8 ) == "1" ) ;
36
36
assert ! ( format!( "{:b}" , 1i16 ) == "1" ) ;
37
37
assert ! ( format!( "{:b}" , 1i32 ) == "1" ) ;
38
38
assert ! ( format!( "{:b}" , 1i64 ) == "1" ) ;
39
- assert ! ( format!( "{:x}" , 1 i ) == "1" ) ;
39
+ assert ! ( format!( "{:x}" , 1 is ) == "1" ) ;
40
40
assert ! ( format!( "{:x}" , 1i8 ) == "1" ) ;
41
41
assert ! ( format!( "{:x}" , 1i16 ) == "1" ) ;
42
42
assert ! ( format!( "{:x}" , 1i32 ) == "1" ) ;
43
43
assert ! ( format!( "{:x}" , 1i64 ) == "1" ) ;
44
- assert ! ( format!( "{:X}" , 1 i ) == "1" ) ;
44
+ assert ! ( format!( "{:X}" , 1 is ) == "1" ) ;
45
45
assert ! ( format!( "{:X}" , 1i8 ) == "1" ) ;
46
46
assert ! ( format!( "{:X}" , 1i16 ) == "1" ) ;
47
47
assert ! ( format!( "{:X}" , 1i32 ) == "1" ) ;
48
48
assert ! ( format!( "{:X}" , 1i64 ) == "1" ) ;
49
- assert ! ( format!( "{:o}" , 1 i ) == "1" ) ;
49
+ assert ! ( format!( "{:o}" , 1 is ) == "1" ) ;
50
50
assert ! ( format!( "{:o}" , 1i8 ) == "1" ) ;
51
51
assert ! ( format!( "{:o}" , 1i16 ) == "1" ) ;
52
52
assert ! ( format!( "{:o}" , 1i32 ) == "1" ) ;
53
53
assert ! ( format!( "{:o}" , 1i64 ) == "1" ) ;
54
54
55
- assert ! ( format!( "{}" , 1 u ) == "1" ) ;
55
+ assert ! ( format!( "{}" , 1 us ) == "1" ) ;
56
56
assert ! ( format!( "{}" , 1u8 ) == "1" ) ;
57
57
assert ! ( format!( "{}" , 1u16 ) == "1" ) ;
58
58
assert ! ( format!( "{}" , 1u32 ) == "1" ) ;
59
59
assert ! ( format!( "{}" , 1u64 ) == "1" ) ;
60
- assert ! ( format!( "{:?}" , 1 u ) == "1" ) ;
60
+ assert ! ( format!( "{:?}" , 1 us ) == "1" ) ;
61
61
assert ! ( format!( "{:?}" , 1u8 ) == "1" ) ;
62
62
assert ! ( format!( "{:?}" , 1u16 ) == "1" ) ;
63
63
assert ! ( format!( "{:?}" , 1u32 ) == "1" ) ;
64
64
assert ! ( format!( "{:?}" , 1u64 ) == "1" ) ;
65
- assert ! ( format!( "{:b}" , 1 u ) == "1" ) ;
65
+ assert ! ( format!( "{:b}" , 1 us ) == "1" ) ;
66
66
assert ! ( format!( "{:b}" , 1u8 ) == "1" ) ;
67
67
assert ! ( format!( "{:b}" , 1u16 ) == "1" ) ;
68
68
assert ! ( format!( "{:b}" , 1u32 ) == "1" ) ;
69
69
assert ! ( format!( "{:b}" , 1u64 ) == "1" ) ;
70
- assert ! ( format!( "{:x}" , 1 u ) == "1" ) ;
70
+ assert ! ( format!( "{:x}" , 1 us ) == "1" ) ;
71
71
assert ! ( format!( "{:x}" , 1u8 ) == "1" ) ;
72
72
assert ! ( format!( "{:x}" , 1u16 ) == "1" ) ;
73
73
assert ! ( format!( "{:x}" , 1u32 ) == "1" ) ;
74
74
assert ! ( format!( "{:x}" , 1u64 ) == "1" ) ;
75
- assert ! ( format!( "{:X}" , 1 u ) == "1" ) ;
75
+ assert ! ( format!( "{:X}" , 1 us ) == "1" ) ;
76
76
assert ! ( format!( "{:X}" , 1u8 ) == "1" ) ;
77
77
assert ! ( format!( "{:X}" , 1u16 ) == "1" ) ;
78
78
assert ! ( format!( "{:X}" , 1u32 ) == "1" ) ;
79
79
assert ! ( format!( "{:X}" , 1u64 ) == "1" ) ;
80
- assert ! ( format!( "{:o}" , 1 u ) == "1" ) ;
80
+ assert ! ( format!( "{:o}" , 1 us ) == "1" ) ;
81
81
assert ! ( format!( "{:o}" , 1u8 ) == "1" ) ;
82
82
assert ! ( format!( "{:o}" , 1u16 ) == "1" ) ;
83
83
assert ! ( format!( "{:o}" , 1u32 ) == "1" ) ;
84
84
assert ! ( format!( "{:o}" , 1u64 ) == "1" ) ;
85
85
86
86
// 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" ) ;
92
92
}
93
93
94
94
#[ test]
95
95
fn 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" ) ;
109
109
}
110
110
111
111
#[ test]
112
112
fn 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" ) ;
128
128
assert ! ( format!( "{:x}" , -1u8 ) == "ff" ) ;
129
129
assert ! ( format!( "{:X}" , -1u8 ) == "FF" ) ;
130
130
assert ! ( format!( "{:b}" , -1u8 ) == "11111111" ) ;
@@ -137,12 +137,12 @@ fn test_format_int_flags() {
137
137
138
138
#[ test]
139
139
fn 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" ) ;
146
146
}
147
147
148
148
#[ test]
@@ -156,96 +156,98 @@ fn test_format_int_twos_complement() {
156
156
157
157
#[ test]
158
158
fn 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" ) ;
161
161
}
162
162
163
163
#[ test]
164
164
#[ should_fail]
165
165
fn test_radix_base_too_large ( ) {
166
- let _ = radix ( 55 i , 37 ) ;
166
+ let _ = radix ( 55 , 37 ) ;
167
167
}
168
168
169
- mod uint {
169
+ mod u32 {
170
170
use test:: Bencher ;
171
171
use core:: fmt:: radix;
172
172
use std:: rand:: { weak_rng, Rng } ;
173
+ use std:: io:: util:: NullWriter ;
173
174
174
175
#[ bench]
175
176
fn format_bin ( b : & mut Bencher ) {
176
177
let mut rng = weak_rng ( ) ;
177
- b. iter ( || { format ! ( "{:b}" , rng. gen :: <uint >( ) ) ; } )
178
+ b. iter ( || { write ! ( & mut NullWriter , "{:b}" , rng. gen :: <u32 >( ) ) } )
178
179
}
179
180
180
181
#[ bench]
181
182
fn format_oct ( b : & mut Bencher ) {
182
183
let mut rng = weak_rng ( ) ;
183
- b. iter ( || { format ! ( "{:o}" , rng. gen :: <uint >( ) ) ; } )
184
+ b. iter ( || { write ! ( & mut NullWriter , "{:o}" , rng. gen :: <u32 >( ) ) } )
184
185
}
185
186
186
187
#[ bench]
187
188
fn format_dec ( b : & mut Bencher ) {
188
189
let mut rng = weak_rng ( ) ;
189
- b. iter ( || { format ! ( "{}" , rng. gen :: <uint >( ) ) ; } )
190
+ b. iter ( || { write ! ( & mut NullWriter , "{}" , rng. gen :: <u32 >( ) ) } )
190
191
}
191
192
192
193
#[ bench]
193
194
fn format_hex ( b : & mut Bencher ) {
194
195
let mut rng = weak_rng ( ) ;
195
- b. iter ( || { format ! ( "{:x}" , rng. gen :: <uint >( ) ) ; } )
196
+ b. iter ( || { write ! ( & mut NullWriter , "{:x}" , rng. gen :: <u32 >( ) ) } )
196
197
}
197
198
198
199
#[ bench]
199
200
fn format_show ( b : & mut Bencher ) {
200
201
let mut rng = weak_rng ( ) ;
201
- b. iter ( || { format ! ( "{:?}" , rng. gen :: <uint >( ) ) ; } )
202
+ b. iter ( || { write ! ( & mut NullWriter , "{:?}" , rng. gen :: <u32 >( ) ) } )
202
203
}
203
204
204
205
#[ bench]
205
206
fn format_base_36 ( b : & mut Bencher ) {
206
207
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 ) ) } )
208
209
}
209
210
}
210
211
211
- mod int {
212
+ mod i32 {
212
213
use test:: Bencher ;
213
214
use core:: fmt:: radix;
214
215
use std:: rand:: { weak_rng, Rng } ;
216
+ use std:: io:: util:: NullWriter ;
215
217
216
218
#[ bench]
217
219
fn format_bin ( b : & mut Bencher ) {
218
220
let mut rng = weak_rng ( ) ;
219
- b. iter ( || { format ! ( "{:b}" , rng. gen :: <int >( ) ) ; } )
221
+ b. iter ( || { write ! ( & mut NullWriter , "{:b}" , rng. gen :: <i32 >( ) ) } )
220
222
}
221
223
222
224
#[ bench]
223
225
fn format_oct ( b : & mut Bencher ) {
224
226
let mut rng = weak_rng ( ) ;
225
- b. iter ( || { format ! ( "{:o}" , rng. gen :: <int >( ) ) ; } )
227
+ b. iter ( || { write ! ( & mut NullWriter , "{:o}" , rng. gen :: <i32 >( ) ) } )
226
228
}
227
229
228
230
#[ bench]
229
231
fn format_dec ( b : & mut Bencher ) {
230
232
let mut rng = weak_rng ( ) ;
231
- b. iter ( || { format ! ( "{}" , rng. gen :: <int >( ) ) ; } )
233
+ b. iter ( || { write ! ( & mut NullWriter , "{}" , rng. gen :: <i32 >( ) ) } )
232
234
}
233
235
234
236
#[ bench]
235
237
fn format_hex ( b : & mut Bencher ) {
236
238
let mut rng = weak_rng ( ) ;
237
- b. iter ( || { format ! ( "{:x}" , rng. gen :: <int >( ) ) ; } )
239
+ b. iter ( || { write ! ( & mut NullWriter , "{:x}" , rng. gen :: <i32 >( ) ) } )
238
240
}
239
241
240
242
#[ bench]
241
243
fn format_show ( b : & mut Bencher ) {
242
244
let mut rng = weak_rng ( ) ;
243
- b. iter ( || { format ! ( "{:?}" , rng. gen :: <int >( ) ) ; } )
245
+ b. iter ( || { write ! ( & mut NullWriter , "{:?}" , rng. gen :: <i32 >( ) ) } )
244
246
}
245
247
246
248
#[ bench]
247
249
fn format_base_36 ( b : & mut Bencher ) {
248
250
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 ) ) } )
250
252
}
251
253
}
0 commit comments