fn unwrap_first_quoted(value: &str) -> &str {
for quote in ['"', '\''] {
if let Some(rest) = value.strip_prefix(quote)
&& let Some(end) = rest.find(quote)
{
return &rest[..end];
}
}
value.trim_matches('"').trim_matches('\'')
}
fn is_shell_expansion(value: &str) -> bool {
let value = value.trim();
value.starts_with("$(") || value.starts_with('`') || value.contains("$(")
}
fn rust_cfg_test_lines(file: &FileFacts) -> HashSet<usize> {
let mut gated = HashSet::new();
if file.path.extension().and_then(|ext| ext.to_str()) != Some("rs") {
return gated;
}
let Some(content) = file.content.as_deref() else {
return gated;
};
let mut depth: i32 = 0;
let mut pending = false;
let mut gate_depth: Option<i32> = None;
let mut in_block_comment = false;
for (index, raw) in content.lines().enumerate() {
let line_no = index + 1;
let sanitized = sanitize_c_style(raw, &mut in_block_comment);
let trimmed = sanitized.trim();
if gate_depth.is_some() {
gated.insert(line_no);
} else if trimmed.starts_with("#[cfg(test)]") || trimmed == "#[test]" {
pending = true;
}
let opens = sanitized.matches('{').count() as i32;
let closes = sanitized.matches('}').count() as i32;
if pending && gate_depth.is_none() {
if opens > 0 {
gate_depth = Some(depth);
gated.insert(line_no);
pending = false;
} else if trimmed.ends_with(';') && !trimmed.starts_with("#[") {
pending = false;
}
}
depth += opens - closes;
if let Some(gate) = gate_depth
&& depth <= gate
{
gate_depth = None;
}
}
gated
}