Ignore the nu-pretty-hex tests that were cfg dead

Never compiled without the `alloc` feature anyways. some work necessary
This commit is contained in:
sholderbach 2024-07-25 22:33:23 +02:00
parent 94fea36040
commit 809d65f29e

View File

@ -1,158 +1,147 @@
// #![no_std]
#[cfg(feature = "alloc")]
extern crate alloc;
extern crate nu_pretty_hex;
#[cfg(feature = "alloc")]
use alloc::{format, string::String, vec, vec::Vec};
use nu_pretty_hex::*; use nu_pretty_hex::*;
#[cfg(feature = "alloc")] // #[test]
#[test] // fn test_simple() {
fn test_simple() { // let bytes: Vec<u8> = (0..16).collect();
let bytes: Vec<u8> = (0..16).collect(); // let expected = "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f";
let expected = "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"; // assert_eq!(expected, simple_hex(&bytes));
assert_eq!(expected, simple_hex(&bytes)); // assert_eq!(expected, bytes.hex_dump().to_string());
assert_eq!(expected, bytes.hex_dump().to_string()); // assert_eq!(simple_hex(&bytes), config_hex(&bytes, HexConfig::simple()));
assert_eq!(simple_hex(&bytes), config_hex(&bytes, HexConfig::simple())); //
// let mut have = String::new();
let mut have = String::new(); // simple_hex_write(&mut have, &bytes).unwrap();
simple_hex_write(&mut have, &bytes).unwrap(); // assert_eq!(expected, have);
assert_eq!(expected, have); //
// let str = "string";
let str = "string"; // let string: String = String::from("string");
let string: String = String::from("string"); // let slice: &[u8] = &[0x73, 0x74, 0x72, 0x69, 0x6e, 0x67];
let slice: &[u8] = &[0x73, 0x74, 0x72, 0x69, 0x6e, 0x67]; // assert_eq!(simple_hex(&str), "73 74 72 69 6e 67");
assert_eq!(simple_hex(&str), "73 74 72 69 6e 67"); // assert_eq!(simple_hex(&str), simple_hex(&string));
assert_eq!(simple_hex(&str), simple_hex(&string)); // assert_eq!(simple_hex(&str), simple_hex(&slice));
assert_eq!(simple_hex(&str), simple_hex(&slice)); //
// assert!(simple_hex(&vec![]).is_empty());
assert!(simple_hex(&vec![]).is_empty()); // }
} //
// #[test]
#[cfg(feature = "alloc")] // fn test_pretty() {
#[test] // let bytes: Vec<u8> = (0..256).map(|x| x as u8).collect();
fn test_pretty() { // let want = include_str!("256.txt");
let bytes: Vec<u8> = (0..256).map(|x| x as u8).collect(); //
let want = include_str!("256.txt"); // let mut hex = String::new();
// pretty_hex_write(&mut hex, &bytes).unwrap();
let mut hex = String::new(); // assert_eq!(want, hex);
pretty_hex_write(&mut hex, &bytes).unwrap(); // assert_eq!(want, format!("{:?}", bytes.hex_dump()));
assert_eq!(want, hex); // assert_eq!(want, pretty_hex(&bytes));
assert_eq!(want, format!("{:?}", bytes.hex_dump())); // assert_eq!(want, config_hex(&bytes, HexConfig::default()));
assert_eq!(want, pretty_hex(&bytes)); //
assert_eq!(want, config_hex(&bytes, HexConfig::default())); // assert_eq!("Length: 0 (0x0) bytes\n", pretty_hex(&vec![]));
// }
assert_eq!("Length: 0 (0x0) bytes\n", pretty_hex(&vec![])); //
} // #[test]
// fn test_config() {
#[cfg(feature = "alloc")] // let cfg = HexConfig {
#[test] // title: false,
fn test_config() { // ascii: false,
let cfg = HexConfig { // width: 0,
title: false, // group: 0,
ascii: false, // chunk: 0,
width: 0, // };
group: 0, // assert!(config_hex(&vec![], cfg).is_empty());
chunk: 0, // assert_eq!("2425262728", config_hex(&"$%&'(", cfg));
}; //
assert!(config_hex(&vec![], cfg).is_empty()); // let v = include_bytes!("data");
assert_eq!("2425262728", config_hex(&"$%&'(", cfg)); // let cfg = HexConfig {
// title: false,
let v = include_bytes!("data"); // group: 8,
let cfg = HexConfig { // ..HexConfig::default()
title: false, // };
group: 8, // let hex = "0000: 6b 4e 1a c3 af 03 d2 1e 7e 73 ba c8 bd 84 0f 83 kN......~s......\n\
..HexConfig::default() // 0010: 89 d5 cf 90 23 67 4b 48 db b1 bc 35 bf ee ....#gKH...5..";
}; // assert_eq!(hex, config_hex(&v, cfg));
let hex = "0000: 6b 4e 1a c3 af 03 d2 1e 7e 73 ba c8 bd 84 0f 83 kN......~s......\n\ // assert_eq!(hex, format!("{:?}", v.hex_conf(cfg)));
0010: 89 d5 cf 90 23 67 4b 48 db b1 bc 35 bf ee ....#gKH...5.."; // let mut str = String::new();
assert_eq!(hex, config_hex(&v, cfg)); // hex_write(&mut str, v, cfg).unwrap();
assert_eq!(hex, format!("{:?}", v.hex_conf(cfg))); // assert_eq!(hex, str);
let mut str = String::new(); //
hex_write(&mut str, v, cfg).unwrap(); // assert_eq!(
assert_eq!(hex, str); // config_hex(
// &v,
assert_eq!( // HexConfig {
config_hex( // ascii: false,
&v, // ..cfg
HexConfig { // }
ascii: false, // ),
..cfg // "0000: 6b 4e 1a c3 af 03 d2 1e 7e 73 ba c8 bd 84 0f 83\n\
} // 0010: 89 d5 cf 90 23 67 4b 48 db b1 bc 35 bf ee"
), // );
"0000: 6b 4e 1a c3 af 03 d2 1e 7e 73 ba c8 bd 84 0f 83\n\ //
0010: 89 d5 cf 90 23 67 4b 48 db b1 bc 35 bf ee" // assert_eq!(
); // config_hex(
// &v,
assert_eq!( // HexConfig {
config_hex( // ascii: false,
&v, // group: 4,
HexConfig { // chunk: 2,
ascii: false, // ..cfg
group: 4, // }
chunk: 2, // ),
..cfg // "0000: 6b4e 1ac3 af03 d21e 7e73 bac8 bd84 0f83\n\
} // 0010: 89d5 cf90 2367 4b48 dbb1 bc35 bfee"
), // );
"0000: 6b4e 1ac3 af03 d21e 7e73 bac8 bd84 0f83\n\ //
0010: 89d5 cf90 2367 4b48 dbb1 bc35 bfee" // let v: Vec<u8> = (0..21).collect();
); // let want = r##"Length: 21 (0x15) bytes
// 0000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................
let v: Vec<u8> = (0..21).collect(); // 0010: 10 11 12 13 14 ....."##;
let want = r##"Length: 21 (0x15) bytes // assert_eq!(want, pretty_hex(&v));
0000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................ //
0010: 10 11 12 13 14 ....."##; // let v: Vec<u8> = (0..13).collect();
assert_eq!(want, pretty_hex(&v)); // assert_eq!(
// config_hex(
let v: Vec<u8> = (0..13).collect(); // &v,
assert_eq!( // HexConfig {
config_hex( // title: false,
&v, // ascii: true,
HexConfig { // width: 11,
title: false, // group: 2,
ascii: true, // chunk: 3
width: 11, // }
group: 2, // ),
chunk: 3 // "0000: 000102 030405 060708 090a ...........\n\
} // 000b: 0b0c .."
), // );
"0000: 000102 030405 060708 090a ...........\n\ //
000b: 0b0c .." // let v: Vec<u8> = (0..19).collect();
); // assert_eq!(
// config_hex(
let v: Vec<u8> = (0..19).collect(); // &v,
assert_eq!( // HexConfig {
config_hex( // title: false,
&v, // ascii: true,
HexConfig { // width: 16,
title: false, // group: 3,
ascii: true, // chunk: 3
width: 16, // }
group: 3, // ),
chunk: 3 // "0000: 000102 030405 060708 090a0b 0c0d0e 0f ................\n\
} // 0010: 101112 ..."
), // );
"0000: 000102 030405 060708 090a0b 0c0d0e 0f ................\n\ //
0010: 101112 ..." // let cfg = HexConfig {
); // title: false,
// group: 0,
let cfg = HexConfig { // ..HexConfig::default()
title: false, // };
group: 0, // assert_eq!(
..HexConfig::default() // format!("{:?}", v.hex_conf(cfg)),
}; // "0000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n\
assert_eq!( // 0010: 10 11 12 ..."
format!("{:?}", v.hex_conf(cfg)), // );
"0000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n\ // assert_eq!(
0010: 10 11 12 ..." // v.hex_conf(cfg).to_string(),
); // "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12"
assert_eq!( // );
v.hex_conf(cfg).to_string(), // }
"00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12"
);
}
// This test case checks that hex_write works even without the alloc crate. // This test case checks that hex_write works even without the alloc crate.
// Decorators to this function like simple_hex_write or PrettyHex::hex_dump() // Decorators to this function like simple_hex_write or PrettyHex::hex_dump()