3 use crate::hex::{FromHex, ToHex};
7 assert_eq!("foobar".as_bytes().to_hex(), "666f6f626172");
11 pub fn test_from_hex_okay() {
12 assert_eq!("666f6f626172".from_hex().unwrap(),
14 assert_eq!("666F6F626172".from_hex().unwrap(),
19 pub fn test_from_hex_odd_len() {
20 assert!("666".from_hex().is_err());
21 assert!("66 6".from_hex().is_err());
25 pub fn test_from_hex_invalid_char() {
26 assert!("66y6".from_hex().is_err());
30 pub fn test_from_hex_ignores_whitespace() {
31 assert_eq!("666f 6f6\r\n26172 ".from_hex().unwrap(),
36 pub fn test_to_hex_all_bytes() {
38 assert_eq!([i as u8].to_hex(), format!("{:02x}", i as usize));
43 pub fn test_from_hex_all_bytes() {
45 let ii: &[u8] = &[i as u8];
46 assert_eq!(format!("{:02x}", i as usize).from_hex()
49 assert_eq!(format!("{:02X}", i as usize).from_hex()
56 pub fn bench_to_hex(b: &mut Bencher) {
57 let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
58 ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
60 s.as_bytes().to_hex();
62 b.bytes = s.len() as u64;
66 pub fn bench_from_hex(b: &mut Bencher) {
67 let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
68 ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
69 let sb = s.as_bytes().to_hex();
71 sb.from_hex().unwrap();
73 b.bytes = sb.len() as u64;