units: Add regression tests for Default impls

Add a regression test to the `api` tests to check the value returned by
`Default` for all types that implement it.
This commit is contained in:
Tobin C. Harding 2024-12-11 13:35:34 +11:00
parent f5c2248a31
commit a4a0f2921c
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 17 additions and 3 deletions

View File

@ -98,12 +98,13 @@ struct CommonTraits {
} }
/// A struct that includes all types that implement `Default`. /// A struct that includes all types that implement `Default`.
#[derive(Default)] // C-COMMON-TRAITS: `Default` #[derive(Debug, Default, PartialEq, Eq)] // C-COMMON-TRAITS: `Default`
struct Default { struct Default {
a: Amount, a: Amount,
b: SignedAmount, b: SignedAmount,
c: relative::Height, c: BlockInterval,
d: relative::Time, d: relative::Height,
e: relative::Time,
} }
/// A struct that includes all public error types. /// A struct that includes all public error types.
@ -249,3 +250,16 @@ fn test_sync() {
assert_sync::<Types>(); assert_sync::<Types>();
assert_sync::<Errors>(); assert_sync::<Errors>();
} }
#[test]
fn regression_default() {
let got: Default = Default::default();
let want = Default {
a: Amount::ZERO,
b: SignedAmount::ZERO,
c: BlockInterval::ZERO,
d: relative::Height::ZERO,
e: relative::Time::ZERO,
};
assert_eq!(got, want);
}