Skip to content

Commit

Permalink
[borsh] Add std feature and test serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pczarn committed May 31, 2024
1 parent 31a80b9 commit 16475e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ rand_xorshift = "0.2"
default = ["std"]
serde_std = ["std", "serde/std"]
serde_no_std = ["serde/alloc"]
borsh_std = ["borsh/std"]
std = []
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,21 @@ mod tests {
assert_eq!(bit_vec, unserialized);
}

#[cfg(feature = "borsh")]
#[test]
fn test_borsh_serialization() {
let bit_vec: BitVec = BitVec::new();
let serialized = borsh::to_vec(&bit_vec).unwrap();
let unserialized: BitVec = borsh::from_slice(&serialized[..]).unwrap();
assert_eq!(bit_vec, unserialized);

let bools = vec![true, false, true, true];
let bit_vec: BitVec = bools.iter().map(|n| *n).collect();
let serialized = borsh::to_vec(&bit_vec).unwrap();
let unserialized = borsh::from_slice(&serialized[..]).unwrap();
assert_eq!(bit_vec, unserialized);
}

#[test]
fn test_bit_vec_unaligned_small_append() {
let mut a = BitVec::from_elem(8, false);
Expand Down

0 comments on commit 16475e1

Please sign in to comment.