Skip to content

Commit 99a18b8

Browse files
committed
More Fuzzing
1 parent 999f973 commit 99a18b8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/test.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,43 @@ fn de_hex2bytes_should_work() {
334334
LJFN { ljf: (*b"Love Jane Forever").to_vec() }
335335
);
336336
}
337+
338+
#[test]
339+
fn random_input_should_work() {
340+
const DATA_1: &[u8] = include_bytes!("lib.rs");
341+
const DATA_2: &[u8] = include_bytes!("test.rs");
342+
343+
let data = [DATA_1, DATA_2].concat();
344+
345+
for chunks_size in [8, 16, 32, 64, 128, 256, 512, 1024] {
346+
let mut data_pieces = Vec::new();
347+
348+
data.chunks(chunks_size).enumerate().for_each(|(i, chunk)| {
349+
data_pieces.push(bytes2hex(if i % 2 == 0 { "0x" } else { "" }, chunk))
350+
});
351+
352+
let data_pieces = data_pieces
353+
.into_iter()
354+
.enumerate()
355+
.map(|(i, piece)| {
356+
if i % 2 == 0 {
357+
match piece.trim_start_matches("0x").len() {
358+
8 => hex2array_unchecked::<8>(&piece).to_vec(),
359+
32 => hex2array_unchecked::<16>(&piece).to_vec(),
360+
64 => hex2array_unchecked::<32>(&piece).to_vec(),
361+
128 => hex2array_unchecked::<64>(&piece).to_vec(),
362+
256 => hex2array_unchecked::<128>(&piece).to_vec(),
363+
512 => hex2array_unchecked::<256>(&piece).to_vec(),
364+
1024 => hex2array_unchecked::<512>(&piece).to_vec(),
365+
2048 => hex2array_unchecked::<1024>(&piece).to_vec(),
366+
_ => hex2bytes_unchecked(&piece),
367+
}
368+
} else {
369+
hex2bytes_unchecked(&piece)
370+
}
371+
})
372+
.collect::<Vec<_>>();
373+
374+
assert_eq!(data_pieces.concat(), data)
375+
}
376+
}

0 commit comments

Comments
 (0)