Debian Codegraph @

debian/rust-vendor/z85/tests/tests.rs

raw
1 use proptest::prelude::*;
2 use z85::*;
3
4 const BINARR: [u8; 8] = [0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B];
5 const Z85ARR: [u8; 10] = *b"HelloWorld";
6
7 #[test]
8 fn encode_simple() {
9 let z85_dat = encode(&BINARR);
10 assert_eq!(&Z85ARR, z85_dat.as_bytes());
11 }
12
13 #[test]
14 fn decode_simple() {
15 let bin_dat = decode(&Z85ARR).unwrap();
16 assert_eq!(&BINARR, bin_dat.as_slice());
17 }
18
19 #[test]
20 fn encode_tail_only() {
21 const BINTAIL: [u8; 2] = [0x86, 0x4F];
22 let z85_dat = encode(&BINTAIL);
23 let out_tail = decode(&z85_dat).unwrap();
24 assert_eq!(&BINTAIL, out_tail.as_slice());
25 }
26
27 #[test]
28 fn decode_too_big_tail() {
29 let z85str = "HelloWorld#####";
30 let decoded = decode(z85str);
31 assert_eq!(decoded, Err(DecodeError::InvalidTail));
32 }
33
34 proptest! {
35 #[test]
36 fn encode_prop(input: Vec<u8>) {
37 let z85_dat = encode(&input);
38 let ans_bin_dat = decode(z85_dat).unwrap();
39 assert_eq!(ans_bin_dat, input);
40 }
41 }