mod hex_bytes_truncation;
mod indirect_offset;
mod magic_rule_parsing;
mod meta_types;
mod number_and_offset_parsing;
mod operator_parsing;
mod strength_and_line_helpers;
mod type_and_operator_suffix_parsing;
mod type_parsing;
mod value_literal_parsing;
mod value_parsing;
use super::*;
use crate::parser::ast::Endianness;
use crate::parser::ast::IndirectAdjustmentOp;
use crate::parser::ast::MetaType;
use crate::parser::ast::PStringLengthWidth;
use crate::parser::ast::SearchFlags;
use crate::parser::ast::StringFlags;
#[allow(dead_code)] fn test_with_whitespace_variants<T, F>(input: &str, expected: &T, parser: F)
where
T: Clone + PartialEq + std::fmt::Debug,
F: Fn(&str) -> IResult<&str, T>,
{
let mut whitespace_variants = Vec::with_capacity(9);
whitespace_variants.extend([
format!(" {input}"), format!(" {input}"), format!("\t{input}"), format!("{input} "), format!("{input} "), format!("{input}\t"), format!(" {input} "), format!(" {input} "), format!("\t{input}\t"), ]);
for variant in whitespace_variants {
assert_eq!(
parser(&variant),
Ok(("", expected.clone())),
"Failed to parse with whitespace: '{variant}'"
);
}
}
fn test_number_with_remaining_input() {
let test_cases = [
("123abc", 123, "abc"),
("0xFF rest", 255, " rest"),
("-42 more", -42, " more"),
("0x10,next", 16, ",next"),
];
for (input, expected_num, expected_remaining) in test_cases {
assert_eq!(
parse_number(input),
Ok((expected_remaining, expected_num)),
"Failed to parse number with remaining input: '{input}'"
);
}
}