use code_analyze_core::analyze::{analyze_directory, analyze_file, analyze_focused};
use tempfile::TempDir;
#[test]
fn test_acceptance_overview_mode() {
let temp_dir = TempDir::new().unwrap();
let root = temp_dir.path();
std::fs::create_dir(root.join("src")).unwrap();
std::fs::write(root.join("src/main.rs"), "fn main() {}").unwrap();
std::fs::write(root.join("src/lib.rs"), "pub fn helper() {}").unwrap();
std::fs::write(root.join("README.md"), "# Test Project").unwrap();
let output = analyze_directory(root, Some(2)).unwrap();
assert!(output.formatted.contains("SUMMARY:"));
assert!(output.formatted.contains("PATH [LOC, FUNCTIONS, CLASSES]"));
assert!(output.formatted.contains("main.rs"));
assert!(output.formatted.contains("lib.rs"));
assert!(!output.files.is_empty());
}
#[test]
fn test_acceptance_file_details_mode() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.rs");
let rust_code = r#"
use std::collections::HashMap;
pub struct Point {
x: i32,
y: i32,
}
impl Point {
pub fn new(x: i32, y: i32) -> Self {
Point { x, y }
}
pub fn distance(&self) -> f64 {
((self.x * self.x + self.y * self.y) as f64).sqrt()
}
}
pub fn calculate(a: i32, b: i32) -> i32 {
a + b
}
"#;
std::fs::write(&file_path, rust_code).unwrap();
let output = analyze_file(file_path.to_str().unwrap(), None).unwrap();
assert!(output.formatted.contains("FILE:"));
assert!(output.formatted.contains("test.rs"));
assert!(output.formatted.contains("F:"));
assert!(output.formatted.contains("C:"));
assert!(output.formatted.contains("I:"));
assert_eq!(output.semantic.functions.len(), 3); assert_eq!(output.semantic.classes.len(), 1); assert_eq!(output.semantic.imports.len(), 1); }
#[test]
fn test_acceptance_symbol_focus_mode() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.rs");
let rust_code = r#"
fn main() {
helper();
}
fn helper() {
worker();
}
fn worker() {
println!("Working");
}
"#;
std::fs::write(&file_path, rust_code).unwrap();
let output = analyze_focused(temp_dir.path(), "helper", 1, Some(2), None).unwrap();
assert!(output.formatted.contains("helper"));
assert!(!output.formatted.is_empty());
}