1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
use core::bstr::ByteStr;
#[test]
fn test_debug() {
assert_eq!(
r#""\0\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x11\x12\r\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f \x7f\x80\x81\xfe\xff""#,
format!("{:?}", ByteStr::new(b"\0\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x11\x12\r\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f \x7f\x80\x81\xfe\xff")),
);
}
#[test]
fn test_display() {
let b1 = ByteStr::new("abc");
let b2 = ByteStr::new(b"\xf0\x28\x8c\xbc");
assert_eq!(&format!("{b1}"), "abc");
assert_eq!(&format!("{b2}"), "�(��");
assert_eq!(&format!("{b1:<7}!"), "abc !");
assert_eq!(&format!("{b1:>7}!"), " abc!");
assert_eq!(&format!("{b1:^7}!"), " abc !");
assert_eq!(&format!("{b1:^6}!"), " abc !");
assert_eq!(&format!("{b1:-<7}!"), "abc----!");
assert_eq!(&format!("{b1:->7}!"), "----abc!");
assert_eq!(&format!("{b1:-^7}!"), "--abc--!");
assert_eq!(&format!("{b1:-^6}!"), "-abc--!");
assert_eq!(&format!("{b2:<7}!"), "�(�� !");
assert_eq!(&format!("{b2:>7}!"), " �(��!");
assert_eq!(&format!("{b2:^7}!"), " �(�� !");
assert_eq!(&format!("{b2:^6}!"), " �(�� !");
assert_eq!(&format!("{b2:-<7}!"), "�(��---!");
assert_eq!(&format!("{b2:->7}!"), "---�(��!");
assert_eq!(&format!("{b2:-^7}!"), "-�(��--!");
assert_eq!(&format!("{b2:-^6}!"), "-�(��-!");
assert_eq!(&format!("{b1:<2}!"), "abc!");
assert_eq!(&format!("{b1:>2}!"), "abc!");
assert_eq!(&format!("{b1:^2}!"), "abc!");
assert_eq!(&format!("{b1:-<2}!"), "abc!");
assert_eq!(&format!("{b1:->2}!"), "abc!");
assert_eq!(&format!("{b1:-^2}!"), "abc!");
assert_eq!(&format!("{b2:<3}!"), "�(��!");
assert_eq!(&format!("{b2:>3}!"), "�(��!");
assert_eq!(&format!("{b2:^3}!"), "�(��!");
assert_eq!(&format!("{b2:^2}!"), "�(��!");
assert_eq!(&format!("{b2:-<3}!"), "�(��!");
assert_eq!(&format!("{b2:->3}!"), "�(��!");
assert_eq!(&format!("{b2:-^3}!"), "�(��!");
assert_eq!(&format!("{b2:-^2}!"), "�(��!");
}
|