use std::path::Path;
#[test]
#[cfg(feature = "geometric")]
fn splice_can_open_geo_backend() {
if !Path::new("./code.geo").exists() {
eprintln!("SKIP: No code.geo file available");
return;
}
let integration =
splice::graph::magellan_integration::MagellanIntegration::open(Path::new("./code.geo"));
assert!(integration.is_ok(), "Should open .geo file");
let integration = integration.unwrap();
assert!(
integration.is_geometric(),
"Should detect geometric backend"
);
assert!(integration.geo_inner().is_some(), "Should have geo_inner");
}
#[test]
#[cfg(feature = "geometric")]
fn splice_can_resolve_real_symbol_from_geo() {
if !Path::new("./code.geo").exists() {
eprintln!("SKIP: No code.geo file available");
return;
}
let mut integration =
splice::graph::magellan_integration::MagellanIntegration::open(Path::new("./code.geo"))
.unwrap();
let symbols = integration.find_symbol_by_name("open", false);
assert!(symbols.is_ok(), "Should find symbols without error");
let symbols = symbols.unwrap();
eprintln!("Found {} symbols named 'open'", symbols.len());
}
#[test]
#[cfg(feature = "geometric")]
fn splice_can_get_real_span_from_geo() {
if !Path::new("./code.geo").exists() {
eprintln!("SKIP: No code.geo file available");
return;
}
let mut integration =
splice::graph::magellan_integration::MagellanIntegration::open(Path::new("./code.geo"))
.unwrap();
let symbols = integration.find_symbol_by_name("open", false).unwrap();
if let Some(symbol) = symbols.first() {
assert!(
symbol.byte_start < symbol.byte_end,
"Span should be valid: {}..{}",
symbol.byte_start,
symbol.byte_end
);
eprintln!(
"Symbol '{}' span: {}..{}",
symbol.name, symbol.byte_start, symbol.byte_end
);
} else {
eprintln!("SKIP: No 'open' symbol found to test span");
}
}
#[test]
#[cfg(feature = "geometric")]
fn splice_can_get_real_code_chunk_from_geo() {
if !Path::new("./code.geo").exists() {
eprintln!("SKIP: No code.geo file available");
return;
}
let mut integration =
splice::graph::magellan_integration::MagellanIntegration::open(Path::new("./code.geo"))
.unwrap();
let symbols = integration.find_symbol_by_name("open", false).unwrap();
if let Some(symbol) = symbols.first() {
let file_path = Path::new(&symbol.file_path);
let chunk = integration.get_code_chunk(file_path, symbol.byte_start, symbol.byte_end);
assert!(chunk.is_ok(), "Should get code chunk without error");
if let Ok(Some(chunk)) = chunk {
assert!(
!chunk.content.is_empty(),
"Chunk content should not be empty"
);
eprintln!("Got chunk with {} bytes of content", chunk.content.len());
} else {
eprintln!("No chunk found at span (this is OK if chunk store is empty)");
}
} else {
eprintln!("SKIP: No 'open' symbol found to test chunk retrieval");
}
}
#[test]
#[cfg(feature = "geometric")]
fn splice_geo_ambiguity_handling_is_explicit() {
if !Path::new("./code.geo").exists() {
eprintln!("SKIP: No code.geo file available");
return;
}
let mut integration =
splice::graph::magellan_integration::MagellanIntegration::open(Path::new("./code.geo"))
.unwrap();
let all_symbols = integration.find_symbol_by_name("open", true).unwrap();
let first_only = integration.find_symbol_by_name("open", false).unwrap();
assert!(
first_only.len() <= 1,
"ambiguous=false should return at most 1 symbol"
);
assert!(
first_only.len() <= all_symbols.len(),
"ambiguous=false should not return more than ambiguous=true"
);
eprintln!(
"ambiguous=true: {} symbols, ambiguous=false: {} symbols",
all_symbols.len(),
first_only.len()
);
}
#[test]
fn splice_sqlite_backend_still_works_for_batch1() {
use std::io::Write;
use tempfile::NamedTempFile;
let temp_file = NamedTempFile::with_suffix(".db").unwrap();
let integration =
splice::graph::magellan_integration::MagellanIntegration::open(temp_file.path());
match integration {
Ok(integ) => {
assert!(!integ.is_geometric(), "Should be SQLite backend");
}
Err(e) => {
let err_str = format!("{}", e);
assert!(
!err_str.contains("Geometric backend"),
"SQLite backend should not fail with geometric error: {}",
err_str
);
}
}
}