pub const COLLECTION_VAR_NAMES: &[&str] = &[
"queue",
"stack",
"heap",
"items",
"elements",
"nodes",
"visited",
"seen",
"pending",
"worklist",
"buffer",
"entries",
"results",
"values",
"keys",
"children",
"neighbors",
"matches", ];
pub const COLLECTION_VAR_SUFFIXES: &[&str] = &[
"_queue", "_stack", "_heap", "_list", "_items", "_set",
];
pub const STRING_VAR_NAMES: &[&str] = &["stdout", "stderr", "output"];
pub const STRING_VAR_SUFFIXES: &[&str] = &["_output", "_result", "_str", "_string"];
#[allow(dead_code)]
pub const STRING_ATTR_NAMES: &[&str] = &[
"email",
"name",
"text",
"content",
"message",
"title",
"description",
"path",
"url",
"value",
"data",
"body",
"subject",
"address",
"filename",
"username",
"password",
"token",
"key",
"secret",
"label",
"output",
"input",
"stdout",
"stderr",
"error",
"warning",
"info",
"debug",
];
pub const DICT_VAR_NAMES: &[&str] = &[
"info", "data", "config", "options", "result", "response",
];
pub const DICT_VAR_SUFFIXES: &[&str] = &["_info", "_data", "_dict"];
pub const OPTION_VAR_NAMES: &[&str] = &[
"m", "match_", "match_result", "match_obj", "found", "hit",
];
pub const OPTION_VAR_SUFFIXES: &[&str] = &["_match", "_result", "_found"];
#[inline]
pub fn is_option_var_name(name: &str) -> bool {
OPTION_VAR_NAMES.contains(&name)
|| OPTION_VAR_SUFFIXES.iter().any(|s| name.ends_with(s))
}
pub const COLLECTION_TYPE_NAMES: &[&str] = &[
"VecDeque",
"std::collections::VecDeque",
"BinaryHeap",
"std::collections::BinaryHeap",
"LinkedList",
"std::collections::LinkedList",
"BTreeSet",
"BTreeMap",
"HashSet",
"HashMap",
];
pub const COLLECTION_TYPE_FRAGMENTS: &[&str] = &["Deque", "Queue", "Stack", "Heap"];
#[inline]
pub fn is_collection_var_name(name: &str) -> bool {
COLLECTION_VAR_NAMES.contains(&name)
|| COLLECTION_VAR_SUFFIXES.iter().any(|s| name.ends_with(s))
}
#[inline]
pub fn is_string_var_name(name: &str) -> bool {
STRING_VAR_NAMES.contains(&name)
|| STRING_VAR_SUFFIXES.iter().any(|s| name.ends_with(s))
}
#[inline]
#[allow(dead_code)]
pub fn is_string_attr_name(name: &str) -> bool {
STRING_ATTR_NAMES.contains(&name)
}
#[inline]
pub fn is_dict_var_name(name: &str) -> bool {
DICT_VAR_NAMES.contains(&name) || DICT_VAR_SUFFIXES.iter().any(|s| name.ends_with(s))
}
#[inline]
pub fn is_collection_type_name(type_name: &str) -> bool {
COLLECTION_TYPE_NAMES.iter().any(|n| type_name.starts_with(n))
|| COLLECTION_TYPE_FRAGMENTS.iter().any(|f| type_name.contains(f))
}
#[inline]
pub fn is_collection_generic_base(base: &str) -> bool {
matches!(
base,
"VecDeque" | "BinaryHeap" | "LinkedList" | "BTreeSet" | "BTreeMap" | "HashSet" | "HashMap" | "Vec"
)
}
pub const COLLECTION_ATTR_NAMES: &[&str] = &[
"heap", "stack", "queue", "items", "elements", "data", "values", "list", "array", "nodes",
"children", "entries", "records",
];
#[inline]
pub fn is_collection_attr_name(name: &str) -> bool {
COLLECTION_ATTR_NAMES.contains(&name)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_collection_var_names() {
assert!(is_collection_var_name("queue"));
assert!(is_collection_var_name("stack"));
assert!(is_collection_var_name("task_queue"));
assert!(is_collection_var_name("node_list"));
assert!(!is_collection_var_name("result"));
assert!(!is_collection_var_name("x"));
}
#[test]
fn test_string_var_names() {
assert!(is_string_var_name("stdout"));
assert!(is_string_var_name("stderr"));
assert!(is_string_var_name("command_output"));
assert!(is_string_var_name("name_str"));
assert!(!is_string_var_name("result"));
assert!(!is_string_var_name("x"));
}
#[test]
fn test_string_attr_names() {
assert!(is_string_attr_name("email"));
assert!(is_string_attr_name("username"));
assert!(is_string_attr_name("path"));
assert!(!is_string_attr_name("x"));
assert!(!is_string_attr_name("count"));
}
#[test]
fn test_dict_var_names() {
assert!(is_dict_var_name("info"));
assert!(is_dict_var_name("config"));
assert!(is_dict_var_name("result")); assert!(is_dict_var_name("response"));
assert!(is_dict_var_name("user_data"));
assert!(is_dict_var_name("cache_dict"));
assert!(!is_dict_var_name("x"));
assert!(!is_dict_var_name("count"));
}
#[test]
fn test_collection_type_names() {
assert!(is_collection_type_name("VecDeque<i32>"));
assert!(is_collection_type_name("std::collections::VecDeque"));
assert!(is_collection_type_name("BinaryHeap<Task>"));
assert!(is_collection_type_name("MyDeque"));
assert!(is_collection_type_name("TaskQueue"));
assert!(!is_collection_type_name("String"));
assert!(!is_collection_type_name("i32"));
}
#[test]
fn test_collection_generic_base() {
assert!(is_collection_generic_base("VecDeque"));
assert!(is_collection_generic_base("BinaryHeap"));
assert!(is_collection_generic_base("Vec"));
assert!(is_collection_generic_base("HashMap"));
assert!(!is_collection_generic_base("String"));
assert!(!is_collection_generic_base("Option"));
}
#[test]
fn test_all_collection_var_names_covered() {
for name in COLLECTION_VAR_NAMES {
assert!(is_collection_var_name(name), "Missing: {}", name);
}
}
#[test]
fn test_all_string_attr_names_covered() {
for name in STRING_ATTR_NAMES {
assert!(is_string_attr_name(name), "Missing: {}", name);
}
}
#[test]
fn test_suffix_patterns() {
assert!(is_collection_var_name("my_queue"));
assert!(is_collection_var_name("data_list"));
assert!(is_collection_var_name("item_set"));
assert!(is_string_var_name("cmd_output"));
assert!(is_string_var_name("value_string"));
}
#[test]
fn test_collection_attr_names() {
assert!(is_collection_attr_name("heap"));
assert!(is_collection_attr_name("stack"));
assert!(is_collection_attr_name("queue"));
assert!(is_collection_attr_name("items"));
assert!(is_collection_attr_name("data"));
assert!(is_collection_attr_name("list"));
assert!(is_collection_attr_name("nodes"));
assert!(is_collection_attr_name("children"));
assert!(!is_collection_attr_name("name"));
assert!(!is_collection_attr_name("email"));
assert!(!is_collection_attr_name("x"));
}
#[test]
fn test_all_collection_attr_names_covered() {
for name in COLLECTION_ATTR_NAMES {
assert!(is_collection_attr_name(name), "Missing: {}", name);
}
}
#[test]
fn test_option_var_names() {
assert!(is_option_var_name("m"));
assert!(is_option_var_name("match_"));
assert!(is_option_var_name("match_result"));
assert!(is_option_var_name("match_obj"));
assert!(is_option_var_name("found"));
assert!(is_option_var_name("hit"));
assert!(is_option_var_name("regex_match"));
assert!(is_option_var_name("pattern_result"));
assert!(is_option_var_name("is_found"));
assert!(!is_option_var_name("x"));
assert!(!is_option_var_name("text"));
assert!(!is_option_var_name("pattern"));
}
#[test]
fn test_all_option_var_names_covered() {
for name in OPTION_VAR_NAMES {
assert!(is_option_var_name(name), "Missing: {}", name);
}
}
}