Merge rust-bitcoin/rust-bitcoin#4420: primitives: Add regression tests for `Display` implementations

82da8a599e Add regression tests for Display impl (Jamil Lambert, PhD)

Pull request description:

  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. Discussed in #4415.

  Add missing tests for all implementations in `primitives` and round trips for types that implement `FromStr`.

ACKs for top commit:
  tcharding:
    ACK 82da8a599e
  apoelstra:
    ACK 82da8a599e4a046b8da7763e8aaeff28becc49a6; successfully ran local tests

Tree-SHA512: ca70ee81e8a76bee27bc0314f2bc718893190c7cc37e5a357244f0925bc3fb675cb2e096aaf764a35216ea7c544f491bd071034f23f97cfa55e3bf50f47b2d84
This commit is contained in:
merge-script 2025-05-02 12:59:26 +00:00
commit 5e96436a5c
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 22 additions and 0 deletions

View File

@ -354,4 +354,11 @@ mod tests {
let sequence_u32: u32 = sequence.into(); let sequence_u32: u32 = sequence.into();
assert_eq!(sequence_u32, 0x7FFF_FFFF); 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());
}
} }

View File

@ -748,4 +748,19 @@ mod tests {
assert!(parse_vout("01").is_err()); // Leading zero not allowed assert!(parse_vout("01").is_err()); // Leading zero not allowed
assert!(parse_vout("+1").is_err()); // Non digits 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");
}
} }