|
19 | 19 | //! |
20 | 20 | //! [`escape_default`]: fn.escape_default.html |
21 | 21 |
|
22 | | -#![stable(feature = "rust1", since = "1.0.0")] |
| 22 | +#![stable(feature = "core_ascii", since = "1.26.0")] |
23 | 23 |
|
24 | 24 | use fmt; |
25 | 25 | use ops::Range; |
@@ -145,357 +145,3 @@ impl fmt::Debug for EscapeDefault { |
145 | 145 | f.pad("EscapeDefault { .. }") |
146 | 146 | } |
147 | 147 | } |
148 | | - |
149 | | - |
150 | | -#[cfg(test)] |
151 | | -mod tests { |
152 | | - use char::from_u32; |
153 | | - |
154 | | - #[test] |
155 | | - fn test_is_ascii() { |
156 | | - assert!(b"".is_ascii()); |
157 | | - assert!(b"banana\0\x7F".is_ascii()); |
158 | | - assert!(b"banana\0\x7F".iter().all(|b| b.is_ascii())); |
159 | | - assert!(!b"Vi\xe1\xbb\x87t Nam".is_ascii()); |
160 | | - assert!(!b"Vi\xe1\xbb\x87t Nam".iter().all(|b| b.is_ascii())); |
161 | | - assert!(!b"\xe1\xbb\x87".iter().any(|b| b.is_ascii())); |
162 | | - |
163 | | - assert!("".is_ascii()); |
164 | | - assert!("banana\0\u{7F}".is_ascii()); |
165 | | - assert!("banana\0\u{7F}".chars().all(|c| c.is_ascii())); |
166 | | - assert!(!"ประเทศไทย中华Việt Nam".chars().all(|c| c.is_ascii())); |
167 | | - assert!(!"ประเทศไทย中华ệ ".chars().any(|c| c.is_ascii())); |
168 | | - } |
169 | | - |
170 | | - #[test] |
171 | | - fn test_to_ascii_uppercase() { |
172 | | - assert_eq!("url()URL()uRl()ürl".to_ascii_uppercase(), "URL()URL()URL()üRL"); |
173 | | - assert_eq!("hıKß".to_ascii_uppercase(), "HıKß"); |
174 | | - |
175 | | - for i in 0..501 { |
176 | | - let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 } |
177 | | - else { i }; |
178 | | - assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_uppercase(), |
179 | | - (from_u32(upper).unwrap()).to_string()); |
180 | | - } |
181 | | - } |
182 | | - |
183 | | - #[test] |
184 | | - fn test_to_ascii_lowercase() { |
185 | | - assert_eq!("url()URL()uRl()Ürl".to_ascii_lowercase(), "url()url()url()Ürl"); |
186 | | - // Dotted capital I, Kelvin sign, Sharp S. |
187 | | - assert_eq!("HİKß".to_ascii_lowercase(), "hİKß"); |
188 | | - |
189 | | - for i in 0..501 { |
190 | | - let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } |
191 | | - else { i }; |
192 | | - assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_lowercase(), |
193 | | - (from_u32(lower).unwrap()).to_string()); |
194 | | - } |
195 | | - } |
196 | | - |
197 | | - #[test] |
198 | | - fn test_make_ascii_lower_case() { |
199 | | - macro_rules! test { |
200 | | - ($from: expr, $to: expr) => { |
201 | | - { |
202 | | - let mut x = $from; |
203 | | - x.make_ascii_lowercase(); |
204 | | - assert_eq!(x, $to); |
205 | | - } |
206 | | - } |
207 | | - } |
208 | | - test!(b'A', b'a'); |
209 | | - test!(b'a', b'a'); |
210 | | - test!(b'!', b'!'); |
211 | | - test!('A', 'a'); |
212 | | - test!('À', 'À'); |
213 | | - test!('a', 'a'); |
214 | | - test!('!', '!'); |
215 | | - test!(b"H\xc3\x89".to_vec(), b"h\xc3\x89"); |
216 | | - test!("HİKß".to_string(), "hİKß"); |
217 | | - } |
218 | | - |
219 | | - |
220 | | - #[test] |
221 | | - fn test_make_ascii_upper_case() { |
222 | | - macro_rules! test { |
223 | | - ($from: expr, $to: expr) => { |
224 | | - { |
225 | | - let mut x = $from; |
226 | | - x.make_ascii_uppercase(); |
227 | | - assert_eq!(x, $to); |
228 | | - } |
229 | | - } |
230 | | - } |
231 | | - test!(b'a', b'A'); |
232 | | - test!(b'A', b'A'); |
233 | | - test!(b'!', b'!'); |
234 | | - test!('a', 'A'); |
235 | | - test!('à', 'à'); |
236 | | - test!('A', 'A'); |
237 | | - test!('!', '!'); |
238 | | - test!(b"h\xc3\xa9".to_vec(), b"H\xc3\xa9"); |
239 | | - test!("hıKß".to_string(), "HıKß"); |
240 | | - |
241 | | - let mut x = "Hello".to_string(); |
242 | | - x[..3].make_ascii_uppercase(); // Test IndexMut on String. |
243 | | - assert_eq!(x, "HELlo") |
244 | | - } |
245 | | - |
246 | | - #[test] |
247 | | - fn test_eq_ignore_ascii_case() { |
248 | | - assert!("url()URL()uRl()Ürl".eq_ignore_ascii_case("url()url()url()Ürl")); |
249 | | - assert!(!"Ürl".eq_ignore_ascii_case("ürl")); |
250 | | - // Dotted capital I, Kelvin sign, Sharp S. |
251 | | - assert!("HİKß".eq_ignore_ascii_case("hİKß")); |
252 | | - assert!(!"İ".eq_ignore_ascii_case("i")); |
253 | | - assert!(!"K".eq_ignore_ascii_case("k")); |
254 | | - assert!(!"ß".eq_ignore_ascii_case("s")); |
255 | | - |
256 | | - for i in 0..501 { |
257 | | - let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } |
258 | | - else { i }; |
259 | | - assert!((from_u32(i).unwrap()).to_string().eq_ignore_ascii_case( |
260 | | - &from_u32(lower).unwrap().to_string())); |
261 | | - } |
262 | | - } |
263 | | - |
264 | | - #[test] |
265 | | - fn inference_works() { |
266 | | - let x = "a".to_string(); |
267 | | - x.eq_ignore_ascii_case("A"); |
268 | | - } |
269 | | - |
270 | | - // Shorthands used by the is_ascii_* tests. |
271 | | - macro_rules! assert_all { |
272 | | - ($what:ident, $($str:tt),+) => {{ |
273 | | - $( |
274 | | - for b in $str.chars() { |
275 | | - if !b.$what() { |
276 | | - panic!("expected {}({}) but it isn't", |
277 | | - stringify!($what), b); |
278 | | - } |
279 | | - } |
280 | | - for b in $str.as_bytes().iter() { |
281 | | - if !b.$what() { |
282 | | - panic!("expected {}(0x{:02x})) but it isn't", |
283 | | - stringify!($what), b); |
284 | | - } |
285 | | - } |
286 | | - assert!($str.$what()); |
287 | | - assert!($str.as_bytes().$what()); |
288 | | - )+ |
289 | | - }}; |
290 | | - ($what:ident, $($str:tt),+,) => (assert_all!($what,$($str),+)) |
291 | | - } |
292 | | - macro_rules! assert_none { |
293 | | - ($what:ident, $($str:tt),+) => {{ |
294 | | - $( |
295 | | - for b in $str.chars() { |
296 | | - if b.$what() { |
297 | | - panic!("expected not-{}({}) but it is", |
298 | | - stringify!($what), b); |
299 | | - } |
300 | | - } |
301 | | - for b in $str.as_bytes().iter() { |
302 | | - if b.$what() { |
303 | | - panic!("expected not-{}(0x{:02x})) but it is", |
304 | | - stringify!($what), b); |
305 | | - } |
306 | | - } |
307 | | - )* |
308 | | - }}; |
309 | | - ($what:ident, $($str:tt),+,) => (assert_none!($what,$($str),+)) |
310 | | - } |
311 | | - |
312 | | - #[test] |
313 | | - fn test_is_ascii_alphabetic() { |
314 | | - assert_all!(is_ascii_alphabetic, |
315 | | - "", |
316 | | - "abcdefghijklmnopqrstuvwxyz", |
317 | | - "ABCDEFGHIJKLMNOQPRSTUVWXYZ", |
318 | | - ); |
319 | | - assert_none!(is_ascii_alphabetic, |
320 | | - "0123456789", |
321 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
322 | | - " \t\n\x0c\r", |
323 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
324 | | - "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", |
325 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
326 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
327 | | - "\x7f", |
328 | | - ); |
329 | | - } |
330 | | - |
331 | | - #[test] |
332 | | - fn test_is_ascii_uppercase() { |
333 | | - assert_all!(is_ascii_uppercase, |
334 | | - "", |
335 | | - "ABCDEFGHIJKLMNOQPRSTUVWXYZ", |
336 | | - ); |
337 | | - assert_none!(is_ascii_uppercase, |
338 | | - "abcdefghijklmnopqrstuvwxyz", |
339 | | - "0123456789", |
340 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
341 | | - " \t\n\x0c\r", |
342 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
343 | | - "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", |
344 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
345 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
346 | | - "\x7f", |
347 | | - ); |
348 | | - } |
349 | | - |
350 | | - #[test] |
351 | | - fn test_is_ascii_lowercase() { |
352 | | - assert_all!(is_ascii_lowercase, |
353 | | - "abcdefghijklmnopqrstuvwxyz", |
354 | | - ); |
355 | | - assert_none!(is_ascii_lowercase, |
356 | | - "ABCDEFGHIJKLMNOQPRSTUVWXYZ", |
357 | | - "0123456789", |
358 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
359 | | - " \t\n\x0c\r", |
360 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
361 | | - "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", |
362 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
363 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
364 | | - "\x7f", |
365 | | - ); |
366 | | - } |
367 | | - |
368 | | - #[test] |
369 | | - fn test_is_ascii_alphanumeric() { |
370 | | - assert_all!(is_ascii_alphanumeric, |
371 | | - "", |
372 | | - "abcdefghijklmnopqrstuvwxyz", |
373 | | - "ABCDEFGHIJKLMNOQPRSTUVWXYZ", |
374 | | - "0123456789", |
375 | | - ); |
376 | | - assert_none!(is_ascii_alphanumeric, |
377 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
378 | | - " \t\n\x0c\r", |
379 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
380 | | - "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", |
381 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
382 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
383 | | - "\x7f", |
384 | | - ); |
385 | | - } |
386 | | - |
387 | | - #[test] |
388 | | - fn test_is_ascii_digit() { |
389 | | - assert_all!(is_ascii_digit, |
390 | | - "", |
391 | | - "0123456789", |
392 | | - ); |
393 | | - assert_none!(is_ascii_digit, |
394 | | - "abcdefghijklmnopqrstuvwxyz", |
395 | | - "ABCDEFGHIJKLMNOQPRSTUVWXYZ", |
396 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
397 | | - " \t\n\x0c\r", |
398 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
399 | | - "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", |
400 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
401 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
402 | | - "\x7f", |
403 | | - ); |
404 | | - } |
405 | | - |
406 | | - #[test] |
407 | | - fn test_is_ascii_hexdigit() { |
408 | | - assert_all!(is_ascii_hexdigit, |
409 | | - "", |
410 | | - "0123456789", |
411 | | - "abcdefABCDEF", |
412 | | - ); |
413 | | - assert_none!(is_ascii_hexdigit, |
414 | | - "ghijklmnopqrstuvwxyz", |
415 | | - "GHIJKLMNOQPRSTUVWXYZ", |
416 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
417 | | - " \t\n\x0c\r", |
418 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
419 | | - "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", |
420 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
421 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
422 | | - "\x7f", |
423 | | - ); |
424 | | - } |
425 | | - |
426 | | - #[test] |
427 | | - fn test_is_ascii_punctuation() { |
428 | | - assert_all!(is_ascii_punctuation, |
429 | | - "", |
430 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
431 | | - ); |
432 | | - assert_none!(is_ascii_punctuation, |
433 | | - "abcdefghijklmnopqrstuvwxyz", |
434 | | - "ABCDEFGHIJKLMNOQPRSTUVWXYZ", |
435 | | - "0123456789", |
436 | | - " \t\n\x0c\r", |
437 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
438 | | - "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", |
439 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
440 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
441 | | - "\x7f", |
442 | | - ); |
443 | | - } |
444 | | - |
445 | | - #[test] |
446 | | - fn test_is_ascii_graphic() { |
447 | | - assert_all!(is_ascii_graphic, |
448 | | - "", |
449 | | - "abcdefghijklmnopqrstuvwxyz", |
450 | | - "ABCDEFGHIJKLMNOQPRSTUVWXYZ", |
451 | | - "0123456789", |
452 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
453 | | - ); |
454 | | - assert_none!(is_ascii_graphic, |
455 | | - " \t\n\x0c\r", |
456 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
457 | | - "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", |
458 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
459 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
460 | | - "\x7f", |
461 | | - ); |
462 | | - } |
463 | | - |
464 | | - #[test] |
465 | | - fn test_is_ascii_whitespace() { |
466 | | - assert_all!(is_ascii_whitespace, |
467 | | - "", |
468 | | - " \t\n\x0c\r", |
469 | | - ); |
470 | | - assert_none!(is_ascii_whitespace, |
471 | | - "abcdefghijklmnopqrstuvwxyz", |
472 | | - "ABCDEFGHIJKLMNOQPRSTUVWXYZ", |
473 | | - "0123456789", |
474 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
475 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
476 | | - "\x08\x0b\x0e\x0f", |
477 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
478 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
479 | | - "\x7f", |
480 | | - ); |
481 | | - } |
482 | | - |
483 | | - #[test] |
484 | | - fn test_is_ascii_control() { |
485 | | - assert_all!(is_ascii_control, |
486 | | - "", |
487 | | - "\x00\x01\x02\x03\x04\x05\x06\x07", |
488 | | - "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", |
489 | | - "\x10\x11\x12\x13\x14\x15\x16\x17", |
490 | | - "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", |
491 | | - "\x7f", |
492 | | - ); |
493 | | - assert_none!(is_ascii_control, |
494 | | - "abcdefghijklmnopqrstuvwxyz", |
495 | | - "ABCDEFGHIJKLMNOQPRSTUVWXYZ", |
496 | | - "0123456789", |
497 | | - "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", |
498 | | - " ", |
499 | | - ); |
500 | | - } |
501 | | -} |
0 commit comments