diff options
| author | bors <bors@rust-lang.org> | 2015-07-13 23:47:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-07-13 23:47:06 +0000 |
| commit | dd46cf8b22c39a74b786361e00af22314a32b196 (patch) | |
| tree | ef42015a6a4e59fe77648d41ca5a79f4e0cdb21f /src/libstd | |
| parent | 72483f58e355c6ec9016cbaba4d9b8d3adbd3867 (diff) | |
| parent | 3226858e500fa70b46c18d1accedc60060f2bbc0 (diff) | |
| download | rust-dd46cf8b22c39a74b786361e00af22314a32b196.tar.gz rust-dd46cf8b22c39a74b786361e00af22314a32b196.zip | |
Auto merge of #26241 - SimonSapin:derefmut-for-string, r=alexcrichton
See https://github.com/rust-lang/rfcs/issues/1157
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ascii.rs | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 9b94b7f7003..cf78fa7b69a 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -469,16 +469,19 @@ mod tests { use char::from_u32; #[test] - fn test_ascii() { - assert!("banana".chars().all(|c| c.is_ascii())); - assert!(!"ประเทศไทย中华Việt Nam".chars().all(|c| c.is_ascii())); - } + fn test_is_ascii() { + assert!(b"".is_ascii()); + assert!(b"banana\0\x7F".is_ascii()); + assert!(b"banana\0\x7F".iter().all(|b| b.is_ascii())); + assert!(!b"Vi\xe1\xbb\x87t Nam".is_ascii()); + assert!(!b"Vi\xe1\xbb\x87t Nam".iter().all(|b| b.is_ascii())); + assert!(!b"\xe1\xbb\x87".iter().any(|b| b.is_ascii())); - #[test] - fn test_ascii_vec() { assert!("".is_ascii()); - assert!("a".is_ascii()); - assert!(!"\u{2009}".is_ascii()); + assert!("banana\0\u{7F}".is_ascii()); + assert!("banana\0\u{7F}".chars().all(|c| c.is_ascii())); + assert!(!"ประเทศไทย中华Việt Nam".chars().all(|c| c.is_ascii())); + assert!(!"ประเทศไทย中华ệ ".chars().any(|c| c.is_ascii())); } #[test] @@ -538,6 +541,55 @@ mod tests { } #[test] + fn test_make_ascii_lower_case() { + macro_rules! test { + ($from: expr, $to: expr) => { + { + let mut x = $from; + x.make_ascii_lowercase(); + assert_eq!(x, $to); + } + } + } + test!(b'A', b'a'); + test!(b'a', b'a'); + test!(b'!', b'!'); + test!('A', 'a'); + test!('À', 'À'); + test!('a', 'a'); + test!('!', '!'); + test!(b"H\xc3\x89".to_vec(), b"h\xc3\x89"); + test!("HİKß".to_string(), "hİKß"); + } + + + #[test] + fn test_make_ascii_upper_case() { + macro_rules! test { + ($from: expr, $to: expr) => { + { + let mut x = $from; + x.make_ascii_uppercase(); + assert_eq!(x, $to); + } + } + } + test!(b'a', b'A'); + test!(b'A', b'A'); + test!(b'!', b'!'); + test!('a', 'A'); + test!('à', 'à'); + test!('A', 'A'); + test!('!', '!'); + test!(b"h\xc3\xa9".to_vec(), b"H\xc3\xa9"); + test!("hıKß".to_string(), "HıKß"); + + let mut x = "Hello".to_string(); + x[..3].make_ascii_uppercase(); // Test IndexMut on String. + assert_eq!(x, "HELlo") + } + + #[test] fn test_eq_ignore_ascii_case() { assert!("url()URL()uRl()Ürl".eq_ignore_ascii_case("url()url()url()Ürl")); assert!(!"Ürl".eq_ignore_ascii_case("ürl")); |
