use std::path::PathBuf;
#[test]
#[allow(deprecated)]
fn test_symbols_in_file_filters_by_kind() {
let source = b"fn test_function() {}\nstruct TestStruct {}\nenum TestEnum {}";
let mut parser = magellan::Parser::new().unwrap();
let symbols = parser.extract_symbols(PathBuf::from("test.rs"), source);
assert_eq!(symbols.len(), 3, "Should extract 3 symbols");
let functions_only: Vec<_> = symbols
.iter()
.filter(|s| s.kind == magellan::SymbolKind::Function)
.collect();
assert_eq!(functions_only.len(), 1, "Should have 1 function");
assert!(functions_only[0].name.as_ref().unwrap() == "test_function");
let structs_only: Vec<_> = symbols
.iter()
.filter(|s| s.kind == magellan::SymbolKind::Class) .collect();
assert_eq!(structs_only.len(), 1, "Should have 1 struct");
}
#[test]
#[allow(deprecated)]
fn test_symbols_in_file_with_none_returns_all() {
let source = b"fn foo() {}\nstruct Bar {}";
let mut parser = magellan::Parser::new().unwrap();
let symbols = parser.extract_symbols(PathBuf::from("test.rs"), source);
assert_eq!(symbols.len(), 2, "Should extract 2 symbols");
}
#[test]
fn test_code_graph_symbols_in_file_with_kind_filter() {
use magellan::CodeGraph;
use tempfile::TempDir;
let temp_dir = TempDir::new().unwrap();
let db_path = temp_dir.path().join("test.db");
let mut graph = CodeGraph::open(&db_path).unwrap();
let source = b"fn func1() {}\nfn func2() {}\nstruct MyStruct {}";
graph.index_file("test.rs", source).unwrap();
let functions = graph
.symbols_in_file_with_kind("test.rs", Some(magellan::SymbolKind::Function))
.unwrap();
assert_eq!(functions.len(), 2, "Should have 2 functions");
for func in &functions {
assert_eq!(func.kind, magellan::SymbolKind::Function);
}
let structs = graph
.symbols_in_file_with_kind("test.rs", Some(magellan::SymbolKind::Class))
.unwrap();
assert_eq!(structs.len(), 1, "Should have 1 struct");
let all = graph.symbols_in_file_with_kind("test.rs", None).unwrap();
assert_eq!(all.len(), 3, "Should have 3 symbols total");
}