Skip to content

Commit

Permalink
test: extend tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
vmx committed Apr 23, 2024
1 parent 5129dcf commit a2959cb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tests/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,34 @@ fn test_struct_canonical() {
let second_bytes = serde_ipld_dagcbor::to_vec(&second).unwrap();

assert_eq!(first_bytes, second_bytes);
// Do not only make sure that the order is the same, but also that it's correct.
assert_eq!(first_bytes, b"\xa2\x61a\x01\x61b\x02")
}

#[test]
fn test_struct_variant_canonical() {
// The `abc` is there to make sure it really follows the DAG-CBOR sorting order, which sorts by
// length of the keys first, then lexicographically. It means that `abc` sorts *after* `b`.
#[derive(Serialize)]
enum First {
Data { a: u8, b: u8, c: u8 },
Data { a: u8, b: u8, abc: u8 },
}

#[derive(Serialize)]
enum Second {
Data { b: u8, c: u8, a: u8 },
Data { b: u8, abc: u8, a: u8 },
}

let first = First::Data { a: 1, b: 2, c: 3 };
let second = Second::Data { a: 1, b: 2, c: 3 };
let first = First::Data { a: 1, b: 2, abc: 3 };
let second = Second::Data { a: 1, b: 2, abc: 3 };

let first_bytes = serde_ipld_dagcbor::to_vec(&first).unwrap();
let second_bytes = serde_ipld_dagcbor::to_vec(&second).unwrap();

assert_eq!(first_bytes, second_bytes);
// Do not only make sure that the order is the same, but also that it's correct.
assert_eq!(
first_bytes,
b"\xa1\x64Data\xa3\x61a\x01\x61b\x02\x63abc\x03"
)
}

0 comments on commit a2959cb

Please sign in to comment.