1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#[cfg(test)]
#[macro_use]
extern crate proptest;
#[cfg(test)]
extern crate hex;

mod encode;

pub use encode::{hex_string, hex_to};

#[cfg(test)]
mod tests {
    use super::*;
    use encode::hex_string;
    use std::str;

    fn _test_hex(s: &String) {
        let mut buffer = vec![0; s.as_bytes().len() * 2];
        hex_to(s.as_bytes(), &mut buffer).unwrap();
        let encode = unsafe { str::from_utf8_unchecked(&buffer[..s.as_bytes().len() * 2]) };

        let hex_string = hex_string(s.as_bytes()).unwrap();

        assert_eq!(encode, hex::encode(s));
        assert_eq!(hex_string, hex::encode(s));
    }

    proptest! {
        #[test]
        fn test_hex(ref s in ".*") {
            _test_hex(s);
        }
    }
}