use serde::Deserialize;
use std::collections::HashMap;
use std::path::Path;
#[derive(Debug, Clone, Deserialize)]
pub struct LangExpectation {
#[serde(alias = "file")]
pub path: Option<String>,
pub symbol: Option<String>,
pub contains_symbols: Option<Vec<String>>,
pub body_contains: Option<Vec<String>>,
pub contains_functions: Option<Vec<String>>,
pub pattern: Option<String>,
pub expected_files: Option<Vec<String>>,
pub expected_refs_contain: Option<Vec<String>>,
}
pub fn load_expectations(
toml_path: &Path,
language: &str,
) -> Vec<(String, LangExpectation, String)> {
let content = std::fs::read_to_string(toml_path)
.unwrap_or_else(|e| panic!("Failed to read {}: {e}", toml_path.display()));
let raw: HashMap<String, toml::Value> = toml::from_str(&content)
.unwrap_or_else(|e| panic!("Failed to parse {}: {e}", toml_path.display()));
let mut expectations = Vec::new();
for (test_name, value) in &raw {
let table = value.as_table().expect("Each section should be a table");
let description = table
.get("description")
.and_then(|v| v.as_str())
.unwrap_or("");
let _ = description; let tool = table
.get("tool")
.and_then(|v| v.as_str())
.unwrap_or("get_symbols_overview")
.to_string();
if let Some(lang_value) = table.get(language) {
if let Ok(lang_exp) = lang_value.clone().try_into::<LangExpectation>() {
expectations.push((test_name.clone(), lang_exp, tool.clone()));
}
} else if table.get("path").is_some() || table.get("file").is_some() {
if let Ok(lang_exp) = value.clone().try_into::<LangExpectation>() {
expectations.push((test_name.clone(), lang_exp, tool.clone()));
}
}
}
expectations
}