1use crate::ByteParser;
4
5pub fn test_buffer_windows_res<B, I, F, E>(bfmt: B, input: I, check: F) -> Result<(), E>
9where
10 B: Clone + ByteParser,
11 I: AsRef<[u8]>,
12 F: Fn(Result<B::Output, E>) -> Result<(), E>,
13 E: From<B::Error> + From<std::io::Error>,
14{
15 for initsize in [0, 1, 2, 3, 5, 7, 1 << 10, 1 << 14] {
16 eprintln!("Checking parser.parse_reader_with_initial_buffer_size(..., {initsize})");
17
18 let res = bfmt
19 .clone()
20 .parse_reader_with_initial_buffer_size(input.as_ref(), initsize);
21
22 check(res)?;
23 }
24
25 eprintln!("Checking parser.parse(...)");
26 check(bfmt.parse_all(input.as_ref()).map_err(E::from))
27}
28
29pub fn test_buffer_windows_outputs<B, I, F, E>(bfmt: B, input: I, check: F) -> Result<(), E>
33where
34 B: Clone + ByteParser,
35 I: AsRef<[u8]>,
36 F: Fn(B::Output) -> Result<(), E>,
37 E: From<B::Error> + From<std::io::Error>,
38{
39 test_buffer_windows_res(bfmt, input, |res| {
40 let output = res?;
41 check(output)
42 })
43}
44
45pub fn test_buffer_windows_output_no_res<B, I, F, E>(bfmt: B, input: I, check: F) -> Result<(), E>
49where
50 B: Clone + ByteParser,
51 I: AsRef<[u8]>,
52 F: Fn(B::Output),
53 E: From<B::Error> + From<std::io::Error>,
54{
55 test_buffer_windows_res(bfmt, input, |res| {
56 let output = res?;
57 check(output);
58 Ok(())
59 })
60}