From 82da8a599e4a046b8da7763e8aaeff28becc49a6 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 30 Apr 2025 16:14:05 +0100 Subject: [PATCH] Add regression tests for Display impl The output of `Display` should not change in stable crates for types that have well defined formatting and ones that implement `FromStr`. Error types do not need to be tested. Add missing tests for all implementations in `primitives` and round trips for types that implement `FromStr`. --- primitives/src/sequence.rs | 7 +++++++ primitives/src/transaction.rs | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/primitives/src/sequence.rs b/primitives/src/sequence.rs index df291b7ee..6078846c1 100644 --- a/primitives/src/sequence.rs +++ b/primitives/src/sequence.rs @@ -354,4 +354,11 @@ mod tests { let sequence_u32: u32 = sequence.into(); assert_eq!(sequence_u32, 0x7FFF_FFFF); } + + #[test] + fn sequence_display() { + let sequence = Sequence(0x7FFF_FFFF); + let want: u32 = 0x7FFF_FFFF; + assert_eq!(format!("{}", sequence), want.to_string()); + } } diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs index 2727551d7..10176ef76 100644 --- a/primitives/src/transaction.rs +++ b/primitives/src/transaction.rs @@ -748,4 +748,19 @@ mod tests { assert!(parse_vout("01").is_err()); // Leading zero not allowed assert!(parse_vout("+1").is_err()); // Non digits not allowed } + + #[test] + #[cfg(feature = "alloc")] + #[cfg(feature = "hex")] + fn outpoint_display_roundtrip() { + let outpoint_str = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20:1"; + let outpoint: OutPoint = outpoint_str.parse().unwrap(); + assert_eq!(format!("{}", outpoint), outpoint_str); + } + + #[test] + fn version_display() { + let version = Version(123); + assert_eq!(format!("{}", version), "123"); + } }