Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit d3da48e

Browse files
committed
Add test to verify hash prints using alternate
Add a unit test to ensure `Display` and `LowerHex` are correctly pre-pending `0x` if the alternate form is printed.
1 parent 04be9e2 commit d3da48e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/util.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,34 @@ mod test {
323323
assert_eq!(u32_to_array_le(0xdeadbeef), [0xef, 0xbe, 0xad, 0xde]);
324324
assert_eq!(u64_to_array_le(0x1badcafedeadbeef), [0xef, 0xbe, 0xad, 0xde, 0xfe, 0xca, 0xad, 0x1b]);
325325
}
326+
327+
hash_newtype!(TestHash, crate::sha256d::Hash, 32, doc="Test hash.");
328+
329+
#[test]
330+
fn display() {
331+
let want = "0000000000000000000000000000000000000000000000000000000000000000";
332+
let got = format!("{}", TestHash::all_zeros());
333+
assert_eq!(got, want)
334+
}
335+
336+
#[test]
337+
fn display_alternate() {
338+
let want = "0x0000000000000000000000000000000000000000000000000000000000000000";
339+
let got = format!("{:#}", TestHash::all_zeros());
340+
assert_eq!(got, want)
341+
}
342+
343+
#[test]
344+
fn lower_hex() {
345+
let want = "0000000000000000000000000000000000000000000000000000000000000000";
346+
let got = format!("{:x}", TestHash::all_zeros());
347+
assert_eq!(got, want)
348+
}
349+
350+
#[test]
351+
fn lower_hex_alternate() {
352+
let want = "0x0000000000000000000000000000000000000000000000000000000000000000";
353+
let got = format!("{:#x}", TestHash::all_zeros());
354+
assert_eq!(got, want)
355+
}
326356
}

0 commit comments

Comments
 (0)