diff --git a/tests/mod.rs b/tests/mod.rs index 84b95482..c4744464 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -72,6 +72,12 @@ struct TestHasCompact { bar: T, } +#[derive(Debug, PartialEq, Encode, Decode)] +struct TestCompactHasCompact { + #[codec(compact)] + bar: T, +} + #[derive(Debug, PartialEq, Encode, Decode)] enum TestHasCompactEnum { Unnamed(#[codec(encoded_as = "::Type")] T), @@ -79,6 +85,11 @@ enum TestHasCompactEnum { #[codec(encoded_as = "::Type")] bar: T }, + UnnamedCompact(#[codec(compact)] T), + NamedCompact { + #[codec(compact)] + bar: T + }, } #[derive(Debug, PartialEq, Encode, Decode)] @@ -211,9 +222,24 @@ fn encoded_as_with_has_compact_works() { } #[test] -fn enum_encoded_as_with_has_compact_works() { +fn compact_with_has_compact_works() { + for &(n, l) in U64_TEST_COMPACT_VALUES { + let encoded = TestHasCompact { bar: n }.encode(); + println!("{}", n); + assert_eq!(encoded.len(), l); + assert_eq!(>::decode(&mut &encoded[..]).unwrap().bar, n); + } +} + +#[test] +fn enum_compact_and_encoded_as_with_has_compact_works() { for &(n, l) in U64_TEST_COMPACT_VALUES_FOR_ENUM { - for value in [ TestHasCompactEnum::Unnamed(n), TestHasCompactEnum::Named { bar: n } ].iter() { + for value in [ + TestHasCompactEnum::Unnamed(n), + TestHasCompactEnum::Named { bar: n }, + TestHasCompactEnum::UnnamedCompact(n), + TestHasCompactEnum::NamedCompact { bar: n }, + ].iter() { let encoded = value.encode(); println!("{:?}", value); assert_eq!(encoded.len(), l);