Test for encoding/decoding
This commit is contained in:
parent
fbfb069bbf
commit
0666c0d24c
1 changed files with 11 additions and 14 deletions
|
|
@ -69,22 +69,19 @@ pub fn decode_sequence<T: Decode>(len: usize, bytes: &[u8]) -> Result<Vec<T>, bi
|
|||
}
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn example_encoding_decoding() {
|
||||
let _xs: Vec<u32> = vec![123, 250, 256, 123, 123, 123];
|
||||
let _xs: Vec<u32> = vec![];
|
||||
let _xs: Vec<u32> = vec![123];
|
||||
let _xs: Vec<u32> = vec![123, 250];
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_encoding_decoding() {
|
||||
let xs: Vec<String> = vec!["foo".to_string(), "bar".to_string()];
|
||||
|
||||
|
||||
println!("original {:?}", xs);
|
||||
let exs = encode_vector(&xs[..]).unwrap();
|
||||
println!("encoded {:?}", exs);
|
||||
|
||||
// WARNING: Don't forget to specify the type here
|
||||
// let dxs = decode_vector::<u32>(&exs[..]).unwrap();
|
||||
let dxs = decode_vector::<String>(&exs[..]).unwrap();
|
||||
println!("decoded {:?}", dxs);
|
||||
|
||||
assert!(dxs == xs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue