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)]
|
#[cfg(test)]
|
||||||
fn example_encoding_decoding() {
|
mod tests {
|
||||||
let _xs: Vec<u32> = vec![123, 250, 256, 123, 123, 123];
|
use super::*;
|
||||||
let _xs: Vec<u32> = vec![];
|
|
||||||
let _xs: Vec<u32> = vec![123];
|
|
||||||
let _xs: Vec<u32> = vec![123, 250];
|
|
||||||
|
|
||||||
let xs: Vec<String> = vec!["foo".to_string(), "bar".to_string()];
|
#[test]
|
||||||
|
fn test_encoding_decoding() {
|
||||||
|
let xs: Vec<String> = vec!["foo".to_string(), "bar".to_string()];
|
||||||
|
|
||||||
|
let exs = encode_vector(&xs[..]).unwrap();
|
||||||
|
|
||||||
println!("original {:?}", xs);
|
// WARNING: Don't forget to specify the type here
|
||||||
let exs = encode_vector(&xs[..]).unwrap();
|
let dxs = decode_vector::<String>(&exs[..]).unwrap();
|
||||||
println!("encoded {:?}", exs);
|
|
||||||
|
|
||||||
// WARNING: Don't forget to specify the type here
|
assert!(dxs == xs);
|
||||||
// let dxs = decode_vector::<u32>(&exs[..]).unwrap();
|
}
|
||||||
let dxs = decode_vector::<String>(&exs[..]).unwrap();
|
|
||||||
println!("decoded {:?}", dxs);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue