forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbstr.rs
More file actions
67 lines (58 loc) · 2.84 KB
/
bstr.rs
File metadata and controls
67 lines (58 loc) · 2.84 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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}!"), "�(��!");
assert_eq!(&format!("{b1:.1}!"), &format!("{:.1}!", "abc"));
assert_eq!(&format!("{b1:.2}!"), &format!("{:.2}!", "abc"));
assert_eq!(&format!("{b1:.3}!"), &format!("{:.3}!", "abc"));
assert_eq!(&format!("{b1:-<5.2}!"), &format!("{:-<5.2}!", "abc"));
assert_eq!(&format!("{b1:-^5.2}!"), &format!("{:-^5.2}!", "abc"));
assert_eq!(&format!("{b1:->5.2}!"), &format!("{:->5.2}!", "abc"));
assert_eq!(&format!("{b2:.1}!"), "�!");
assert_eq!(&format!("{b2:.2}!"), "�(!");
assert_eq!(&format!("{b2:.3}!"), "�(�!");
assert_eq!(&format!("{b2:.4}!"), "�(��!");
assert_eq!(&format!("{b2:-<6.3}!"), "�(�---!");
assert_eq!(&format!("{b2:-^6.3}!"), "-�(�--!");
assert_eq!(&format!("{b2:->6.3}!"), "---�(�!");
}