diff options
Diffstat (limited to 'src/libcoretest/char.rs')
| -rw-r--r-- | src/libcoretest/char.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index c1f3ea42ef4..ba8918fc6cb 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -175,9 +175,10 @@ fn test_escape_unicode() { #[test] fn test_encode_utf8() { fn check(input: char, expect: &[u8]) { - let mut buf = [0; 4]; - let n = input.encode_utf8(&mut buf).unwrap_or(0); - assert_eq!(&buf[..n], expect); + assert_eq!(input.encode_utf8().as_slice(), expect); + for (a, b) in input.encode_utf8().zip(expect) { + assert_eq!(a, *b); + } } check('x', &[0x78]); @@ -189,9 +190,10 @@ fn test_encode_utf8() { #[test] fn test_encode_utf16() { fn check(input: char, expect: &[u16]) { - let mut buf = [0; 2]; - let n = input.encode_utf16(&mut buf).unwrap_or(0); - assert_eq!(&buf[..n], expect); + assert_eq!(input.encode_utf16().as_slice(), expect); + for (a, b) in input.encode_utf16().zip(expect) { + assert_eq!(a, *b); + } } check('x', &[0x0078]); |
