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`.
This commit is contained in:
Jamil Lambert, PhD 2025-04-30 16:14:05 +01:00
parent 8a0e645dfd
commit 82da8a599e
No known key found for this signature in database
GPG Key ID: 54DC29234AB5D2C0
2 changed files with 22 additions and 0 deletions

View File

@ -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());
}
}

View File

@ -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");
}
}