Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 committed Jan 18, 2019
1 parent f4d8911 commit 6c71f05
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,24 @@ struct TestHasCompact<T: HasCompact> {
bar: T,
}

#[derive(Debug, PartialEq, Encode, Decode)]
struct TestCompactHasCompact<T: HasCompact> {
#[codec(compact)]
bar: T,
}

#[derive(Debug, PartialEq, Encode, Decode)]
enum TestHasCompactEnum<T: HasCompact> {
Unnamed(#[codec(encoded_as = "<T as HasCompact>::Type")] T),
Named {
#[codec(encoded_as = "<T as HasCompact>::Type")]
bar: T
},
UnnamedCompact(#[codec(compact)] T),
NamedCompact {
#[codec(compact)]
bar: T
},
}

#[derive(Debug, PartialEq, Encode, Decode)]
Expand Down Expand Up @@ -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!(<TestCompactHasCompact<u64>>::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);
Expand Down

0 comments on commit 6c71f05

Please sign in to comment.