File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ use std::os;
19
19
use std:: rand:: RngUtil ;
20
20
use std:: rand;
21
21
use std:: result;
22
+ use std:: str;
22
23
use std:: uint;
23
24
use std:: util;
24
25
use std:: vec;
@@ -36,6 +37,8 @@ fn main() {
36
37
bench ! ( vec_plus) ;
37
38
bench ! ( vec_append) ;
38
39
bench ! ( vec_push_all) ;
40
+ bench ! ( is_utf8_ascii) ;
41
+ bench ! ( is_utf8_multibyte) ;
39
42
}
40
43
41
44
fn maybe_run_test ( argv : & [ ~str ] , name : ~str , test : & fn ( ) ) {
@@ -127,3 +130,24 @@ fn vec_push_all() {
127
130
}
128
131
}
129
132
}
133
+
134
+ fn is_utf8_ascii ( ) {
135
+ let mut v : ~[ u8 ] = ~[ ] ;
136
+ for uint:: range( 0 , 20000 ) |_| {
137
+ v. push ( 'b' as u8 ) ;
138
+ if !str:: is_utf8 ( v) {
139
+ fail ! ( "is_utf8 failed" ) ;
140
+ }
141
+ }
142
+ }
143
+
144
+ fn is_utf8_multibyte ( ) {
145
+ let s = "b¢€𤭢" ;
146
+ let mut v : ~[ u8 ] = ~[ ] ;
147
+ for uint:: range( 0 , 5000 ) |_| {
148
+ v. push_all ( s. as_bytes ( ) ) ;
149
+ if !str:: is_utf8 ( v) {
150
+ fail ! ( "is_utf8 failed" ) ;
151
+ }
152
+ }
153
+ }
You can’t perform that action at this time.
0 commit comments