spydecy_debugger/
lib.rs

1//! Spydecy Interactive Debugger
2//!
3//! This module implements the introspective debugger that allows stepping through
4//! the transpilation process to identify issues. Built incrementally alongside
5//! the transpiler (per Gemini's recommendation).
6//!
7//! # Sprint 2 Feature
8//!
9//! `visualize python-ast` - Display Python AST and HIR conversion
10
11#![warn(missing_docs, clippy::all, clippy::pedantic)]
12#![deny(unsafe_code)]
13#![allow(
14    clippy::module_name_repetitions,
15    clippy::format_push_string,
16    clippy::str_to_string,
17    clippy::unwrap_used,
18    clippy::uninlined_format_args
19)]
20
21pub mod visualize;
22
23use anyhow::Result;
24use std::path::Path;
25
26/// Visualize Python AST for debugging
27///
28/// # Errors
29///
30/// Returns an error if the file cannot be read or parsed
31pub fn visualize_python_ast(file_path: &Path) -> Result<String> {
32    visualize::visualize_python(file_path)
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38    use std::io::Write;
39    use tempfile::NamedTempFile;
40
41    #[test]
42    fn test_visualize_simple_function() {
43        let mut temp_file = NamedTempFile::new().unwrap();
44        writeln!(temp_file, "def my_len(x):\n    return len(x)").unwrap();
45
46        let result = visualize_python_ast(temp_file.path());
47        assert!(result.is_ok());
48        let output = result.unwrap();
49        assert!(output.contains("Module"));
50        assert!(output.contains("FunctionDef"));
51    }
52
53    #[test]
54    fn test_visualize_invalid_syntax() {
55        let mut temp_file = NamedTempFile::new().unwrap();
56        writeln!(temp_file, "def invalid syntax here").unwrap();
57
58        let result = visualize_python_ast(temp_file.path());
59        assert!(result.is_err());
60    }
61}