Use a macro in test_decode_utf8 to preserve line numbers in panic messages.
This commit is contained in:
parent
599f1b96b1
commit
892bf3d41d
@ -358,29 +358,31 @@ fn eu_iterator_specializations() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_decode_utf8() {
|
fn test_decode_utf8() {
|
||||||
use core::char::*;
|
macro_rules! assert_decode_utf8 {
|
||||||
use core::iter::FromIterator;
|
($input_bytes: expr, $expected_str: expr) => {
|
||||||
|
let input_bytes: &[u8] = &$input_bytes;
|
||||||
for &(str, bs) in [("", &[] as &[u8]),
|
let s = char::decode_utf8(input_bytes.iter().cloned())
|
||||||
("A", &[0x41u8] as &[u8]),
|
.map(|r_b| r_b.unwrap_or('\u{FFFD}'))
|
||||||
("<EFBFBD>", &[0xC1u8, 0x81u8] as &[u8]),
|
.collect::<String>();
|
||||||
("♥", &[0xE2u8, 0x99u8, 0xA5u8]),
|
assert_eq!(s, $expected_str,
|
||||||
("♥A", &[0xE2u8, 0x99u8, 0xA5u8, 0x41u8] as &[u8]),
|
"input bytes: {:?}, expected str: {:?}, result: {:?}",
|
||||||
("<EFBFBD>", &[0xE2u8, 0x99u8] as &[u8]),
|
input_bytes, $expected_str, s);
|
||||||
("<EFBFBD>A", &[0xE2u8, 0x99u8, 0x41u8] as &[u8]),
|
}
|
||||||
("<EFBFBD>", &[0xC0u8] as &[u8]),
|
|
||||||
("<EFBFBD>A", &[0xC0u8, 0x41u8] as &[u8]),
|
|
||||||
("<EFBFBD>", &[0x80u8] as &[u8]),
|
|
||||||
("<EFBFBD>A", &[0x80u8, 0x41u8] as &[u8]),
|
|
||||||
("<EFBFBD>", &[0xFEu8] as &[u8]),
|
|
||||||
("<EFBFBD>A", &[0xFEu8, 0x41u8] as &[u8]),
|
|
||||||
("<EFBFBD>", &[0xFFu8] as &[u8]),
|
|
||||||
("<EFBFBD>A", &[0xFFu8, 0x41u8] as &[u8])].into_iter() {
|
|
||||||
assert!(Iterator::eq(str.chars(),
|
|
||||||
decode_utf8(bs.into_iter().map(|&b|b))
|
|
||||||
.map(|r_b| r_b.unwrap_or('\u{FFFD}'))),
|
|
||||||
"chars = {}, bytes = {:?}, decoded = {:?}", str, bs,
|
|
||||||
Vec::from_iter(decode_utf8(bs.into_iter().map(|&b|b))
|
|
||||||
.map(|r_b| r_b.unwrap_or('\u{FFFD}'))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_decode_utf8!([], "");
|
||||||
|
assert_decode_utf8!([0x41], "A");
|
||||||
|
assert_decode_utf8!([0xC1, 0x81], "<EFBFBD>");
|
||||||
|
assert_decode_utf8!([0xE2, 0x99, 0xA5], "♥");
|
||||||
|
assert_decode_utf8!([0xE2, 0x99, 0xA5, 0x41], "♥A");
|
||||||
|
assert_decode_utf8!([0xE2, 0x99], "<EFBFBD>");
|
||||||
|
assert_decode_utf8!([0xE2, 0x99, 0x41], "<EFBFBD>A");
|
||||||
|
assert_decode_utf8!([0xC0], "<EFBFBD>");
|
||||||
|
assert_decode_utf8!([0xC0, 0x41], "<EFBFBD>A");
|
||||||
|
assert_decode_utf8!([0x80], "<EFBFBD>");
|
||||||
|
assert_decode_utf8!([0x80, 0x41], "<EFBFBD>A");
|
||||||
|
assert_decode_utf8!([0xFE], "<EFBFBD>");
|
||||||
|
assert_decode_utf8!([0xFE, 0x41], "<EFBFBD>A");
|
||||||
|
assert_decode_utf8!([0xFF], "<EFBFBD>");
|
||||||
|
assert_decode_utf8!([0xFF, 0x41], "<EFBFBD>A");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user