Skip to content

Commit da676ff

Browse files
test humanize_blob.
1 parent ca3fc87 commit da676ff

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

rs/nervous_system/string/src/tests.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,21 @@ fn test_clamp_debug_len() {
5757

5858
assert_eq!(&clamp_debug_len(&S { i: 42 }, 100), "S {\n i: 42,\n}");
5959
}
60+
61+
#[test]
62+
fn test_humanize_blob() {
63+
// Short blob: fully hex-encoded.
64+
assert_eq!(humanize_blob(&[0x00, 0x61, 0x73, 0x6d], 10), "0061736d");
65+
66+
// Exact boundary.
67+
assert_eq!(humanize_blob(&[0xab, 0xcd], 2), "abcd");
68+
69+
// Truncated.
70+
assert_eq!(
71+
humanize_blob(&[0xab, 0xcd, 0xef], 2),
72+
"abcd... (3 bytes total)",
73+
);
74+
75+
// Empty.
76+
assert_eq!(humanize_blob(&[], 10), "");
77+
}

0 commit comments

Comments
 (0)